Browse Source

New menu system finished. Also, the key bindings now gets updated when config.json is saved.

merge-requests/365/head
eidheim 10 years ago
parent
commit
484ac9feda
  1. 14
      src/files.h
  2. 4
      src/juci.cc
  3. 169
      src/menu.cc
  4. 4
      src/menu.h
  5. 247
      src/window.cc
  6. 3
      src/window.h

14
src/files.h

@ -59,19 +59,19 @@ const std::string configjson =
" \"clang_format_style\": \"ColumnLimit: 0\"\n" " \"clang_format_style\": \"ColumnLimit: 0\"\n"
" },\n" " },\n"
" \"keybindings\": {\n" " \"keybindings\": {\n"
" \"preferences\": \"<primary>comma\",\n"
" \"quit\": \"<primary>q\",\n"
" \"new_file\": \"<primary>n\",\n" " \"new_file\": \"<primary>n\",\n"
" \"new_folder\": \"<primary><shift>n\",\n" " \"new_folder\": \"<primary><shift>n\",\n"
" \"open_folder\": \"<primary><shift>o\",\n"
" \"open_file\": \"<primary>o\",\n" " \"open_file\": \"<primary>o\",\n"
" \"open_folder\": \"<primary><shift>o\",\n"
" \"save\": \"<primary>s\",\n" " \"save\": \"<primary>s\",\n"
" \"save_as\": \"<primary><shift>s\",\n" " \"save_as\": \"<primary><shift>s\",\n"
" \"preferences\": \"<primary>comma\",\n"
" \"quit\": \"<primary>q\",\n"
" \"edit_copy\": \"<primary>c\",\n"
" \"edit_cut\": \"<primary>x\",\n"
" \"edit_paste\": \"<primary>v\",\n"
" \"edit_undo\": \"<primary>z\",\n" " \"edit_undo\": \"<primary>z\",\n"
" \"edit_redo\": \"<primary><shift>z\",\n" " \"edit_redo\": \"<primary><shift>z\",\n"
" \"edit_cut\": \"<primary>x\",\n"
" \"edit_copy\": \"<primary>c\",\n"
" \"edit_paste\": \"<primary>v\",\n"
" \"edit_find\": \"<primary>f\",\n" " \"edit_find\": \"<primary>f\",\n"
" \"edit_set_tab\": \"\",\n" " \"edit_set_tab\": \"\",\n"
" \"source_spellcheck\": \"\",\n" " \"source_spellcheck\": \"\",\n"
@ -81,10 +81,10 @@ const std::string configjson =
" \"source_indentation_auto_indent_buffer\": \"<primary><shift>i\",\n" " \"source_indentation_auto_indent_buffer\": \"<primary><shift>i\",\n"
" \"source_goto_line\": \"<primary>g\",\n" " \"source_goto_line\": \"<primary>g\",\n"
" \"source_center_cursor\": \"<primary>l\",\n" " \"source_center_cursor\": \"<primary>l\",\n"
" \"source_find_documentation\": \"<primary><shift>d\",\n"
" \"source_goto_declaration\": \"<primary>d\",\n" " \"source_goto_declaration\": \"<primary>d\",\n"
" \"source_goto_method\": \"<primary>m\",\n" " \"source_goto_method\": \"<primary>m\",\n"
" \"source_rename\": \"<primary>r\",\n" " \"source_rename\": \"<primary>r\",\n"
" \"source_find_documentation\": \"<primary><shift>d\",\n"
" \"source_goto_next_diagnostic\": \"<primary>e\",\n" " \"source_goto_next_diagnostic\": \"<primary>e\",\n"
" \"source_apply_fix_its\": \"<control>space\",\n" " \"source_apply_fix_its\": \"<control>space\",\n"
" \"compile_and_run\": \"<primary>Return\",\n" " \"compile_and_run\": \"<primary>Return\",\n"

4
src/juci.cc

