From cbaee6b3a14174391710b15dda352bfdd47e6ee8 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 2 Aug 2015 11:22:02 +0200 Subject: [PATCH] Added go to line and center cursor. Remember to rm ~./juci/config/config.json and ~./juci/config/menu.xml to update the keys and menu. --- src/files.h | 5 +++++ src/window.cc | 62 +++++++++++++++++++++++++++++++++++++++++---------- src/window.h | 1 + 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/files.h b/src/files.h index 0aa5e88..6a34e45 100644 --- a/src/files.h +++ b/src/files.h @@ -47,6 +47,8 @@ const std::string configjson = " \"edit_undo\": \"z\",\n" " \"edit_redo\": \"z\",\n" " \"edit_find\": \"f\",\n" +" \"source_goto_line\": \"g\",\n" +" \"source_center_cursor\": \"l\",\n" " \"source_goto_declaration\": \"d\",\n" " \"source_goto_method\": \"m\",\n" " \"source_rename\": \"r\",\n" @@ -112,6 +114,9 @@ const std::string menuxml = " \n" " \n" " \n" +" \n" +" \n" +" \n" " \n" " \n" " \n" diff --git a/src/window.cc b/src/window.cc index 70c487c..3b8c102 100644 --- a/src/window.cc +++ b/src/window.cc @@ -148,6 +148,16 @@ void Window::create_menu() { INFO("Done Redo"); }); + menu.action_group->add(Gtk::Action::create("SourceGotoLine", "Go to line"), Gtk::AccelKey(menu.key_map["source_goto_line"]), [this]() { + goto_line_entry(); + }); + menu.action_group->add(Gtk::Action::create("SourceCenterCursor", "Center cursor"), Gtk::AccelKey(menu.key_map["source_center_cursor"]), [this]() { + if(notebook.get_current_page()!=-1) { + while(gtk_events_pending()) + gtk_main_iteration(); + notebook.get_current_view()->scroll_to(notebook.get_current_view()->get_buffer()->get_insert(), 0.0, 1.0, 0.5); + } + }); menu.action_group->add(Gtk::Action::create("SourceGotoDeclaration", "Go to declaration"), Gtk::AccelKey(menu.key_map["source_goto_declaration"]), [this]() { if(notebook.get_current_page()!=-1) { if(notebook.get_current_view()->get_declaration_location) { @@ -483,6 +493,34 @@ void Window::search_and_replace_entry() { entry_box.show(); } +void Window::goto_line_entry() { + entry_box.clear(); + if(notebook.get_current_page()!=-1) { + entry_box.entries.emplace_back("", [this](const std::string& content){ + auto buffer=notebook.get_current_view()->get_buffer(); + try { + auto line=stoul(content); + if(line>0 && (int)line<=buffer->get_line_count()) { + line--; + if(notebook.get_current_page()!=-1) { + buffer->place_cursor(buffer->get_iter_at_line(line)); + while(gtk_events_pending()) + gtk_main_iteration(); + notebook.get_current_view()->scroll_to(buffer->get_insert(), 0.0, 1.0, 0.5); + } + } + } + catch(const std::exception &e) {} + entry_box.hide(); + }); + auto entry_it=entry_box.entries.begin(); + entry_box.buttons.emplace_back("Go to line", [this, entry_it](){ + entry_it->activate(); + }); + entry_box.show(); + } +} + void Window::rename_token_entry() { entry_box.clear(); if(notebook.get_current_page()!=-1) { @@ -502,23 +540,23 @@ void Window::rename_token_entry() { }; label_it->update(0, ""); entry_box.entries.emplace_back(*token_name, [this, token_name, token](const std::string& content){ - if(notebook.get_current_page()!=-1 && content!=*token_name) { - for(int c=0;crename_similar_tokens) { - auto number=notebook.get_view(c)->rename_similar_tokens(*token, content); - if(number>0) { - Singleton::terminal()->print("Replaced "+std::to_string(number)+" occurrences in file "+notebook.get_view(c)->file_path+"\n"); - notebook.save(c); - } + if(notebook.get_current_page()!=-1 && content!=*token_name) { + for(int c=0;crename_similar_tokens) { + auto number=notebook.get_view(c)->rename_similar_tokens(*token, content); + if(number>0) { + Singleton::terminal()->print("Replaced "+std::to_string(number)+" occurrences in file "+notebook.get_view(c)->file_path+"\n"); + notebook.save(c); } } - entry_box.hide(); } - }); + entry_box.hide(); + } + }); auto entry_it=entry_box.entries.begin(); entry_box.buttons.emplace_back("Rename", [this, entry_it](){ - entry_it->activate(); - }); + entry_it->activate(); + }); entry_box.show(); } } diff --git a/src/window.h b/src/window.h index 992d2be..8d51c9a 100644 --- a/src/window.h +++ b/src/window.h @@ -33,6 +33,7 @@ private: void save_file_dialog(); void search_and_replace_entry(); + void goto_line_entry(); void rename_token_entry(); std::string last_search; std::string last_replace;