From eb587684af8bb041751b03cded7e8f4d5246e930 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 26 Oct 2015 19:07:42 +0100 Subject: [PATCH] Fixed 2 out of 3 Ubuntu menu problems. --- src/juci.cc | 4 ++- src/menu.cc | 77 ++++++++++++++++++++++++++++++++++++++++++++++++----- src/menu.h | 2 ++ 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/src/juci.cc b/src/juci.cc index c2bff14..fda51e8 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -38,7 +38,6 @@ int app::on_command_line(const Glib::RefPtr &cmd) { } void app::on_activate() { - window = std::unique_ptr(new Window()); add_window(*window); window->show(); bool first_directory=true; @@ -71,6 +70,7 @@ void app::on_activate() { void app::on_startup() { Gtk::Application::on_startup(); + Singleton::menu()->init(); Singleton::menu()->build(); auto object = Singleton::menu()->builder->get_object("juci-menu"); @@ -88,6 +88,8 @@ void app::on_startup() { app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) { Glib::set_application_name("juCi++"); + Singleton::menu()->application=static_cast(this); //For Ubuntu 14... + window = std::unique_ptr(new Window()); } int main(int argc, char *argv[]) { diff --git a/src/menu.cc b/src/menu.cc index 8a65aaa..e3711a1 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -6,6 +6,33 @@ using namespace std; //TODO: remove Menu::Menu() { +} + +//TODO: if Ubuntu ever gets fixed, move to constructor, also cleanup the rest of the Ubuntu specific code +void Menu::init() { + auto accels=Singleton::Config::menu()->keys; + for(auto &accel: accels) { +#ifdef __linux //Ubuntu... + size_t pos=0; + std::string second=accel.second; + while((pos=second.find('<', pos))!=std::string::npos) { + second.replace(pos, 1, "<"); + pos+=4; + } + pos=0; + while((pos=second.find('>', pos))!=std::string::npos) { + second.replace(pos, 1, ">"); + pos+=4; + } + if(second.size()>0) + accel.second=""+second+""; + else + accel.second=""; +#else + accel.second=""; +#endif + } + ui_xml = "" " " @@ -13,18 +40,21 @@ Menu::Menu() { " " " _About" " app.about" + +accels["about"]+ //For Ubuntu... " " " " "
" " " " _Preferences" " app.preferences" + +accels["preferences"]+ //For Ubuntu... " " "
" "
" " " " _Quit" " app.quit" + +accels["quit"]+ //For Ubuntu... " " "
" "
" @@ -36,16 +66,19 @@ Menu::Menu() { " " " _New _File" " app.new_file" + +accels["new_file"]+ //For Ubuntu... " " " " " _New _Directory" " app.new_folder" + +accels["new_folder"]+ //For Ubuntu... " " " " " _New _Project" " " " C++" " app.new_project_cpp" + +accels["new_project_cpp"]+ //For Ubuntu... " " " " " " @@ -53,20 +86,24 @@ Menu::Menu() { " " " _Open _File" " app.open_file" + +accels["open_file"]+ //For Ubuntu... " " " " " _Open _Folder" " app.open_folder" + +accels["open_folder"]+ //For Ubuntu... " " " " "
" " " " _Save" " app.save" + +accels["save"]+ //For Ubuntu... " " " " " _Save _As" " app.save_as" + +accels["save_as"]+ //For Ubuntu... " " "
" " " @@ -77,30 +114,36 @@ Menu::Menu() { " " " _Undo" " app.edit_undo" + +accels["edit_undo"]+ //For Ubuntu... " " " " " _Redo" " app.edit_redo" + +accels["edit_redo"]+ //For Ubuntu... " " " " "
" " " " _Cut" " app.edit_cut" + +accels["edit_cut"]+ //For Ubuntu... " " " " " _Copy" " app.edit_copy" + +accels["edit_copy"]+ //For Ubuntu... " " " " " _Paste" " app.edit_paste" + +accels["edit_paste"]+ //For Ubuntu... " " "
" "
" " " " _Find" " app.edit_find" + +accels["edit_find"]+ //For Ubuntu... " " "
" " " @@ -113,14 +156,17 @@ Menu::Menu() { " " " _Spell _Check _Buffer" " app.source_spellcheck" + +accels["source_spellcheck"]+ //For Ubuntu... " " " " " _Clear _Spelling _Errors" " app.source_spellcheck_clear" + +accels["source_spellcheck_clear"]+ //For Ubuntu... " " " " " _Go _to _Next _Spelling _Error" " app.source_spellcheck_next_error" + +accels["source_spellcheck_next_error"]+ //For Ubuntu... " " " " " " @@ -130,10 +176,12 @@ Menu::Menu() { " " " _Set _Current _Buffer _Tab" " app.source_indentation_set_buffer_tab" + +accels["source_indentation_set_buffer_tab"]+ //For Ubuntu... " " " " " _Auto-Indent _Current _Buffer" " app.source_indentation_auto_indent_buffer" + +accels["source_indentation_auto_indent_buffer"]+ //For Ubuntu... " " " " " " @@ -141,40 +189,48 @@ Menu::Menu() { " " " _Go _to _Line" " app.source_goto_line" + +accels["source_goto_line"]+ //For Ubuntu... " " " " " _Center _Cursor" " app.source_center_cursor" + +accels["source_center_cursor"]+ //For Ubuntu... " " " " "
" " " " _Find _Documentation" " app.source_find_documentation" + +accels["source_find_documentation"]+ //For Ubuntu... " " "
" "
" " " " _Go to Declaration" " app.source_goto_declaration" + +accels["source_goto_declaration"]+ //For Ubuntu... " " " " " _Go to Method" " app.source_goto_method" + +accels["source_goto_method"]+ //For Ubuntu... " " " " " _Rename" " app.source_rename" + +accels["source_rename"]+ //For Ubuntu... " " "
" "
" " " " _Go to Next Diagnostic" " app.source_goto_next_diagnostic" + +accels["source_goto_next_diagnostic"]+ //For Ubuntu... " " " " " _Apply Fix-Its" " app.source_apply_fix_its" + +accels["source_apply_fix_its"]+ //For Ubuntu... " " "
" " " @@ -185,24 +241,29 @@ Menu::Menu() { " " " _Compile _and _Run" " app.compile_and_run" + +accels["compile_and_run"]+ //For Ubuntu... " " " " " _Compile" " app.compile" + +accels["compile"]+ //For Ubuntu... " " " " "
" " " " _Run _Command" " app.run_command" + +accels["run_command"]+ //For Ubuntu... " " " " " _Kill _Last _Process" " app.kill_last_running" + +accels["kill_last_running"]+ //For Ubuntu... " " " " " _Force _Kill _Last _Process" " app.force_kill_last_running" + +accels["force_kill_last_running"]+ //For Ubuntu... " " "
" " " @@ -213,16 +274,19 @@ Menu::Menu() { " " " _Next _Tab" " app.next_tab" + +accels["next_tab"]+ //For Ubuntu... " " " " " _Previous _Tab" " app.previous_tab" + +accels["previous_tab"]+ //For Ubuntu... " " " " "
" " " " _Close _Tab" " app.close_tab" + +accels["close_tab"]+ //For Ubuntu... " " "
" " " @@ -231,17 +295,18 @@ Menu::Menu() { } void Menu::add_action(const std::string &name, std::function action) { - auto application = builder->get_application(); - actions[name]=application->add_action(name, action); } void Menu::set_keys() { - auto application = builder->get_application(); - for(auto &key: Singleton::Config::menu()->keys) { - if(key.second.size()>0 && actions.find(key.first)!=actions.end()) - application->set_accel_for_action("app."+key.first, key.second); + if(key.second.size()>0 && actions.find(key.first)!=actions.end()) { +#if GTK_VERSION_GE(3, 12) + application->set_accel_for_action("app."+key.first, key.second); +#else + application->add_accelerator(key.second, "app."+key.first); //For Ubuntu 14... +#endif + } } } diff --git a/src/menu.h b/src/menu.h index eb381bf..3aaa133 100644 --- a/src/menu.h +++ b/src/menu.h @@ -13,6 +13,8 @@ public: }; Menu(); + void init(); //For Ubuntu 14... + Gtk::Application* application; //For Ubuntu 14... void add_action(const std::string &name, std::function action); std::unordered_map > actions;