From bac182a360ef2d0fcc7cc51f2c8ddb8da8f902ce Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 21 Jul 2015 13:43:14 +0200 Subject: [PATCH] Go to method implemented. --- juci/selectiondialog.cc | 26 +++++++++++++++----------- juci/selectiondialog.h | 6 +++++- juci/source.cc | 37 +++++++++++++++++++++++-------------- juci/source.h | 2 +- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/juci/selectiondialog.cc b/juci/selectiondialog.cc index 52a673a..6bee4cb 100644 --- a/juci/selectiondialog.cc +++ b/juci/selectiondialog.cc @@ -1,4 +1,5 @@ #include "selectiondialog.h" +#include namespace sigc { SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE @@ -6,10 +7,7 @@ namespace sigc { SelectionDialogBase::SelectionDialogBase(Gtk::TextView& text_view, bool popup): text_view(text_view), popup(popup) {} -void SelectionDialogBase::show() { - if(rows.size()==0) - return; - +void SelectionDialogBase::init() { if(popup) window=std::unique_ptr(new Gtk::Window(Gtk::WindowType::WINDOW_POPUP)); else @@ -39,10 +37,13 @@ void SelectionDialogBase::show() { }); list_view_text->clear_items(); - for (auto &i : rows) { - list_view_text->append(i.first); - } - +} + +void SelectionDialogBase::append(const std::string& row) { + list_view_text->append(row); +} + +void SelectionDialogBase::show() { scrolled_window->add(*list_view_text); if(popup) window->add(*scrolled_window); @@ -146,9 +147,12 @@ void SelectionDialog::show() { std::shared_ptr search_key(new std::string()); auto filter_model=Gtk::TreeModelFilter::create(list_view_text->get_model()); filter_model->set_visible_func([this, search_key](const Gtk::TreeModel::const_iterator& iter){ - std::string row; - iter->get_value(0, row); - if(row.find(*search_key)!=std::string::npos) + std::string row_lc; + iter->get_value(0, row_lc); + auto search_key_lc=*search_key; + std::transform(row_lc.begin(), row_lc.end(), row_lc.begin(), ::tolower); + std::transform(search_key_lc.begin(), search_key_lc.end(), search_key_lc.begin(), ::tolower); + if(row_lc.find(search_key_lc)!=std::string::npos) return true; return false; }); diff --git a/juci/selectiondialog.h b/juci/selectiondialog.h index ffb631f..7afad0e 100644 --- a/juci/selectiondialog.h +++ b/juci/selectiondialog.h @@ -8,11 +8,13 @@ class SelectionDialogBase { public: SelectionDialogBase(Gtk::TextView& text_view, bool popup); + virtual void init(); //TODO: use constructor instead of init + virtual void append(const std::string& row); virtual void show(); virtual void hide(); virtual void move(); - std::map > rows; + std::map > rows; //TODO: remove, instead add on_select std::function on_hide; bool shown=false; Glib::RefPtr start_mark; @@ -34,6 +36,7 @@ private: class SelectionDialog : public SelectionDialogBase { public: SelectionDialog(Gtk::TextView& text_view); + void init() {SelectionDialogBase::init();} void show(); std::function on_select; }; @@ -41,6 +44,7 @@ public: class CompletionDialog : public SelectionDialogBase { public: CompletionDialog(Gtk::TextView& text_view); + void init() {SelectionDialogBase::init();} void show(); bool on_key_release(GdkEventKey* key); bool on_key_press(GdkEventKey* key); diff --git a/juci/source.cc b/juci/source.cc index ea1e34f..17c4937 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -652,6 +652,7 @@ void Source::ClangViewAutocomplete::autocomplete() { completion_dialog.start_mark=get_buffer()->create_mark(start_iter); std::map > rows; + completion_dialog.init(); for (auto &data : *ac_data) { std::stringstream ss; std::string return_value; @@ -668,10 +669,12 @@ void Source::ClangViewAutocomplete::autocomplete() { if (ss_str.length() > 0) { // if length is 0 the result is empty auto pair=std::pair(ss_str, data.brief_comments); rows[ss.str() + " --> " + return_value] = pair; + completion_dialog.append(ss.str() + " --> " + return_value); } } if (rows.empty()) { rows["No suggestions found..."] = std::pair(); + completion_dialog.append("No suggestions found..."); } completion_dialog.rows=std::move(rows); completion_dialog.show(); @@ -804,20 +807,26 @@ Source::ClangViewAutocomplete(file_path, project_path), selection_dialog(*this) return location; }; - goto_method=[this](){ - if(selection_dialog.start_mark) - get_buffer()->delete_mark(selection_dialog.start_mark); - selection_dialog.start_mark=get_buffer()->create_mark(get_buffer()->get_insert()->get_iter()); - - std::map > rows; - rows["Not implemented yet"]=std::pair("1", ""); - rows["but you can try the selection search"]=std::pair("2", ""); - rows["search for instance for 'try'"]=std::pair("3", ""); - selection_dialog.rows=std::move(rows); - selection_dialog.on_select=[this](std::string selected) { - cout << selected << endl; - }; - selection_dialog.show(); + goto_method=[this](){ + if(clang_readable) { + if(selection_dialog.start_mark) + get_buffer()->delete_mark(selection_dialog.start_mark); + selection_dialog.start_mark=get_buffer()->create_mark(get_buffer()->get_insert()->get_iter()); + std::map > rows; + selection_dialog.init(); + for(auto &method: clang_tokens->get_cxx_methods()) { + rows[method.first]=std::pair(std::to_string(method.second), ""); + selection_dialog.append(method.first); + } + selection_dialog.rows=std::move(rows); + selection_dialog.on_select=[this](std::string selected) { + auto offset=stoul(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(); + }; + selection_dialog.show(); + } }; } diff --git a/juci/source.h b/juci/source.h index 2ead12c..6a2c75b 100644 --- a/juci/source.h +++ b/juci/source.h @@ -79,6 +79,7 @@ public: std::unique_ptr clang_tokens; bool clang_readable=false; sigc::connection delayed_reparse_connection; + sigc::connection delayed_tooltips_connection; private: std::map get_buffer_map() const; // inits the syntax highligthing on file open @@ -94,7 +95,6 @@ public: Tooltips type_tooltips; bool on_motion_notify_event(GdkEventMotion* event); void on_mark_set(const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr& mark); - sigc::connection delayed_tooltips_connection; bool on_scroll_event(GdkEventScroll* event); static clang::Index clang_index;