@ -38,6 +38,7 @@ int app::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) {
} }
void app::on_activate() { void app::on_activate() {
window = std::unique_ptr<Window>(new Window());
add_window(*window); add_window(*window);
window->show(); window->show();
bool first_directory=true; bool first_directory=true;
@ -83,13 +84,10 @@ void app::on_startup() {
set_app_menu(juci_menu); set_app_menu(juci_menu);
set_menubar(window_menu); set_menubar(window_menu);
} }
window->set_menu_actions();
} }
app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) { app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) {
Glib::set_application_name("juCi++"); Glib::set_application_name("juCi++");
window = std::unique_ptr<Window>(new Window());
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {

169
src/menu.cc

@ -44,7 +44,7 @@ Menu::Menu() {
" <submenu>" " <submenu>"
" <attribute name='label' translatable='yes'>_New _Project</attribute>" " <attribute name='label' translatable='yes'>_New _Project</attribute>"
" <item>" " <item>"
" <attribute name='label' translatable='yes'>C++</attribute>" " <attribute name='label' translatable='no'>C++</attribute>"
" <attribute name='action'>app.new_project_cpp</attribute>" " <attribute name='action'>app.new_project_cpp</attribute>"
" </item>" " </item>"
" </submenu>" " </submenu>"
@ -70,6 +70,162 @@ Menu::Menu() {
" </item>" " </item>"
" </section>" " </section>"
" </submenu>" " </submenu>"
""
" <submenu>"
" <attribute name='label' translatable='yes'>_Edit</attribute>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Undo</attribute>"
" <attribute name='action'>app.edit_undo</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Redo</attribute>"
" <attribute name='action'>app.edit_redo</attribute>"
" </item>"
" </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Cut</attribute>"
" <attribute name='action'>app.edit_cut</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Copy</attribute>"
" <attribute name='action'>app.edit_copy</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Paste</attribute>"
" <attribute name='action'>app.edit_paste</attribute>"
" </item>"
" </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Find</attribute>"
" <attribute name='action'>app.edit_find</attribute>"
" </item>"
" </section>"
" </submenu>"
""
" <submenu>"
" <attribute name='label' translatable='yes'>_Source</attribute>"
" <section>"
" <submenu>"
" <attribute name='label' translatable='yes'>_Spell _Check</attribute>"
" <item>"
" <attribute name='label' translatable='yes'>_Spell _Check _Buffer</attribute>"
" <attribute name='action'>app.source_spellcheck</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Clear _Spelling _Errors</attribute>"
" <attribute name='action'>app.source_spellcheck_clear</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Go _to _Next _Spelling _Error</attribute>"
" <attribute name='action'>app.source_spellcheck_next_error</attribute>"
" </item>"
" </submenu>"
" </section>"
" <section>"
" <submenu>"
" <attribute name='label' translatable='yes'>_Indentation</attribute>"
" <item>"
" <attribute name='label' translatable='yes'>_Set _Current _Buffer _Tab</attribute>"
" <attribute name='action'>app.source_indentation_set_buffer_tab</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Auto-Indent _Current _Buffer</attribute>"
" <attribute name='action'>app.source_indentation_auto_indent_buffer</attribute>"
" </item>"
" </submenu>"
" </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Go _to _Line</attribute>"
" <attribute name='action'>app.source_goto_line</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Center _Cursor</attribute>"
" <attribute name='action'>app.source_center_cursor</attribute>"
" </item>"
" </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Find _Documentation</attribute>"
" <attribute name='action'>app.source_find_documentation</attribute>"
" </item>"
" </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Go to Declaration</attribute>"
" <attribute name='action'>app.source_goto_declaration</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Go to Method</attribute>"
" <attribute name='action'>app.source_goto_method</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Rename</attribute>"
" <attribute name='action'>app.source_rename</attribute>"
" </item>"
" </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Go to Next Diagnostic</attribute>"
" <attribute name='action'>app.source_goto_next_diagnostic</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Apply Fix-Its</attribute>"
" <attribute name='action'>app.source_apply_fix_its</attribute>"
" </item>"
" </section>"
" </submenu>"
""
" <submenu>"
" <attribute name='label' translatable='yes'>_Project</attribute>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Compile _and _Run</attribute>"
" <attribute name='action'>app.compile_and_run</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Compile</attribute>"
" <attribute name='action'>app.compile</attribute>"
" </item>"
" </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Run _Command</attribute>"
" <attribute name='action'>app.run_command</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Kill _Last _Process</attribute>"
" <attribute name='action'>app.kill_last_running</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Force _Kill _Last _Process</attribute>"
" <attribute name='action'>app.force_kill_last_running</attribute>"
" </item>"
" </section>"
" </submenu>"
""
" <submenu>"
" <attribute name='label' translatable='yes'>_Window</attribute>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Next _Tab</attribute>"
" <attribute name='action'>app.next_tab</attribute>"
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Previous _Tab</attribute>"
" <attribute name='action'>app.previous_tab</attribute>"
" </item>"
" </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Close _Tab</attribute>"
" <attribute name='action'>app.close_tab</attribute>"
" </item>"
" </section>"
" </submenu>"
" </menu>" " </menu>"
"</interface>"; "</interface>";
} }
@ -78,10 +234,15 @@ void Menu::add_action(const std::string &name, std::function<void()> action) {
auto application = builder->get_application(); auto application = builder->get_application();
actions[name]=application->add_action(name, action); actions[name]=application->add_action(name, action);
}
void Menu::set_keys() {
auto application = builder->get_application();
auto key=Singleton::Config::menu()->keys.find(name); for(auto &key: Singleton::Config::menu()->keys) {
if(key!=Singleton::Config::menu()->keys.end()) if(key.second.size()>0 && actions.find(key.first)!=actions.end())
application->set_accel_for_action("app."+name, key->second); application->set_accel_for_action("app."+key.first, key.second);
}
} }
void Menu::build() { void Menu::build() {

4
src/menu.h

@ -13,12 +13,14 @@ public:
}; };
Menu(); Menu();
void add_action(const std::string &name, std::function<void()> action); void add_action(const std::string &name, std::function<void()> action);
std::unordered_map<std::string, Glib::RefPtr<Gio::SimpleAction> > actions; std::unordered_map<std::string, Glib::RefPtr<Gio::SimpleAction> > actions;
void set_keys();
void build(); void build();
Glib::RefPtr<Gtk::Builder> builder;
std::string ui_xml; std::string ui_xml;
Glib::RefPtr<Gtk::Builder> builder;
}; };
#endif // JUCI_MENU_H_ #endif // JUCI_MENU_H_

