From f23a54c58a0ef8e4a256fc6d3e2465baa021aa02 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 8 Sep 2024 17:48:19 +0300 Subject: [PATCH] update menu build --- po/POTFILES.in | 2 + src/app/browser.cpp | 13 +- src/app/browser/header.cpp | 43 +++--- src/app/browser/header.hpp | 11 +- src/app/browser/header/menu.cpp | 246 +++++++++++++++----------------- src/app/browser/header/menu.hpp | 40 ++---- 6 files changed, 177 insertions(+), 178 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index f91583d3..b27b62e1 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,6 +4,8 @@ src/app/browser/header/main.cpp src/app/browser/header/main/subtitle.cpp src/app/browser/header/main/title.cpp src/app/browser/header/menu.cpp +src/app/browser/header/menu/tab.cpp +src/app/browser/header/menu/tools.cpp src/app/browser/header/tab.cpp src/app/browser/main.cpp src/app/browser/main/tab.cpp diff --git a/src/app/browser.cpp b/src/app/browser.cpp index 167113b6..6954a2da 100644 --- a/src/app/browser.cpp +++ b/src/app/browser.cpp @@ -22,7 +22,7 @@ Browser::Browser( } ); - add_action( + const auto ACTION__DEBUG = add_action( "debug", [this] { @@ -38,7 +38,7 @@ Browser::Browser( "i" ); - add_action( + const auto ACTION__MAIN_TAB_APPEND = add_action( "main_tab_append", [this] { @@ -151,7 +151,14 @@ Browser::Browser( ); // Init components - browserHeader = Gtk::make_managed(); + browserHeader = Gtk::make_managed( + ACTION__DEBUG, + ACTION__MAIN_TAB_APPEND, + ACTION__MAIN_TAB_CLOSE, + ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK, + ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD, + ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE + ); set_titlebar( * browserHeader diff --git a/src/app/browser/header.cpp b/src/app/browser/header.cpp index d79b4378..28f1acad 100644 --- a/src/app/browser/header.cpp +++ b/src/app/browser/header.cpp @@ -5,33 +5,44 @@ using namespace app::browser; -Header::Header() -{ - // Init header bar +Header::Header( + const Glib::RefPtr & ACTION__DEBUG, + const Glib::RefPtr & ACTION__MAIN_TAB_APPEND, + const Glib::RefPtr & ACTION__MAIN_TAB_CLOSE, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE +) { + // Init widget set_show_title_buttons( SHOW_TITLE_BUTTONS ); - // Init menu - headerMenu = Gtk::make_managed(); - - pack_start( - * headerMenu + // Init components + headerMenu = Gtk::make_managed( + ACTION__DEBUG, + ACTION__MAIN_TAB_APPEND, + ACTION__MAIN_TAB_CLOSE, + ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK, + ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD, + ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE ); - // Init tab + pack_start( + * headerMenu + ); + headerTab = Gtk::make_managed(); - pack_start( - * headerTab - ); + pack_start( + * headerTab + ); - // Init main widget headerMain = Gtk::make_managed(); - set_title_widget( - * headerMain - ); + set_title_widget( + * headerMain + ); } void Header::refresh( diff --git a/src/app/browser/header.hpp b/src/app/browser/header.hpp index 31b0d1e6..4f90f296 100644 --- a/src/app/browser/header.hpp +++ b/src/app/browser/header.hpp @@ -1,6 +1,8 @@ #ifndef APP_BROWSER_HEADER_HPP #define APP_BROWSER_HEADER_HPP +#include +#include #include #include #include @@ -26,7 +28,14 @@ namespace app::browser public: - Header(); + Header( + const Glib::RefPtr & ACTION__DEBUG, + const Glib::RefPtr & ACTION__MAIN_TAB_APPEND, + const Glib::RefPtr & ACTION__MAIN_TAB_CLOSE, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE + ); void refresh( const Glib::ustring & TITLE, diff --git a/src/app/browser/header/menu.cpp b/src/app/browser/header/menu.cpp index 1402a84c..285e165a 100644 --- a/src/app/browser/header/menu.cpp +++ b/src/app/browser/header/menu.cpp @@ -2,158 +2,144 @@ using namespace app::browser::header; -Menu::Menu() -{ +Menu::Menu( + const Glib::RefPtr & ACTION__DEBUG, + const Glib::RefPtr & ACTION__MAIN_TAB_APPEND, + const Glib::RefPtr & ACTION__MAIN_TAB_CLOSE, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE +) { + // Init widget set_tooltip_text( _("Menu") ); - set_menu_model( - main( - main_tab( - main_tab_page( - main_tab_page_navigation( - main_tab_page_navigation_history() - ) - ), - main_tab_close() - ), - main_tools() - ) - ); -} - -Glib::RefPtr Menu::main( - const Glib::RefPtr & MAIN_TAB, - const Glib::RefPtr & MAIN_TOOLS -) { - auto menu = Gio::Menu::create(); - - menu->append_submenu( - _("Tab"), - MAIN_TAB - ); - - menu->append_submenu( - _("Tools"), - MAIN_TOOLS - ); + // Init components @TODO make builder + const auto MENU__MAIN = Gio::Menu::create(); - menu->append( - _("Quit"), - "app.quit" - ); + const auto MENU__MAIN_TAB = Gio::Menu::create(); - return menu; -} + MENU__MAIN_TAB->append( + _("New.."), + get_action_detailed_name( + ACTION__MAIN_TAB_APPEND + ) + ); -Glib::RefPtr Menu::main_tab( - const Glib::RefPtr & MAIN_TAB_PAGE, - const Glib::RefPtr & MAIN_TAB_CLOSE -) { - auto menu = Gio::Menu::create(); + const auto MENU__MAIN_TAB_PAGE = Gio::Menu::create(); - menu->append( - _("New.."), - "win.main_tab_append" - ); + const auto MENU__MAIN_TAB_PAGE_NAVIGATION = Gio::Menu::create(); - menu->append_submenu( - _("Page"), - MAIN_TAB_PAGE - ); + const auto MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY = Gio::Menu::create(); - menu->append_submenu( - _("Close"), - MAIN_TAB_CLOSE - ); + MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY->append( + _("Back"), + get_action_detailed_name( + ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK + ) + ); - return menu; -} + MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY->append( + _("Forward"), + get_action_detailed_name( + ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD + ) + ); -Glib::RefPtr Menu::main_tab_page( - const Glib::RefPtr & MAIN_TAB_PAGE_NAVIGATION -) { - auto menu = Gio::Menu::create(); + MENU__MAIN_TAB_PAGE_NAVIGATION->append_submenu( + _("History"), + MENU__MAIN_TAB_PAGE_NAVIGATION_HISTORY + ); - menu->append_submenu( - _("Navigation"), - MAIN_TAB_PAGE_NAVIGATION - ); + MENU__MAIN_TAB_PAGE_NAVIGATION->append( + _("Update"), + get_action_detailed_name( + ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE + ) + ); - return menu; -} + MENU__MAIN_TAB_PAGE->append_submenu( + _("Navigation"), + MENU__MAIN_TAB_PAGE_NAVIGATION + ); -Glib::RefPtr Menu::main_tab_page_navigation( - const Glib::RefPtr & MAIN_TAB_PAGE_NAVIGATION_HISTORY -) { - auto menu = Gio::Menu::create(); + MENU__MAIN_TAB->append_submenu( + _("Page"), + MENU__MAIN_TAB_PAGE + ); - menu->append_submenu( - _("History"), - MAIN_TAB_PAGE_NAVIGATION_HISTORY - ); + const auto MENU__MAIN_TAB_CLOSE = Gio::Menu::create(); - menu->append( - _("Update"), - "win.main_tab_page_navigation_update" - ); - - return menu; -} - -Glib::RefPtr Menu::main_tab_page_navigation_history() -{ - auto menu = Gio::Menu::create(); - - menu->append( - _("Back"), - "win.main_tab_page_navigation_history_back" - ); - - menu->append( - _("Forward"), - "win.main_tab_page_navigation_history_forward" - ); - - return menu; -} - -Glib::RefPtr Menu::main_tab_close() -{ - auto menu = Gio::Menu::create(); - - menu->append( - _("Active tab"), - "win.main_tab_close" - ); + MENU__MAIN_TAB_CLOSE->append( + _("Active tab"), + get_action_detailed_name( + ACTION__MAIN_TAB_CLOSE + ) + ); + + // @TODO + /* + MENU__MAIN_TAB_CLOSE->append( + _("All tabs to left"), + get_action_detailed_name( + ACTION__MAIN_TAB_CLOSE + ) + ); - menu->append( - _("All tabs to left"), - "win.main_tab_close_left" - ); + MENU__MAIN_TAB_CLOSE->append( + _("All tabs to right"), + get_action_detailed_name( + ACTION__MAIN_TAB_CLOSE + ) + ); - menu->append( - _("All tabs to right"), - "win.main_tab_close_right" - ); + MENU__MAIN_TAB_CLOSE->append( + _("All tabs"), + get_action_detailed_name( + ACTION__MAIN_TAB_CLOSE + ) + ); + */ + + MENU__MAIN_TAB->append_submenu( + _("Close"), + MENU__MAIN_TAB_CLOSE + ); + + MENU__MAIN->append_submenu( + _("Tab"), + MENU__MAIN_TAB + ); + + const auto MENU__MAIN_TOOLS = Gio::Menu::create(); + + MENU__MAIN_TOOLS->append( + _("Debug"), + get_action_detailed_name( + ACTION__DEBUG + ) + ); + + MENU__MAIN->append_submenu( + _("Tools"), + MENU__MAIN_TOOLS + ); + + MENU__MAIN->append( + _("Quit"), + "app.quit" // @TODO + ); - menu->append( - _("All tabs"), - "win.main_tab_close_all" + set_menu_model( + MENU__MAIN ); - - return menu; } -Glib::RefPtr Menu::main_tools() -{ - auto menu = Gio::Menu::create(); - - menu->append( - _("Debug"), - "win.debug" +Glib::ustring Menu::get_action_detailed_name( + const Glib::RefPtr & ACTION +) { + return Glib::ustring::sprintf( + "win.%s", ACTION->get_name() ); - - return menu; } \ No newline at end of file diff --git a/src/app/browser/header/menu.hpp b/src/app/browser/header/menu.hpp index 2e171109..bf57677d 100644 --- a/src/app/browser/header/menu.hpp +++ b/src/app/browser/header/menu.hpp @@ -2,45 +2,29 @@ #define APP_BROWSER_HEADER_MENU_HPP #include +#include #include +#include #include namespace app::browser::header { class Menu : public Gtk::MenuButton { - // 1 level - static Glib::RefPtr main( - const Glib::RefPtr & MAIN_TAB, - const Glib::RefPtr & MAIN_TOOLS + static Glib::ustring get_action_detailed_name( + const Glib::RefPtr & ACTION ); - // 2 level - static Glib::RefPtr main_tab( - const Glib::RefPtr & MAIN_TAB_PAGE, - const Glib::RefPtr & MAIN_TAB_CLOSE - ); - - // 3 level - static Glib::RefPtr main_tab_page( - const Glib::RefPtr & MAIN_TAB_PAGE_NAVIGATION - ); - - // 4 level - static Glib::RefPtr main_tab_page_navigation( - const Glib::RefPtr & MAIN_TAB_PAGE_NAVIGATION_HISTORY - ); - - // 5 level - static Glib::RefPtr main_tab_page_navigation_history(); - - static Glib::RefPtr main_tab_close(); - - static Glib::RefPtr main_tools(); - public: - Menu(); + Menu( + const Glib::RefPtr & ACTION__DEBUG, + const Glib::RefPtr & ACTION__MAIN_TAB_APPEND, + const Glib::RefPtr & ACTION__MAIN_TAB_CLOSE, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD, + const Glib::RefPtr & ACTION__MAIN_TAB_PAGE_NAVIGATION_UPDATE + ); }; }