From d63ba8f1adcaccaf674f51b56e45b7c9782f92ba Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 5 Sep 2024 16:40:41 +0300 Subject: [PATCH] update actions --- src/app/browser.cpp | 93 +++++++++---------- src/app/browser/header/menu.cpp | 2 +- src/app/browser/main.cpp | 26 +++--- src/app/browser/main.hpp | 2 +- src/app/browser/main/tab.cpp | 15 +-- src/app/browser/main/tab.hpp | 26 +++--- src/app/browser/main/tab/page.cpp | 17 ---- src/app/browser/main/tab/page.hpp | 1 - .../main/tab/page/navigation/request.cpp | 2 +- .../main/tab/page/navigation/update.cpp | 2 +- src/main.cpp | 20 ++-- 11 files changed, 88 insertions(+), 118 deletions(-) diff --git a/src/app/browser.cpp b/src/app/browser.cpp index 25aa7e53..98b1ef00 100644 --- a/src/app/browser.cpp +++ b/src/app/browser.cpp @@ -32,100 +32,97 @@ Browser::Browser( * browserMain ); - // Init actions + // Init browser window actions add_action( - "main_tab_append", + "refresh", [this] { - browserMain->tab_append(); - } - ); + browserMain->refresh(); - add_action( - "main_tab_page_update", - [this] - { - browserMain->tab_update(); + browserHeader->set_title( + browserMain->get_current_tab_page_title() + ); + + browserHeader->set_subtitle( + browserMain->get_current_tab_page_subtitle() + ); } ); - // Close add_action( - "main_tab_close", + "debug", [this] { - browserMain->tab_close(); + // @TODO https://gitlab.gnome.org/GNOME/gtkmm/-/commit/5f3b82537d3daad7bda59dd01e719788070f4b6c + gtk_window_set_interactive_debugging( + true + ); } ); - // Close submenu + // Tab actions add_action( - "main_tab_close_left", + "main_tab_append", [this] { - browserMain->tab_close_left(); + browserMain->tab_append(); } ); add_action( - "main_tab_close_right", + "main_tab_close", [this] { - browserMain->tab_close_right(); + browserMain->tab_close(); } ); add_action( - "main_tab_close_all", + "main_tab_close_left", [this] { - browserMain->tab_close_all(); + browserMain->tab_close_left(); } ); - // History add_action( - "main_tab_page_navigation_history_try_back", + "main_tab_close_right", [this] { - browserMain->tab_page_navigation_history_try_back(); + browserMain->tab_close_right(); } ); add_action( - "main_tab_page_navigation_history_try_forward", + "main_tab_close_all", [this] { - browserMain->tab_page_navigation_history_try_forward(); + browserMain->tab_close_all(); } ); - // Tool - add_action( - "debug", - [this] - { - // @TODO https://gitlab.gnome.org/GNOME/gtkmm/-/commit/5f3b82537d3daad7bda59dd01e719788070f4b6c - gtk_window_set_interactive_debugging( - true + // Tab page navigation actions + add_action( + "main_tab_page_navigation_update", + [this] + { + browserMain->tab_page_update(); + } ); - } - ); - - // Hidden - add_action( - "refresh", - [this] - { - browserMain->refresh(); - browserHeader->set_title( - browserMain->get_current_tab_page_title() + add_action( + "main_tab_page_navigation_history_try_back", + [this] + { + browserMain->tab_page_navigation_history_try_back(); + } ); - browserHeader->set_subtitle( - browserMain->get_current_tab_page_subtitle() + add_action( + "main_tab_page_navigation_history_try_forward", + [this] + { + browserMain->tab_page_navigation_history_try_forward(); + } ); - } - ); } \ No newline at end of file diff --git a/src/app/browser/header/menu.cpp b/src/app/browser/header/menu.cpp index 1ebf5935..77e23bfe 100644 --- a/src/app/browser/header/menu.cpp +++ b/src/app/browser/header/menu.cpp @@ -96,7 +96,7 @@ Glib::RefPtr Menu::main_tab_page_navigation( menu->append( _("Update"), - "win.main_tab_page_update" + "win.main_tab_page_navigation_update" ); return menu; diff --git a/src/app/browser/main.cpp b/src/app/browser/main.cpp index 8a3e69d5..e15b382d 100644 --- a/src/app/browser/main.cpp +++ b/src/app/browser/main.cpp @@ -38,17 +38,17 @@ Glib::ustring Main::get_current_tab_page_subtitle() }; // Actions -void Main::tab_append() +void Main::refresh() { - mainTab->append( - _("New page") + mainTab->refresh( + mainTab->get_current_page() ); }; -void Main::tab_update() +void Main::tab_append() { - mainTab->update( - mainTab->get_current_page() + mainTab->append( + _("New page") ); }; @@ -74,6 +74,13 @@ void Main::tab_close_all() mainTab->close_all(); }; +void Main::tab_page_update() +{ + mainTab->page_update( + mainTab->get_current_page() + ); +}; + bool Main::tab_page_navigation_history_try_back() { const int & PAGE_NUMBER = mainTab->get_current_page(); @@ -102,11 +109,4 @@ bool Main::tab_page_navigation_history_try_forward() } return false; -}; - -void Main::refresh() -{ - mainTab->refresh( - mainTab->get_current_page() - ); }; \ No newline at end of file diff --git a/src/app/browser/main.hpp b/src/app/browser/main.hpp index 5553f2f3..2f495926 100644 --- a/src/app/browser/main.hpp +++ b/src/app/browser/main.hpp @@ -36,7 +36,7 @@ namespace app::browser void tab_close_right(); void tab_close(); - void tab_update(); + void tab_page_update(); bool tab_page_navigation_history_try_back(); bool tab_page_navigation_history_try_forward(); diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index 63975488..c90d6205 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -124,21 +124,12 @@ void Tab::refresh( ); } -void Tab::update( +void Tab::page_update( const int & PAGE_NUMBER ) { - auto pageWidget = get_nth_page( + get_tabPage( PAGE_NUMBER - ); - - if (pageWidget == nullptr) - { - throw _("Tab page not found!"); - } - - pageWidget->activate_action( - "page.update" - ); + )->update(); } // Private helpers diff --git a/src/app/browser/main/tab.hpp b/src/app/browser/main/tab.hpp index b0569fa5..f272801b 100644 --- a/src/app/browser/main/tab.hpp +++ b/src/app/browser/main/tab.hpp @@ -40,6 +40,10 @@ namespace app::browser::main ); // Actions + void refresh( + const int & PAGE_NUMBER // @TODO + ); + void append( const Glib::ustring & TITLE, const Glib::ustring & REQUEST = "", @@ -54,21 +58,17 @@ namespace app::browser::main void close_right(); void close_all(); - bool page_navigation_history_try_back( - const int & PAGE_NUMBER - ); + void page_update( + const int & PAGE_NUMBER + ); - bool page_navigation_history_try_forward( - const int & PAGE_NUMBER - ); + bool page_navigation_history_try_back( + const int & PAGE_NUMBER + ); - void refresh( - const int & PAGE_NUMBER - ); - - void update( - const int & PAGE_NUMBER - ); + bool page_navigation_history_try_forward( + const int & PAGE_NUMBER + ); }; } diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index 812af0f6..9c735174 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -15,23 +15,6 @@ Page::Page( Gtk::Orientation::VERTICAL ); - // Init actions group - auto GioSimpleActionGroup = Gio::SimpleActionGroup::create(); - - // Define group actions - GioSimpleActionGroup->add_action( - "update", - [this] - { - Page::update(); - } - ); - - insert_action_group( - "page", - GioSimpleActionGroup - ); - // Init components pageNavigation = Gtk::make_managed( REQUEST diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index bd5dea7a..de93ba7b 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/src/app/browser/main/tab/page/navigation/request.cpp b/src/app/browser/main/tab/page/navigation/request.cpp index 721563fc..ae37345f 100644 --- a/src/app/browser/main/tab/page/navigation/request.cpp +++ b/src/app/browser/main/tab/page/navigation/request.cpp @@ -42,7 +42,7 @@ Request::Request( parse(); activate_action( - "page.update" + "win.main_tab_page_navigation_update" ); } ); diff --git a/src/app/browser/main/tab/page/navigation/update.cpp b/src/app/browser/main/tab/page/navigation/update.cpp index c8cf4d6a..20d50381 100644 --- a/src/app/browser/main/tab/page/navigation/update.cpp +++ b/src/app/browser/main/tab/page/navigation/update.cpp @@ -5,7 +5,7 @@ using namespace app::browser::main::tab::page::navigation; Update::Update() { set_action_name( - "page.update" + "win.main_tab_page_navigation_update" ); set_icon_name( diff --git a/src/main.cpp b/src/main.cpp index 830f4f79..ff3026df 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,16 +27,6 @@ int main( ); // Init accels @TODO db settings - app->set_accel_for_action( - "win.main_tab_append", - "t" - ); - - app->set_accel_for_action( - "win.main_tab_page_update", - "r" - ); - app->set_accel_for_action( "win.debug", "i" @@ -47,6 +37,16 @@ int main( "q" ); + app->set_accel_for_action( + "win.main_tab_append", + "t" + ); + + app->set_accel_for_action( + "win.main_tab_page_navigation_update", + "r" + ); + // Launch browser component return app->make_window_and_run( argc,