Browse Source

update history actions api

CPP-GTK4
yggverse 3 months ago
parent
commit
0a09de1fdd
  1. 14
      src/app/browser.cpp
  2. 4
      src/app/browser/header/menu.cpp
  3. 37
      src/app/browser/main.cpp
  4. 11
      src/app/browser/main.hpp
  5. 12
      src/app/browser/main/tab.cpp
  6. 6
      src/app/browser/main/tab.hpp
  7. 30
      src/app/browser/main/tab/page.cpp
  8. 4
      src/app/browser/main/tab/page.hpp
  9. 70
      src/app/browser/main/tab/page/navigation.cpp
  10. 13
      src/app/browser/main/tab/page/navigation.hpp
  11. 2
      src/app/browser/main/tab/page/navigation/history/back.cpp
  12. 2
      src/app/browser/main/tab/page/navigation/history/forward.cpp

14
src/app/browser.cpp

@ -104,27 +104,25 @@ Browser::Browser(
// Tab page navigation actions // Tab page navigation actions
add_action( add_action(
"main_tab_page_navigation_update", "main_tab_page_navigation_update",
[this](const bool & ADD_HISTORY = false) [this]()
{ {
browserMain->tab_page_navigation_update( browserMain->tab_page_navigation_update();
ADD_HISTORY
);
} }
); );
add_action( add_action(
"main_tab_page_navigation_history_try_back", "main_tab_page_navigation_history_back",
[this]() [this]()
{ {
browserMain->tab_page_navigation_history_try_back(); browserMain->tab_page_navigation_history_back();
} }
); );
add_action( add_action(
"main_tab_page_navigation_history_try_forward", "main_tab_page_navigation_history_forward",
[this] [this]
{ {
browserMain->tab_page_navigation_history_try_forward(); browserMain->tab_page_navigation_history_forward();
} }
); );
} }

4
src/app/browser/header/menu.cpp

@ -108,12 +108,12 @@ Glib::RefPtr<Gio::Menu> Menu::main_tab_page_navigation_history()
menu->append( menu->append(
_("Back"), _("Back"),
"win.main_tab_page_navigation_history_try_back" "win.main_tab_page_navigation_history_back"
); );
menu->append( menu->append(
_("Forward"), _("Forward"),
"win.main_tab_page_navigation_history_try_forward" "win.main_tab_page_navigation_history_forward"
); );
return menu; return menu;

37
src/app/browser/main.cpp

@ -74,39 +74,22 @@ void Main::tab_close_all()
mainTab->close_all(); mainTab->close_all();
}; };
void Main::tab_page_navigation_update( void Main::tab_page_navigation_update() {
const bool & ADD_HISTORY
) {
mainTab->page_navigation_update( mainTab->page_navigation_update(
mainTab->get_current_page(), // @TODO mainTab->get_current_page() // @TODO
ADD_HISTORY
); );
}; };
bool Main::tab_page_navigation_history_try_back() void Main::tab_page_navigation_history_back()
{ {
const int & PAGE_NUMBER = mainTab->get_current_page(); mainTab->page_navigation_history_back(
mainTab->get_current_page() // @TODO
if (PAGE_NUMBER >= 0) );
{
return mainTab->page_navigation_history_try_back(
PAGE_NUMBER
);
}
return false;
}; };
bool Main::tab_page_navigation_history_try_forward() void Main::tab_page_navigation_history_forward()
{ {
const int & PAGE_NUMBER = mainTab->get_current_page(); mainTab->page_navigation_history_forward(
mainTab->get_current_page() // @TODO
if (PAGE_NUMBER >= 0) );
{
return mainTab->page_navigation_history_try_forward(
PAGE_NUMBER
);
}
return false;
}; };

11
src/app/browser/main.hpp

@ -38,14 +38,9 @@ namespace app::browser
void tab_close_right(); void tab_close_right();
void tab_close(); void tab_close();
void tab_page_navigation_update( void tab_page_navigation_update();
const bool & ADD_HISTORY void tab_page_navigation_history_back();
); void tab_page_navigation_history_forward();
bool tab_page_navigation_history_try_back();
bool tab_page_navigation_history_try_forward();
}; };
} }

12
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 const int & PAGE_NUMBER
) { ) {
return get_tabPage( get_tabPage(
PAGE_NUMBER 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 const int & PAGE_NUMBER
) { ) {
return get_tabPage( get_tabPage(
PAGE_NUMBER PAGE_NUMBER
)->navigation_history_try_forward(); )->navigation_history_forward();
} }
// Private helpers // Private helpers

6
src/app/browser/main/tab.hpp

@ -60,14 +60,14 @@ namespace app::browser::main
void page_navigation_update( void page_navigation_update(
const int & PAGE_NUMBER, 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 const int & PAGE_NUMBER
); );
bool page_navigation_history_try_forward( void page_navigation_history_forward(
const int & PAGE_NUMBER const int & PAGE_NUMBER
); );
}; };

30
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
);
}
} }

4
src/app/browser/main/tab/page.hpp

@ -63,8 +63,8 @@ namespace app::browser::main::tab
const bool & ADD_HISTORY const bool & ADD_HISTORY
); );
bool navigation_history_try_back(); void navigation_history_back();
bool navigation_history_try_forward(); void navigation_history_forward();
}; };
} }

70
src/app/browser/main/tab/page/navigation.cpp

@ -87,47 +87,11 @@ Navigation::Navigation(
} }
// Actions // 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( void Navigation::history_add(
const Glib::ustring & VALUE const Glib::ustring & REQUEST
) { ) {
navigationHistory->add( navigationHistory->add(
VALUE REQUEST
); );
} }
@ -188,3 +152,33 @@ Glib::ustring Navigation::get_request_port()
{ {
return navigationRequest->get_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;
}

13
src/app/browser/main/tab/page/navigation.hpp

@ -38,12 +38,9 @@ namespace app::browser::main::tab::page
// Actions // Actions
void history_add( void history_add(
const Glib::ustring & VALUE const Glib::ustring & REQUEST
); );
bool history_try_back();
bool history_try_forward();
void refresh(); void refresh();
// Setters // Setters
@ -59,6 +56,14 @@ namespace app::browser::main::tab::page
Glib::ustring get_request_port(); Glib::ustring get_request_port();
Glib::ustring get_request_path(); Glib::ustring get_request_path();
Glib::ustring get_request_query(); Glib::ustring get_request_query();
bool try_history_back(
Glib::ustring & request
);
bool try_history_forward(
Glib::ustring & request
);
}; };
} }

2
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() Back::Back()
{ {
set_action_name( set_action_name(
"win.main_tab_page_navigation_history_try_back" "win.main_tab_page_navigation_history_back"
); );
set_icon_name( set_icon_name(

2
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() Forward::Forward()
{ {
set_action_name( set_action_name(
"win.main_tab_page_navigation_history_try_forward" "win.main_tab_page_navigation_history_forward"
); );
set_icon_name( set_icon_name(

Loading…
Cancel
Save