From 0a09de1fddc7c24f40637a5fa213acc087a77b09 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 5 Sep 2024 22:04:01 +0300 Subject: [PATCH] update history actions api --- src/app/browser.cpp | 14 ++-- src/app/browser/header/menu.cpp | 4 +- src/app/browser/main.cpp | 37 +++------- src/app/browser/main.hpp | 11 +-- src/app/browser/main/tab.cpp | 12 ++-- src/app/browser/main/tab.hpp | 6 +- src/app/browser/main/tab/page.cpp | 30 ++++++-- src/app/browser/main/tab/page.hpp | 4 +- src/app/browser/main/tab/page/navigation.cpp | 70 +++++++++---------- src/app/browser/main/tab/page/navigation.hpp | 13 ++-- .../main/tab/page/navigation/history/back.cpp | 2 +- .../tab/page/navigation/history/forward.cpp | 2 +- 12 files changed, 101 insertions(+), 104 deletions(-) diff --git a/src/app/browser.cpp b/src/app/browser.cpp index 1db8ec36..20e67bf4 100644 --- a/src/app/browser.cpp +++ b/src/app/browser.cpp @@ -104,27 +104,25 @@ Browser::Browser( // Tab page navigation actions add_action( "main_tab_page_navigation_update", - [this](const bool & ADD_HISTORY = false) + [this]() { - browserMain->tab_page_navigation_update( - ADD_HISTORY - ); + browserMain->tab_page_navigation_update(); } ); add_action( - "main_tab_page_navigation_history_try_back", + "main_tab_page_navigation_history_back", [this]() { - browserMain->tab_page_navigation_history_try_back(); + browserMain->tab_page_navigation_history_back(); } ); add_action( - "main_tab_page_navigation_history_try_forward", + "main_tab_page_navigation_history_forward", [this] { - browserMain->tab_page_navigation_history_try_forward(); + browserMain->tab_page_navigation_history_forward(); } ); } \ No newline at end of file diff --git a/src/app/browser/header/menu.cpp b/src/app/browser/header/menu.cpp index 77e23bfe..1402a84c 100644 --- a/src/app/browser/header/menu.cpp +++ b/src/app/browser/header/menu.cpp @@ -108,12 +108,12 @@ Glib::RefPtr Menu::main_tab_page_navigation_history() menu->append( _("Back"), - "win.main_tab_page_navigation_history_try_back" + "win.main_tab_page_navigation_history_back" ); menu->append( _("Forward"), - "win.main_tab_page_navigation_history_try_forward" + "win.main_tab_page_navigation_history_forward" ); return menu; diff --git a/src/app/browser/main.cpp b/src/app/browser/main.cpp index 53d5829e..462f846c 100644 --- a/src/app/browser/main.cpp +++ b/src/app/browser/main.cpp @@ -74,39 +74,22 @@ void Main::tab_close_all() mainTab->close_all(); }; -void Main::tab_page_navigation_update( - const bool & ADD_HISTORY -) { +void Main::tab_page_navigation_update() { mainTab->page_navigation_update( - mainTab->get_current_page(), // @TODO - ADD_HISTORY + mainTab->get_current_page() // @TODO ); }; -bool Main::tab_page_navigation_history_try_back() +void Main::tab_page_navigation_history_back() { - const int & PAGE_NUMBER = mainTab->get_current_page(); - - if (PAGE_NUMBER >= 0) - { - return mainTab->page_navigation_history_try_back( - PAGE_NUMBER - ); - } - - return false; + mainTab->page_navigation_history_back( + mainTab->get_current_page() // @TODO + ); }; -bool Main::tab_page_navigation_history_try_forward() +void Main::tab_page_navigation_history_forward() { - const int & PAGE_NUMBER = mainTab->get_current_page(); - - if (PAGE_NUMBER >= 0) - { - return mainTab->page_navigation_history_try_forward( - PAGE_NUMBER - ); - } - - return false; + mainTab->page_navigation_history_forward( + mainTab->get_current_page() // @TODO + ); }; \ No newline at end of file diff --git a/src/app/browser/main.hpp b/src/app/browser/main.hpp index 960c01c5..3b8fca37 100644 --- a/src/app/browser/main.hpp +++ b/src/app/browser/main.hpp @@ -38,14 +38,9 @@ namespace app::browser void tab_close_right(); void tab_close(); - void tab_page_navigation_update( - const bool & ADD_HISTORY - ); - - bool tab_page_navigation_history_try_back(); - bool tab_page_navigation_history_try_forward(); - - + void tab_page_navigation_update(); + void tab_page_navigation_history_back(); + void tab_page_navigation_history_forward(); }; } diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index 2eb04193..10366fa8 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -118,20 +118,20 @@ void Tab::page_navigation_update( ); } -bool Tab::page_navigation_history_try_back( +void Tab::page_navigation_history_back( const int & PAGE_NUMBER ) { - return get_tabPage( + get_tabPage( PAGE_NUMBER - )->navigation_history_try_back(); + )->navigation_history_back(); } -bool Tab::page_navigation_history_try_forward( +void Tab::page_navigation_history_forward( const int & PAGE_NUMBER ) { - return get_tabPage( + get_tabPage( PAGE_NUMBER - )->navigation_history_try_forward(); + )->navigation_history_forward(); } // Private helpers diff --git a/src/app/browser/main/tab.hpp b/src/app/browser/main/tab.hpp index 00085d42..34e4ca98 100644 --- a/src/app/browser/main/tab.hpp +++ b/src/app/browser/main/tab.hpp @@ -60,14 +60,14 @@ namespace app::browser::main void page_navigation_update( const int & PAGE_NUMBER, - const bool & ADD_HISTORY + const bool & ADD_HISTORY = true ); - bool page_navigation_history_try_back( + void page_navigation_history_back( const int & PAGE_NUMBER ); - bool page_navigation_history_try_forward( + void page_navigation_history_forward( const int & PAGE_NUMBER ); }; diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index 1ee1dd35..23c007c0 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -242,12 +242,34 @@ void Page::navigation_update( } } -bool Page::navigation_history_try_back() +void Page::navigation_history_back() { - return pageNavigation->history_try_back(); + Glib::ustring request; + + if (pageNavigation->try_history_back(request)) + { + pageNavigation->set_request_text( + request + ); + + navigation_update( + false + ); + } } -bool Page::navigation_history_try_forward() +void Page::navigation_history_forward() { - return pageNavigation->history_try_forward(); + Glib::ustring request; + + if (pageNavigation->try_history_forward(request)) + { + pageNavigation->set_request_text( + request + ); + + navigation_update( + false + ); + } } \ No newline at end of file diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 0c5ca31c..2711a23e 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -63,8 +63,8 @@ namespace app::browser::main::tab const bool & ADD_HISTORY ); - bool navigation_history_try_back(); - bool navigation_history_try_forward(); + void navigation_history_back(); + void navigation_history_forward(); }; } diff --git a/src/app/browser/main/tab/page/navigation.cpp b/src/app/browser/main/tab/page/navigation.cpp index 975415ec..69c61565 100644 --- a/src/app/browser/main/tab/page/navigation.cpp +++ b/src/app/browser/main/tab/page/navigation.cpp @@ -87,47 +87,11 @@ Navigation::Navigation( } // Actions -bool Navigation::history_try_back() -{ - navigation::History::Memory match; - - if (navigationHistory->try_back(match)) - { - navigationRequest->set_text( - match.request - ); - - return activate_action( - "win.main_tab_page_navigation_update" - ); - } - - return false; -} - -bool Navigation::history_try_forward() -{ - navigation::History::Memory match; - - if (navigationHistory->try_forward(match)) - { - navigationRequest->set_text( - match.request - ); - - return activate_action( - "win.main_tab_page_navigation_update" - ); - } - - return false; -} - void Navigation::history_add( - const Glib::ustring & VALUE + const Glib::ustring & REQUEST ) { navigationHistory->add( - VALUE + REQUEST ); } @@ -187,4 +151,34 @@ Glib::ustring Navigation::get_request_query() Glib::ustring Navigation::get_request_port() { return navigationRequest->get_port(); +} + +bool Navigation::try_history_back( + Glib::ustring & request +) { + navigation::History::Memory match; + + if (navigationHistory->try_back(match)) + { + request = match.request; + + return true; + } + + return false; +} + +bool Navigation::try_history_forward( + Glib::ustring & request +) { + navigation::History::Memory match; + + if (navigationHistory->try_forward(match)) + { + request = match.request; + + return true; + } + + return false; } \ No newline at end of file diff --git a/src/app/browser/main/tab/page/navigation.hpp b/src/app/browser/main/tab/page/navigation.hpp index 14455a79..2370d67d 100644 --- a/src/app/browser/main/tab/page/navigation.hpp +++ b/src/app/browser/main/tab/page/navigation.hpp @@ -38,12 +38,9 @@ namespace app::browser::main::tab::page // Actions void history_add( - const Glib::ustring & VALUE + const Glib::ustring & REQUEST ); - bool history_try_back(); - bool history_try_forward(); - void refresh(); // Setters @@ -59,6 +56,14 @@ namespace app::browser::main::tab::page Glib::ustring get_request_port(); Glib::ustring get_request_path(); Glib::ustring get_request_query(); + + bool try_history_back( + Glib::ustring & request + ); + + bool try_history_forward( + Glib::ustring & request + ); }; } diff --git a/src/app/browser/main/tab/page/navigation/history/back.cpp b/src/app/browser/main/tab/page/navigation/history/back.cpp index d4b6f49f..e49d1103 100644 --- a/src/app/browser/main/tab/page/navigation/history/back.cpp +++ b/src/app/browser/main/tab/page/navigation/history/back.cpp @@ -5,7 +5,7 @@ using namespace app::browser::main::tab::page::navigation::history; Back::Back() { set_action_name( - "win.main_tab_page_navigation_history_try_back" + "win.main_tab_page_navigation_history_back" ); set_icon_name( diff --git a/src/app/browser/main/tab/page/navigation/history/forward.cpp b/src/app/browser/main/tab/page/navigation/history/forward.cpp index 4091032b..f261545f 100644 --- a/src/app/browser/main/tab/page/navigation/history/forward.cpp +++ b/src/app/browser/main/tab/page/navigation/history/forward.cpp @@ -5,7 +5,7 @@ using namespace app::browser::main::tab::page::navigation::history; Forward::Forward() { set_action_name( - "win.main_tab_page_navigation_history_try_forward" + "win.main_tab_page_navigation_history_forward" ); set_icon_name(