Browse Source

Further cleanup of selectiondialog.*.

merge-requests/365/head
eidheim 11 years ago
parent
commit
e4cdc8e0c6
  1. 4
      juci/selectiondialog.cc
  2. 4
      juci/selectiondialog.h
  3. 53
      juci/source.cc

4
juci/selectiondialog.cc

@ -163,7 +163,7 @@ void SelectionDialog::show() {
filter_model->refilter();
list_view_text.set_search_entry(search_entry); //TODO:Report the need of this to GTK's git (bug)
});
search_entry.signal_event().connect([this, search_key, filter_model](GdkEvent* event) {
search_entry.signal_event().connect([this](GdkEvent* event) {
if(event->type==GDK_KEY_PRESS) {
auto key=(GdkEventKey*)event;
if(key->keyval==GDK_KEY_Down && list_view_text.get_model()->children().size()>0) {
@ -234,8 +234,6 @@ void CompletionDialog::show() {
search_entry.set_text(text);
list_view_text.set_search_entry(search_entry);
}
row_in_entry=false;
}
void CompletionDialog::select(bool hide_window) {

4
juci/selectiondialog.h

@ -16,7 +16,7 @@ public:
virtual void move();
std::function<void()> on_hide;
std::function<void(const std::string& selected, bool finished)> on_select;
std::function<void(const std::string& selected, bool hide_window)> on_select;
Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark;
protected:
virtual void resize();
@ -50,7 +50,7 @@ private:
void select(bool hide_window=true);
int show_offset;
bool row_in_entry;
bool row_in_entry=false;
};
#endif // JUCI_SELECTIONDIALOG_H_

53
juci/source.cc

@ -644,11 +644,32 @@ void Source::ClangViewAutocomplete::autocomplete() {
for(size_t c=0;c<prefix.size();c++)
start_iter--;
completion_dialog=std::unique_ptr<CompletionDialog>(new CompletionDialog(*this, get_buffer()->create_mark(start_iter)));
auto rows=std::make_shared<std::unordered_map<std::string, std::string> >();
completion_dialog->on_hide=[this](){
start_reparse();
completion_dialog_shown=false;
};
auto rows=std::make_shared<std::unordered_map<std::string, std::string> >();
completion_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) {
auto row = rows->at(selected);
get_buffer()->erase(completion_dialog->start_mark->get_iter(), get_buffer()->get_insert()->get_iter());
get_buffer()->insert(completion_dialog->start_mark->get_iter(), row);
if(hide_window) {
char find_char=row.back();
if(find_char==')' || find_char=='>') {
if(find_char==')')
find_char='(';
else
find_char='<';
size_t pos=row.find(find_char);
if(pos!=std::string::npos) {
auto start_offset=completion_dialog->start_mark->get_iter().get_offset()+pos+1;
auto end_offset=completion_dialog->start_mark->get_iter().get_offset()+row.size()-1;
if(start_offset!=end_offset)
get_buffer()->select_range(get_buffer()->get_iter_at_offset(start_offset), get_buffer()->get_iter_at_offset(end_offset));
}
}
}
};
for (auto &data : *ac_data) {
std::stringstream ss;
std::string return_value;
@ -671,27 +692,6 @@ void Source::ClangViewAutocomplete::autocomplete() {
(*rows)["No suggestions found..."] = "";
completion_dialog->add_row("No suggestions found...");
}
completion_dialog->on_select=[this, rows](const std::string& selected, bool finished) {
auto row = rows->at(selected);
get_buffer()->erase(completion_dialog->start_mark->get_iter(), get_buffer()->get_insert()->get_iter());
get_buffer()->insert(completion_dialog->start_mark->get_iter(), row);
if(finished) {
char find_char=row.back();
if(find_char==')' || find_char=='>') {
if(find_char==')')
find_char='(';
else
find_char='<';
size_t pos=row.find(find_char);
if(pos!=std::string::npos) {
auto start_offset=completion_dialog->start_mark->get_iter().get_offset()+pos+1;
auto end_offset=completion_dialog->start_mark->get_iter().get_offset()+row.size()-1;
if(start_offset!=end_offset)
get_buffer()->select_range(get_buffer()->get_iter_at_offset(start_offset), get_buffer()->get_iter_at_offset(end_offset));
}
}
}
};
completion_dialog_shown=true;
completion_dialog->show();
}
@ -826,16 +826,17 @@ Source::ClangViewAutocomplete(file_path, project_path) {
goto_method=[this](){
if(clang_readable) {
selection_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*this, get_buffer()->create_mark(get_buffer()->get_insert()->get_iter())));
auto rows=std::make_shared<std::unordered_map<std::string, std::string> >();
auto rows=std::make_shared<std::unordered_map<std::string, unsigned> >();
auto methods=clang_tokens->get_cxx_methods();
if(methods.size()==0)
return;
for(auto &method: methods) {
(*rows)[method.first]=std::to_string(method.second);
(*rows)[method.first]=method.second;
selection_dialog->add_row(method.first);
}
selection_dialog->on_select=[this, rows](const std::string& selected, bool finished) {
auto offset=stoul(rows->at(selected));
//TODO see if rows gets destroyed when selection_dialog gets destroyed.
selection_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) {
auto offset=rows->at(selected);
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(offset));
scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5);
delayed_tooltips_connection.disconnect();

Loading…
Cancel
Save