#include "menu.h" #include "config.h" #include #include //TODO: if Ubuntu ever gets fixed, cleanup the Ubuntu specific code Menu::Menu() { auto accels=Config::get().menu.keys; for(auto &accel: accels) { #ifdef JUCI_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 = "" " " "
" " " " _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... " " "
" "
" " " " _Print" " app.print" +accels["print"]+ //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" "
" " " " _Set _Run _Arguments" " app.project_set_run_arguments" +accels["project_set_run_arguments"]+ //For Ubuntu... " " " " " _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... " " "
" "
" "" " " " _Debug" "
" " " " _Set _Run _Arguments" " app.debug_set_run_arguments" +accels["debug_set_run_arguments"]+ //For Ubuntu... " " " " " _Start/_Continue" " app.debug_start_continue" +accels["debug_start_continue"]+ //For Ubuntu... " " " " " _Stop" " app.debug_stop" +accels["debug_stop"]+ //For Ubuntu... " " " " " _Kill" " app.debug_kill" +accels["debug_kill"]+ //For Ubuntu... " " "
" "
" " " " _Step _Over" " app.debug_step_over" +accels["debug_step_over"]+ //For Ubuntu... " " " " " _Step _Into" " app.debug_step_into" +accels["debug_step_into"]+ //For Ubuntu... " " " " " _Step _Out" " app.debug_step_out" +accels["debug_step_out"]+ //For Ubuntu... " " "
" "
" " " " _Backtrace" " app.debug_backtrace" +accels["debug_backtrace"]+ //For Ubuntu... " " " " " _Show _Variables" " app.debug_show_variables" +accels["debug_show_variables"]+ //For Ubuntu... " " "
" "
" " " " _Run Command" " app.debug_run_command" +accels["debug_run_command"]+ //For Ubuntu... " " "
" "
" " " " _Toggle _Breakpoint" " app.debug_toggle_breakpoint" +accels["debug_toggle_breakpoint"]+ //For Ubuntu... " " "
" "
" " " " _Go _to _Stop" " app.debug_goto_stop" +accels["debug_goto_stop"]+ //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: Config::get().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); auto object = Menu::get().builder->get_object("juci-menu"); juci_menu = Glib::RefPtr::cast_dynamic(object); object = Menu::get().builder->get_object("window-menu"); window_menu = Glib::RefPtr::cast_dynamic(object); } catch (const Glib::Error &ex) { std::cerr << "building menu failed: " << ex.what(); } }