#include "menu.h" #include "singletons.h" #include #include 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 JUCI_UBUNTU_BUGGED_MENU 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 = "" " " "
" " " " _About" " app.about" +accels["about"]+ //For Ubuntu... " " "
" "
" " " " _Preferences" " app.preferences" +accels["preferences"]+ //For Ubuntu... " " "
" "
" " " " _Quit" " app.quit" +accels["quit"]+ //For Ubuntu... " " "
" "
" "" " " " " " _File" "
" " " " _New _File" " app.new_file" +accels["new_file"]+ //For Ubuntu... " " " " " _New _Folder" " app.new_folder" +accels["new_folder"]+ //For Ubuntu... " " " " " _New _Project" " " " C++" " app.new_project_cpp" +accels["new_project_cpp"]+ //For Ubuntu... " " " " "
" "
" " " " _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... " " "
" "
" "" " " " _Edit" "
" " " " _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... " " "
" "
" "" " " " _Source" "
" " " " _Spell _Check" " " " _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... " " " " "
" "
" " " " _Indentation" " " " _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... " " " " "
" "
" " " " _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 Usage" " app.source_goto_usage" +accels["source_goto_usage"]+ //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... " " "
" "
" "" " " " _Project" "
" " " " _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... " " "
" "
" "" " " " _Window" "
" " " " _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... " " "
" "
" "
" "
"; } void Menu::add_action(const std::string &name, std::function action) { auto g_application=g_application_get_default(); auto gio_application=Glib::wrap(g_application, true); auto application=Glib::RefPtr::cast_static(gio_application); actions[name]=application->add_action(name, action); } void Menu::set_keys() { auto g_application=g_application_get_default(); auto gio_application=Glib::wrap(g_application, true); auto application=Glib::RefPtr::cast_static(gio_application); for(auto &key: Singleton::config->menu.keys) { 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 } } } void Menu::build() { builder = Gtk::Builder::create(); try { builder->add_from_string(ui_xml); } catch (const Glib::Error &ex) { std::cerr << "building menu failed: " << ex.what(); } }