From a8163f0d84705dd5c5cd925a1ede20b4114f39ae Mon Sep 17 00:00:00 2001 From: eidheim Date: Sat, 28 Sep 2024 15:50:12 +0200 Subject: [PATCH] Cleanup of menu inconsistency fix --- src/juci.cpp | 7 ++++- src/menu.cpp | 76 ++++++++++++++++++++++++++++++---------------------- src/menu.hpp | 1 + 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/juci.cpp b/src/juci.cpp index b7e1487..b16c0aa 100644 --- a/src/juci.cpp +++ b/src/juci.cpp @@ -121,7 +121,12 @@ void Application::on_startup() { Gtk::Application::on_startup(); Menu::get().build(); - set_menubar(Menu::get().window_menu); + if(Menu::get().juci_menu) + set_app_menu(Menu::get().juci_menu); + if(!Menu::get().window_menu) + std::cerr << "Menu not found." << std::endl; + else + set_menubar(Menu::get().window_menu); } Application::Application() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) { diff --git a/src/menu.cpp b/src/menu.cpp index f224373..46a9b72 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -4,6 +4,44 @@ #include #include +const Glib::ustring juci_section_xml = R"RAW(
+ + _About + app.about + +
+
+ + _Preferences + app.preferences + +
+
+ + _Snippets + app.snippets + + + _Commands + app.commands + +
+
+ + _Quit + app.quit + +
+)RAW"; + +#ifdef __APPLE__ +const Glib::ustring juci_menu_xml = "" + juci_section_xml + ""; +const Glib::ustring juci_submenu_xml = ""; +#else +const Glib::ustring juci_menu_xml = ""; +const Glib::ustring juci_submenu_xml = "juCi++" + juci_section_xml + ""; +#endif + const Glib::ustring menu_xml = R"RAW(
@@ -88,38 +126,10 @@ const Glib::ustring menu_xml = R"RAW(
+ )RAW" + juci_menu_xml + R"RAW( + - - _juci++ -
- - _About - app.about - -
-
- - _Preferences - app.preferences - -
-
- - _Snippets - app.snippets - - - _Commands - app.commands - -
-
- - _Quit - app.quit - -
-
+ )RAW" + juci_submenu_xml + R"RAW( _File
@@ -612,7 +622,9 @@ void Menu::set_keys() { void Menu::build() { try { builder = Gtk::Builder::create_from_string(menu_xml); - auto object = builder->get_object("window-menu"); + auto object = builder->get_object("juci-menu"); + juci_menu = Glib::RefPtr::cast_dynamic(object); + object = builder->get_object("window-menu"); window_menu = Glib::RefPtr::cast_dynamic(object); object = builder->get_object("right-click-line-menu"); auto ptr = Glib::RefPtr::cast_dynamic(object); diff --git a/src/menu.hpp b/src/menu.hpp index b2e81a1..224ea73 100644 --- a/src/menu.hpp +++ b/src/menu.hpp @@ -20,6 +20,7 @@ public: void build(); + Glib::RefPtr juci_menu; Glib::RefPtr window_menu; std::unique_ptr right_click_line_menu; std::unique_ptr right_click_selected_menu;