Browse Source

Go to method implemented.

merge-requests/365/head
eidheim 11 years ago
parent
commit
bac182a360
  1. 24
      juci/selectiondialog.cc
  2. 6
      juci/selectiondialog.h
  3. 19
      juci/source.cc
  4. 2
      juci/source.h

24
juci/selectiondialog.cc

@ -1,4 +1,5 @@
#include "selectiondialog.h" #include "selectiondialog.h"
#include <algorithm>
namespace sigc { namespace sigc {
SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE 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) {} SelectionDialogBase::SelectionDialogBase(Gtk::TextView& text_view, bool popup): text_view(text_view), popup(popup) {}
void SelectionDialogBase::show() { void SelectionDialogBase::init() {
if(rows.size()==0)
return;
if(popup) if(popup)
window=std::unique_ptr<Gtk::Window>(new Gtk::Window(Gtk::WindowType::WINDOW_POPUP)); window=std::unique_ptr<Gtk::Window>(new Gtk::Window(Gtk::WindowType::WINDOW_POPUP));
else else
@ -39,10 +37,13 @@ void SelectionDialogBase::show() {
}); });
list_view_text->clear_items(); 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); scrolled_window->add(*list_view_text);
if(popup) if(popup)
window->add(*scrolled_window); window->add(*scrolled_window);
@ -146,9 +147,12 @@ void SelectionDialog::show() {
std::shared_ptr<std::string> search_key(new std::string()); std::shared_ptr<std::string> search_key(new std::string());
auto filter_model=Gtk::TreeModelFilter::create(list_view_text->get_model()); 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){ filter_model->set_visible_func([this, search_key](const Gtk::TreeModel::const_iterator& iter){
std::string row; std::string row_lc;
iter->get_value(0, row); iter->get_value(0, row_lc);
if(row.find(*search_key)!=std::string::npos) 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 true;
return false; return false;
}); });

6
juci/selectiondialog.h

@ -8,11 +8,13 @@
class SelectionDialogBase { class SelectionDialogBase {
public: public:
SelectionDialogBase(Gtk::TextView& text_view, bool popup); 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 show();
virtual void hide(); virtual void hide();
virtual void move(); virtual void move();
std::map<std::string, std::pair<std::string, std::string> > rows; std::map<std::string, std::pair<std::string, std::string> > rows; //TODO: remove, instead add on_select
std::function<void()> on_hide; std::function<void()> on_hide;
bool shown=false; bool shown=false;
Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark; Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark;
@ -34,6 +36,7 @@ private:
class SelectionDialog : public SelectionDialogBase { class SelectionDialog : public SelectionDialogBase {
public: public:
SelectionDialog(Gtk::TextView& text_view); SelectionDialog(Gtk::TextView& text_view);
void init() {SelectionDialogBase::init();}
void show(); void show();
std::function<void(std::string selected)> on_select; std::function<void(std::string selected)> on_select;
}; };
@ -41,6 +44,7 @@ public:
class CompletionDialog : public SelectionDialogBase { class CompletionDialog : public SelectionDialogBase {
public: public:
CompletionDialog(Gtk::TextView& text_view); CompletionDialog(Gtk::TextView& text_view);
void init() {SelectionDialogBase::init();}
void show(); void show();
bool on_key_release(GdkEventKey* key); bool on_key_release(GdkEventKey* key);
bool on_key_press(GdkEventKey* key); bool on_key_press(GdkEventKey* key);

19
juci/source.cc

@ -652,6 +652,7 @@ void Source::ClangViewAutocomplete::autocomplete() {
completion_dialog.start_mark=get_buffer()->create_mark(start_iter); completion_dialog.start_mark=get_buffer()->create_mark(start_iter);
std::map<std::string, std::pair<std::string, std::string> > rows; std::map<std::string, std::pair<std::string, std::string> > rows;
completion_dialog.init();
for (auto &data : *ac_data) { for (auto &data : *ac_data) {
std::stringstream ss; std::stringstream ss;
std::string return_value; 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 if (ss_str.length() > 0) { // if length is 0 the result is empty
auto pair=std::pair<std::string, std::string>(ss_str, data.brief_comments); auto pair=std::pair<std::string, std::string>(ss_str, data.brief_comments);
rows[ss.str() + " --> " + return_value] = pair; rows[ss.str() + " --> " + return_value] = pair;
completion_dialog.append(ss.str() + " --> " + return_value);
} }
} }
if (rows.empty()) { if (rows.empty()) {
rows["No suggestions found..."] = std::pair<std::string, std::string>(); rows["No suggestions found..."] = std::pair<std::string, std::string>();
completion_dialog.append("No suggestions found...");
} }
completion_dialog.rows=std::move(rows); completion_dialog.rows=std::move(rows);
completion_dialog.show(); completion_dialog.show();
@ -805,19 +808,25 @@ Source::ClangViewAutocomplete(file_path, project_path), selection_dialog(*this)
}; };
goto_method=[this](){ goto_method=[this](){
if(clang_readable) {
if(selection_dialog.start_mark) if(selection_dialog.start_mark)
get_buffer()->delete_mark(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()); selection_dialog.start_mark=get_buffer()->create_mark(get_buffer()->get_insert()->get_iter());
std::map<std::string, std::pair<std::string, std::string> > rows; std::map<std::string, std::pair<std::string, std::string> > rows;
rows["Not implemented yet"]=std::pair<std::string, std::string>("1", ""); selection_dialog.init();
rows["but you can try the selection search"]=std::pair<std::string, std::string>("2", ""); for(auto &method: clang_tokens->get_cxx_methods()) {
rows["search for instance for 'try'"]=std::pair<std::string, std::string>("3", ""); rows[method.first]=std::pair<std::string, std::string>(std::to_string(method.second), "");
selection_dialog.append(method.first);
}
selection_dialog.rows=std::move(rows); selection_dialog.rows=std::move(rows);
selection_dialog.on_select=[this](std::string selected) { selection_dialog.on_select=[this](std::string selected) {
cout << selected << endl; 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(); selection_dialog.show();
}
}; };
} }

2
juci/source.h

@ -79,6 +79,7 @@ public:
std::unique_ptr<clang::Tokens> clang_tokens; std::unique_ptr<clang::Tokens> clang_tokens;
bool clang_readable=false; bool clang_readable=false;
sigc::connection delayed_reparse_connection; sigc::connection delayed_reparse_connection;
sigc::connection delayed_tooltips_connection;
private: private:
std::map<std::string, std::string> get_buffer_map() const; std::map<std::string, std::string> get_buffer_map() const;
// inits the syntax highligthing on file open // inits the syntax highligthing on file open
@ -94,7 +95,6 @@ public:
Tooltips type_tooltips; Tooltips type_tooltips;
bool on_motion_notify_event(GdkEventMotion* event); bool on_motion_notify_event(GdkEventMotion* event);
void on_mark_set(const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark); void on_mark_set(const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark);
sigc::connection delayed_tooltips_connection;
bool on_scroll_event(GdkEventScroll* event); bool on_scroll_event(GdkEventScroll* event);
static clang::Index clang_index; static clang::Index clang_index;

Loading…
Cancel
Save