247
src/window.cc

@ -27,10 +27,12 @@ Window::Window() : compiling(false) {
JDEBUG("start"); JDEBUG("start");
set_title("juCi++"); set_title("juCi++");
set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK); set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK);
set_menu_actions();
configure(); configure();
set_default_size(Singleton::Config::window()->default_size.first, Singleton::Config::window()->default_size.second); set_default_size(Singleton::Config::window()->default_size.first, Singleton::Config::window()->default_size.second);
//PluginApi(&this->notebook, &this->menu); //PluginApi(&this->notebook, &this->menu);
add(vpaned); add(vpaned);
directory_and_notebook_panes.pack1(*Singleton::directories(), Gtk::SHRINK); directory_and_notebook_panes.pack1(*Singleton::directories(), Gtk::SHRINK);
@ -87,27 +89,8 @@ Window::Window() : compiling(false) {
notebook.get_current_view()->search_highlight(last_search, case_sensitive_search, regex_search); notebook.get_current_view()->search_highlight(last_search, case_sensitive_search, regex_search);
} }
/*if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceIndentation/SourceIndentationAutoIndentBuffer"))) activate_menu_items();
menu_item->set_sensitive((bool)notebook.get_current_view()->auto_indent);
if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceGotoDeclaration")))
menu_item->set_sensitive((bool)notebook.get_current_view()->get_declaration_location);
if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceGotoMethod")))
menu_item->set_sensitive((bool)notebook.get_current_view()->goto_method);
if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceRename")))
menu_item->set_sensitive((bool)notebook.get_current_view()->rename_similar_tokens);
if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceGotoNextDiagnostic")))
menu_item->set_sensitive((bool)notebook.get_current_view()->goto_next_diagnostic);
if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceApplyFixIts")))
menu_item->set_sensitive((bool)notebook.get_current_view()->apply_fix_its);
if(auto menu_item=dynamic_cast<Gtk::MenuItem*>(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceFindDocumentation")))
menu_item->set_sensitive((bool)notebook.get_current_view()->get_token_data);*/
Singleton::directories()->select(notebook.get_current_view()->file_path); Singleton::directories()->select(notebook.get_current_view()->file_path);
if(auto source_view=dynamic_cast<Source::ClangView*>(notebook.get_current_view())) { if(auto source_view=dynamic_cast<Source::ClangView*>(notebook.get_current_view())) {
@ -145,11 +128,14 @@ Window::Window() : compiling(false) {
void Window::configure() { void Window::configure() {
MainConfig(); // Read the configs here MainConfig(); // Read the configs here
auto style_context = Gtk::StyleContext::create(); auto style_context = Gtk::StyleContext::create();
auto screen = Gdk::Screen::get_default(); auto screen = Gdk::Screen::get_default();
auto css_provider = Gtk::CssProvider::get_named(Singleton::Config::window()->theme_name, Singleton::Config::window()->theme_variant); auto css_provider = Gtk::CssProvider::get_named(Singleton::Config::window()->theme_name, Singleton::Config::window()->theme_variant);
//TODO: add check if theme exists, or else write error to Singleton::terminal() //TODO: add check if theme exists, or else write error to Singleton::terminal()
style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS); style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
Singleton::menu()->set_keys();
} }
void Window::set_menu_actions() { void Window::set_menu_actions() {
@ -276,33 +262,8 @@ void Window::set_menu_actions() {
} }
}); });
/*
menu->add_action("edit_undo", [this]() {
menu.action_group->add(Gtk::Action::create("EditCopy", "Copy"), Gtk::AccelKey(key_map["edit_copy"]), [this]() {
auto widget=get_focus();
if(auto entry=dynamic_cast<Gtk::Entry*>(widget))
entry->copy_clipboard();
else if(auto text_view=dynamic_cast<Gtk::TextView*>(widget))
text_view->get_buffer()->copy_clipboard(Gtk::Clipboard::get());
});
menu.action_group->add(Gtk::Action::create("EditCut", "Cut"), Gtk::AccelKey(key_map["edit_cut"]), [this]() {
auto widget=get_focus();
if(auto entry=dynamic_cast<Gtk::Entry*>(widget))
entry->cut_clipboard();
else if(notebook.get_current_page()!=-1)
notebook.get_current_view()->get_buffer()->cut_clipboard(Gtk::Clipboard::get());
});
menu.action_group->add(Gtk::Action::create("EditPaste", "Paste"), Gtk::AccelKey(key_map["edit_paste"]), [this]() {
auto widget=get_focus();
if(auto entry=dynamic_cast<Gtk::Entry*>(widget))
entry->paste_clipboard();
else if(notebook.get_current_page()!=-1)
notebook.get_current_view()->paste();
});
menu.action_group->add(Gtk::Action::create("EditFind", "Find"), Gtk::AccelKey(key_map["edit_find"]), [this]() {
search_and_replace_entry();
});
menu.action_group->add(Gtk::Action::create("EditUndo", "Undo"), Gtk::AccelKey(key_map["edit_undo"]), [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto undo_manager = notebook.get_current_view()->get_source_buffer()->get_undo_manager(); auto undo_manager = notebook.get_current_view()->get_source_buffer()->get_undo_manager();
if (undo_manager->can_undo()) { if (undo_manager->can_undo()) {
@ -311,7 +272,7 @@ void Window::set_menu_actions() {
} }
} }
}); });
menu.action_group->add(Gtk::Action::create("EditRedo", "Redo"), Gtk::AccelKey(key_map["edit_redo"]), [this]() { menu->add_action("edit_redo", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto undo_manager = notebook.get_current_view()->get_source_buffer()->get_undo_manager(); auto undo_manager = notebook.get_current_view()->get_source_buffer()->get_undo_manager();
if(undo_manager->can_redo()) { if(undo_manager->can_redo()) {
@ -320,32 +281,59 @@ void Window::set_menu_actions() {
} }
} }
}); });
menu.action_group->add(Gtk::Action::create("SourceSpellCheck", "Spell Check")); menu->add_action("edit_cut", [this]() {
menu.action_group->add(Gtk::Action::create("SourceSpellCheckBuffer", "Spell Check Buffer"), Gtk::AccelKey(key_map["source_spellcheck"]), [this]() { auto widget=get_focus();
if(auto entry=dynamic_cast<Gtk::Entry*>(widget))
entry->cut_clipboard();
else if(notebook.get_current_page()!=-1)
notebook.get_current_view()->get_buffer()->cut_clipboard(Gtk::Clipboard::get());
});
menu->add_action("edit_copy", [this]() {
auto widget=get_focus();
if(auto entry=dynamic_cast<Gtk::Entry*>(widget))
entry->copy_clipboard();
else if(auto text_view=dynamic_cast<Gtk::TextView*>(widget))
text_view->get_buffer()->copy_clipboard(Gtk::Clipboard::get());
});
menu->add_action("edit_paste", [this]() {
auto widget=get_focus();
if(auto entry=dynamic_cast<Gtk::Entry*>(widget))
entry->paste_clipboard();
else if(notebook.get_current_page()!=-1)
notebook.get_current_view()->paste();
});
menu->add_action("edit_find", [this]() {
search_and_replace_entry();
});
menu->add_action("source_spellcheck", [this]() {
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
notebook.get_current_view()->spellcheck(); notebook.get_current_view()->spellcheck();
}); });
menu.action_group->add(Gtk::Action::create("SourceSpellCheckClear", "Clear Spelling Errors"), Gtk::AccelKey(key_map["source_spellcheck_clear"]), [this]() { menu->add_action("source_spellcheck_clear", [this]() {
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
notebook.get_current_view()->remove_spellcheck_errors(); notebook.get_current_view()->remove_spellcheck_errors();
}); });
menu.action_group->add(Gtk::Action::create("SourceSpellCheckNextError", "Go to next Spelling Error"), Gtk::AccelKey(key_map["source_spellcheck_next_error"]), [this]() { menu->add_action("source_spellcheck_next_error", [this]() {
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
notebook.get_current_view()->goto_next_spellcheck_error(); notebook.get_current_view()->goto_next_spellcheck_error();
}); });
menu.action_group->add(Gtk::Action::create("SourceIndentation", "Indentation"));
menu.action_group->add(Gtk::Action::create("SourceIndentationSetBufferTab", "Set Current Buffer Tab"), Gtk::AccelKey(key_map["source_indentation_set_buffer_tab"]), [this]() { menu->add_action("source_indentation_set_buffer_tab", [this]() {
set_tab_entry(); set_tab_entry();
}); });
menu.action_group->add(Gtk::Action::create("SourceIndentationAutoIndentBuffer", "Auto-Indent Current Buffer"), Gtk::AccelKey(key_map["source_indentation_auto_indent_buffer"]), [this]() { menu->add_action("source_indentation_auto_indent_buffer", [this]() {
if(notebook.get_current_page()!=-1 && notebook.get_current_view()->auto_indent) if(notebook.get_current_page()!=-1 && notebook.get_current_view()->auto_indent)
notebook.get_current_view()->auto_indent(); notebook.get_current_view()->auto_indent();
}); });
menu.action_group->add(Gtk::Action::create("SourceGotoLine", "Go to Line"), Gtk::AccelKey(key_map["source_goto_line"]), [this]() {
menu->add_action("source_goto_line", [this]() {
goto_line_entry(); goto_line_entry();
}); });
menu.action_group->add(Gtk::Action::create("SourceCenterCursor", "Center Cursor"), Gtk::AccelKey(key_map["source_center_cursor"]), [this]() { menu->add_action("source_center_cursor", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
while(gtk_events_pending()) while(gtk_events_pending())
gtk_main_iteration(); gtk_main_iteration();
@ -353,44 +341,8 @@ void Window::set_menu_actions() {
notebook.get_current_view()->scroll_to(notebook.get_current_view()->get_buffer()->get_insert(), 0.0, 1.0, 0.5); 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(key_map["source_goto_declaration"]), [this]() {
if(notebook.get_current_page()!=-1) { menu->add_action("source_find_documentation", [this]() {
if(notebook.get_current_view()->get_declaration_location) {
auto location=notebook.get_current_view()->get_declaration_location();
if(location.first.size()>0) {
notebook.open(location.first);
auto line=static_cast<int>(location.second.line)-1;
auto index=static_cast<int>(location.second.index)-1;
auto buffer=notebook.get_current_view()->get_buffer();
line=std::min(line, buffer->get_line_count()-1);
if(line>=0) {
auto iter=buffer->get_iter_at_line(line);
while(!iter.ends_line())
iter.forward_char();
auto end_line_index=iter.get_line_index();
index=std::min(index, end_line_index);
buffer->place_cursor(buffer->get_iter_at_line_index(line, index));
while(gtk_events_pending())
gtk_main_iteration();
if(notebook.get_current_page()!=-1)
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("SourceGotoMethod", "Go to Method"), Gtk::AccelKey(key_map["source_goto_method"]), [this]() {
if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->goto_method) {
notebook.get_current_view()->goto_method();
}
}
});
menu.action_group->add(Gtk::Action::create("SourceRename", "Rename"), Gtk::AccelKey(key_map["source_rename"]), [this]() {
rename_token_entry();
});
menu.action_group->add(Gtk::Action::create("SourceFindDocumentation", "Find Documentation"), Gtk::AccelKey(key_map["source_find_documentation"]), [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->get_token_data) { if(notebook.get_current_view()->get_token_data) {
auto data=notebook.get_current_view()->get_token_data(); auto data=notebook.get_current_view()->get_token_data();
@ -430,22 +382,62 @@ void Window::set_menu_actions() {
} }
} }
}); });
menu.action_group->add(Gtk::Action::create("SourceGotoNextDiagnostic", "Go to next Diagnostic"), Gtk::AccelKey(key_map["source_goto_next_diagnostic"]), [this]() {
menu->add_action("source_goto_declaration", [this]() {
if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->get_declaration_location) {
auto location=notebook.get_current_view()->get_declaration_location();
if(location.first.size()>0) {
notebook.open(location.first);
auto line=static_cast<int>(location.second.line)-1;
auto index=static_cast<int>(location.second.index)-1;
auto buffer=notebook.get_current_view()->get_buffer();
line=std::min(line, buffer->get_line_count()-1);
if(line>=0) {
auto iter=buffer->get_iter_at_line(line);
while(!iter.ends_line())
iter.forward_char();
auto end_line_index=iter.get_line_index();
index=std::min(index, end_line_index);
buffer->place_cursor(buffer->get_iter_at_line_index(line, index));
while(gtk_events_pending())
gtk_main_iteration();
if(notebook.get_current_page()!=-1)
notebook.get_current_view()->scroll_to(notebook.get_current_view()->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
}
}
}
}
});
menu->add_action("source_goto_method", [this]() {
if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->goto_method) {
notebook.get_current_view()->goto_method();
}
}
});
menu->add_action("source_rename", [this]() {
rename_token_entry();
});
menu->add_action("source_goto_next_diagnostic", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->goto_next_diagnostic) { if(notebook.get_current_view()->goto_next_diagnostic) {
notebook.get_current_view()->goto_next_diagnostic(); notebook.get_current_view()->goto_next_diagnostic();
} }
} }
}); });
menu.action_group->add(Gtk::Action::create("SourceApplyFixIts", "Apply Fix-Its"), Gtk::AccelKey(key_map["source_apply_fix_its"]), [this]() { menu->add_action("source_apply_fix_its", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->apply_fix_its) { if(notebook.get_current_view()->apply_fix_its) {
notebook.get_current_view()->apply_fix_its(); notebook.get_current_view()->apply_fix_its();
} }
} }
}); });
menu.action_group->add(Gtk::Action::create("ProjectCompileAndRun", "Compile and Run"), Gtk::AccelKey(key_map["compile_and_run"]), [this]() {
menu->add_action("compile_and_run", [this]() {
if(notebook.get_current_page()==-1 || compiling) if(notebook.get_current_page()==-1 || compiling)
return; return;
CMake cmake(notebook.get_current_view()->file_path); CMake cmake(notebook.get_current_view()->file_path);
@ -485,7 +477,7 @@ void Window::set_menu_actions() {
} }
} }
}); });
menu.action_group->add(Gtk::Action::create("ProjectCompile", "Compile"), Gtk::AccelKey(key_map["compile"]), [this]() { menu->add_action("compile", [this]() {
if(notebook.get_current_page()==-1 || compiling) if(notebook.get_current_page()==-1 || compiling)
return; return;
CMake cmake(notebook.get_current_view()->file_path); CMake cmake(notebook.get_current_view()->file_path);
@ -497,7 +489,8 @@ void Window::set_menu_actions() {
}); });
} }
}); });
menu.action_group->add(Gtk::Action::create("ProjectRunCommand", "Run Command"), Gtk::AccelKey(key_map["run_command"]), [this]() {
menu->add_action("run_command", [this]() {
entry_box.clear(); entry_box.clear();
entry_box.labels.emplace_back(); entry_box.labels.emplace_back();
auto label_it=entry_box.labels.begin(); auto label_it=entry_box.labels.begin();
@ -518,7 +511,7 @@ void Window::set_menu_actions() {
else else
run_path=Singleton::directories()->current_path; run_path=Singleton::directories()->current_path;
Singleton::terminal()->async_print("Running: "+content+'\n'); Singleton::terminal()->async_print("Running: "+content+'\n');
Singleton::terminal()->async_execute(content, run_path, [this, content](int exit_code){ Singleton::terminal()->async_execute(content, run_path, [this, content](int exit_code){
Singleton::terminal()->async_print(content+" returned: "+std::to_string(exit_code)+'\n'); Singleton::terminal()->async_print(content+" returned: "+std::to_string(exit_code)+'\n');
}); });
@ -532,29 +525,21 @@ void Window::set_menu_actions() {
}); });
entry_box.show(); entry_box.show();
}); });
menu.action_group->add(Gtk::Action::create("ProjectKillLastRunning", "Kill Last Process"), Gtk::AccelKey(key_map["kill_last_running"]), [this]() {
menu->add_action("kill_last_running", [this]() {
Singleton::terminal()->kill_last_async_execute(); Singleton::terminal()->kill_last_async_execute();
}); });
menu.action_group->add(Gtk::Action::create("ProjectForceKillLastRunning", "Force Kill Last Process"), Gtk::AccelKey(key_map["force_kill_last_running"]), [this]() { menu->add_action("force_kill_last_running", [this]() {
Singleton::terminal()->kill_last_async_execute(true); Singleton::terminal()->kill_last_async_execute(true);
}); });
menu.action_group->add(Gtk::Action::create("WindowCloseTab", "Close Tab"), Gtk::AccelKey(key_map["close_tab"]), [this]() {
notebook.close_current_page();
if(notebook.get_current_page()!=-1) { menu->add_action("next_tab", [this]() {
notebook.get_current_view()->set_status(notebook.get_current_view()->status);
notebook.get_current_view()->set_info(notebook.get_current_view()->info);
}
else {
Singleton::status()->set_text("");
Singleton::info()->set_text("");
}
});
menu.action_group->add(Gtk::Action::create("WindowNextTab", "Next Tab"), Gtk::AccelKey(key_map["next_tab"]), [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
notebook.open(notebook.get_view((notebook.get_current_page()+1)%notebook.size())->file_path); notebook.open(notebook.get_view((notebook.get_current_page()+1)%notebook.size())->file_path);
} }
}); });
menu.action_group->add(Gtk::Action::create("WindowPreviousTab", "Previous Tab"), Gtk::AccelKey(key_map["previous_tab"]), [this]() { menu->add_action("previous_tab", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
int previous_page=notebook.get_current_page()-1; int previous_page=notebook.get_current_page()-1;
if(previous_page<0) if(previous_page<0)
@ -562,7 +547,31 @@ void Window::set_menu_actions() {
notebook.open(notebook.get_view(previous_page)->file_path); notebook.open(notebook.get_view(previous_page)->file_path);
} }
}); });
*/ menu->add_action("close_tab", [this]() {
notebook.close_current_page();
if(notebook.get_current_page()!=-1) {
notebook.get_current_view()->set_status(notebook.get_current_view()->status);
notebook.get_current_view()->set_info(notebook.get_current_view()->info);
}
else {
Singleton::status()->set_text("");
Singleton::info()->set_text("");
activate_menu_items(false);
}
});
activate_menu_items(false);
}
void Window::activate_menu_items(bool activate) {
auto menu = Singleton::menu();
menu->actions["source_indentation_auto_indent_buffer"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->auto_indent) : false);
menu->actions["source_find_documentation"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_token_data) : false);
menu->actions["source_goto_declaration"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_declaration_location) : false);
menu->actions["source_goto_method"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_method) : false);
menu->actions["source_rename"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->rename_similar_tokens) : false);
menu->actions["source_goto_next_diagnostic"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_next_diagnostic) : false);
menu->actions["source_apply_fix_its"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->apply_fix_its) : false);
} }
bool Window::on_key_press_event(GdkEventKey *event) { bool Window::on_key_press_event(GdkEventKey *event) {

3
src/window.h

@ -18,7 +18,6 @@ public:
std::string version; std::string version;
std::pair<int, int> default_size; std::pair<int, int> default_size;
}; };
void set_menu_actions();
protected: protected:
bool on_key_press_event(GdkEventKey *event); bool on_key_press_event(GdkEventKey *event);
@ -36,6 +35,8 @@ private:
std::atomic<bool> compiling; std::atomic<bool> compiling;
void configure(); void configure();
void set_menu_actions();
void activate_menu_items(bool activate=true);
void hide(); void hide();
void search_and_replace_entry(); void search_and_replace_entry();
void set_tab_entry(); void set_tab_entry();

Loading…
Cancel
Save