From e4cdc8e0c6171f1c6f16b34756b3c3a12b2b0ff5 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 22 Jul 2015 14:01:55 +0200 Subject: [PATCH] Further cleanup of selectiondialog.*. --- juci/selectiondialog.cc | 4 +--- juci/selectiondialog.h | 4 ++-- juci/source.cc | 53 +++++++++++++++++++++-------------------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/juci/selectiondialog.cc b/juci/selectiondialog.cc index 0a34363..98c4710 100644 --- a/juci/selectiondialog.cc +++ b/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) { diff --git a/juci/selectiondialog.h b/juci/selectiondialog.h index 7d9ec12..5ff32c2 100644 --- a/juci/selectiondialog.h +++ b/juci/selectiondialog.h @@ -16,7 +16,7 @@ public: virtual void move(); std::function on_hide; - std::function on_select; + std::function on_select; Glib::RefPtr 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_ \ No newline at end of file diff --git a/juci/source.cc b/juci/source.cc index 9aead05..a57ac0c 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -644,11 +644,32 @@ void Source::ClangViewAutocomplete::autocomplete() { for(size_t c=0;c(new CompletionDialog(*this, get_buffer()->create_mark(start_iter))); + auto rows=std::make_shared >(); completion_dialog->on_hide=[this](){ start_reparse(); completion_dialog_shown=false; }; - auto rows=std::make_shared >(); + 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(new SelectionDialog(*this, get_buffer()->create_mark(get_buffer()->get_insert()->get_iter()))); - auto rows=std::make_shared >(); + auto rows=std::make_shared >(); 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();