diff --git a/src/app/browser.cpp b/src/app/browser.cpp index daa0f30f..46fa5792 100644 --- a/src/app/browser.cpp +++ b/src/app/browser.cpp @@ -9,7 +9,7 @@ Browser::Browser( //const std::shared_ptr & db ) { // Init window actions - add_action( + const auto ACTION__REFRESH = add_action( "refresh", [this] { @@ -45,14 +45,12 @@ Browser::Browser( } ); - add_action( + const auto ACTION__MAIN_TAB_CLOSE = add_action( "main_tab_close", [this] { browserMain->tab_close(); } - )->set_enabled( - false ); add_action( @@ -96,24 +94,20 @@ Browser::Browser( false ); - add_action( + const auto ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK = add_action( "main_tab_page_navigation_history_back", [this] { browserMain->tab_page_navigation_history_back(); } - )->set_enabled( - false ); - add_action( + const auto ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD = add_action( "main_tab_page_navigation_history_forward", [this] { browserMain->tab_page_navigation_history_forward(); } - )->set_enabled( - false ); // Init widget @@ -134,7 +128,12 @@ Browser::Browser( ); // Init main widget - browserMain = Gtk::make_managed(); + browserMain = Gtk::make_managed( + ACTION__REFRESH, + ACTION__MAIN_TAB_CLOSE, + ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK, + ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD + ); set_child( * browserMain diff --git a/src/app/browser.hpp b/src/app/browser.hpp index 2bc8840f..e4081653 100644 --- a/src/app/browser.hpp +++ b/src/app/browser.hpp @@ -1,7 +1,9 @@ #ifndef APP_BROWSER_HPP #define APP_BROWSER_HPP +#include #include +#include #include #include @@ -20,9 +22,11 @@ namespace app class Browser : public Gtk::ApplicationWindow { + // Components app::browser::Header * browserHeader; app::browser::Main * browserMain; + // Defaults const int WIDTH = 640; const int HEIGHT = 480; diff --git a/src/app/browser/main.cpp b/src/app/browser/main.cpp index 38c8548b..ecda54a7 100644 --- a/src/app/browser/main.cpp +++ b/src/app/browser/main.cpp @@ -3,8 +3,12 @@ using namespace app::browser; -Main::Main() -{ +Main::Main( + const Glib::RefPtr & ACTION__REFRESH, + 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 +) { // Init container set_orientation( Gtk::Orientation::VERTICAL @@ -15,7 +19,12 @@ Main::Main() ); // Init tabs - mainTab = Gtk::make_managed(); + mainTab = Gtk::make_managed( + ACTION__REFRESH, + ACTION__MAIN_TAB_CLOSE, + ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK, + ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD + ); append( * mainTab diff --git a/src/app/browser/main.hpp b/src/app/browser/main.hpp index bdacc6f6..04eec670 100644 --- a/src/app/browser/main.hpp +++ b/src/app/browser/main.hpp @@ -1,7 +1,9 @@ #ifndef APP_BROWSER_MAIN_HPP #define APP_BROWSER_MAIN_HPP +#include #include +#include #include #include #include @@ -23,7 +25,12 @@ namespace app::browser public: - Main(); + Main( + const Glib::RefPtr & ACTION__REFRESH, + 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 + ); // Actions void refresh(); diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index c70425bc..6a9ec258 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -4,21 +4,29 @@ using namespace app::browser::main; -Tab::Tab() -{ +Tab::Tab( + const Glib::RefPtr & ACTION__REFRESH, + const Glib::RefPtr & ACTION__TAB_CLOSE, + const Glib::RefPtr & ACTION__TAB_PAGE_NAVIGATION_HISTORY_BACK, + const Glib::RefPtr & ACTION__TAB_PAGE_NAVIGATION_HISTORY_FORWARD +) { + // Init actions + action__refresh = ACTION__REFRESH; + action__tab_close = ACTION__TAB_CLOSE; + action__tab_page_navigation_history_back = ACTION__TAB_PAGE_NAVIGATION_HISTORY_BACK; + action__tab_page_navigation_history_forward = ACTION__TAB_PAGE_NAVIGATION_HISTORY_FORWARD; + // Init widget set_scrollable( SCROLLABLE ); - // Init events + // Init event listeners signal_switch_page().connect( [this](Gtk::Widget*, guint) { // Refresh window elements, e.g. tab label to header bar - activate_action( - "win.refresh" - ); + action__refresh->activate(); } ); } @@ -31,7 +39,9 @@ void Tab::refresh( PAGE_NUMBER ); - get_tabLabel(PAGE_NUMBER)->set_label( + get_tabLabel( + PAGE_NUMBER + )->set_label( tabPage->get_title() ); } @@ -45,11 +55,13 @@ void Tab::append( auto tabPage = new tab::Page( TITLE, SUBTITLE, - REQUEST + REQUEST, + action__tab_page_navigation_history_back, + action__tab_page_navigation_history_forward ); auto tabLabel = new tab::Label( - TITLE + action__tab_close ); int page_number = append_page( diff --git a/src/app/browser/main/tab.hpp b/src/app/browser/main/tab.hpp index 85a5df75..fbe8fb68 100644 --- a/src/app/browser/main/tab.hpp +++ b/src/app/browser/main/tab.hpp @@ -1,7 +1,9 @@ #ifndef APP_BROWSER_MAIN_TAB_HPP #define APP_BROWSER_MAIN_TAB_HPP +#include #include +#include #include #include @@ -15,9 +17,13 @@ namespace app::browser::main class Tab : public Gtk::Notebook { - const bool REORDERABLE = true; - const bool SCROLLABLE = true; + // Actions + Glib::RefPtr action__refresh, + action__tab_close, + action__tab_page_navigation_history_back, + action__tab_page_navigation_history_forward; + // Components tab::Label * get_tabLabel( const int & PAGE_NUMBER ); @@ -26,9 +32,18 @@ namespace app::browser::main const int & PAGE_NUMBER ); + // Defaults + const bool REORDERABLE = true; + const bool SCROLLABLE = true; + public: - Tab(); + Tab( + const Glib::RefPtr & ACTION__REFRESH, + const Glib::RefPtr & ACTION__TAB_CLOSE, + const Glib::RefPtr & ACTION__TAB_PAGE_NAVIGATION_HISTORY_BACK, + const Glib::RefPtr & ACTION__TAB_PAGE_NAVIGATION_HISTORY_FORWARD + ); // Actions void refresh( diff --git a/src/app/browser/main/tab/label.cpp b/src/app/browser/main/tab/label.cpp index e37ee4c1..d146cf9d 100644 --- a/src/app/browser/main/tab/label.cpp +++ b/src/app/browser/main/tab/label.cpp @@ -3,11 +3,10 @@ using namespace app::browser::main::tab; Label::Label( - const Glib::ustring & TEXT + const Glib::RefPtr & ACTION__CLOSE ) { - set_text( - TEXT - ); + // Init actions + action__close = ACTION__CLOSE; // Setup label controller auto GtkGestureClick = Gtk::GestureClick::create(); @@ -22,9 +21,7 @@ Label::Label( { if (n == 2) // double click { - activate_action( - "win.main_tab_close" - ); + action__close->activate(); } } ); diff --git a/src/app/browser/main/tab/label.hpp b/src/app/browser/main/tab/label.hpp index bbcbceb8..d0fab41a 100644 --- a/src/app/browser/main/tab/label.hpp +++ b/src/app/browser/main/tab/label.hpp @@ -1,6 +1,7 @@ #ifndef APP_BROWSER_MAIN_TAB_LABEL_HPP #define APP_BROWSER_MAIN_TAB_LABEL_HPP +#include #include #include #include @@ -11,10 +12,12 @@ namespace app::browser::main::tab { class Label : public Gtk::Label { + Glib::RefPtr action__close; + public: Label( - const Glib::ustring & TEXT + const Glib::RefPtr & ACTION__CLOSE ); }; } diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index b14730c5..dbf571f1 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -7,7 +7,9 @@ using namespace app::browser::main::tab; Page::Page( const Glib::ustring & TITLE, const Glib::ustring & SUBTITLE, - const Glib::ustring & REQUEST + const Glib::ustring & REQUEST, + const Glib::RefPtr & ACTION__PAGE_NAVIGATION_HISTORY_BACK, + const Glib::RefPtr & ACTION__PAGE_NAVIGATION_HISTORY_FORWARD ) { // Init container set_orientation( @@ -16,7 +18,9 @@ Page::Page( // Init components pageNavigation = Gtk::make_managed( - REQUEST + REQUEST, + ACTION__PAGE_NAVIGATION_HISTORY_BACK, + ACTION__PAGE_NAVIGATION_HISTORY_FORWARD ); append( diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index e36c410f..701caf4f 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,9 @@ namespace app::browser::main::tab Page( const Glib::ustring & TITLE, const Glib::ustring & SUBTITLE, - const Glib::ustring & REQUEST + const Glib::ustring & REQUEST, + const Glib::RefPtr & ACTION__PAGE_NAVIGATION_HISTORY_BACK, + const Glib::RefPtr & ACTION__PAGE_NAVIGATION_HISTORY_FORWARD ); // Actions diff --git a/src/app/browser/main/tab/page/navigation.cpp b/src/app/browser/main/tab/page/navigation.cpp index 637634ff..a04ac33e 100644 --- a/src/app/browser/main/tab/page/navigation.cpp +++ b/src/app/browser/main/tab/page/navigation.cpp @@ -8,7 +8,9 @@ using namespace app::browser::main::tab::page; Navigation::Navigation( - const Glib::ustring & REQUEST + const Glib::ustring & REQUEST, + const Glib::RefPtr & ACTION__NAVIGATION_HISTORY_BACK, + const Glib::RefPtr & ACTION__NAVIGATION_HISTORY_FORWARD ) { // Init container set_orientation( @@ -42,7 +44,10 @@ Navigation::Navigation( * navigationBase ); - navigationHistory = Gtk::make_managed(); + navigationHistory = Gtk::make_managed( + ACTION__NAVIGATION_HISTORY_BACK, + ACTION__NAVIGATION_HISTORY_FORWARD + ); append( * navigationHistory diff --git a/src/app/browser/main/tab/page/navigation.hpp b/src/app/browser/main/tab/page/navigation.hpp index 67a9426b..4cc9b0a0 100644 --- a/src/app/browser/main/tab/page/navigation.hpp +++ b/src/app/browser/main/tab/page/navigation.hpp @@ -1,7 +1,9 @@ #ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HPP #define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HPP +#include #include +#include #include #include #include @@ -33,7 +35,9 @@ namespace app::browser::main::tab::page public: Navigation( - const Glib::ustring & REQUEST + const Glib::ustring & REQUEST, + const Glib::RefPtr & ACTION__NAVIGATION_HISTORY_BACK, + const Glib::RefPtr & ACTION__NAVIGATION_HISTORY_FORWARD ); // Actions diff --git a/src/app/browser/main/tab/page/navigation/history.cpp b/src/app/browser/main/tab/page/navigation/history.cpp index aca2cb7e..5e37d3a4 100644 --- a/src/app/browser/main/tab/page/navigation/history.cpp +++ b/src/app/browser/main/tab/page/navigation/history.cpp @@ -4,19 +4,25 @@ using namespace app::browser::main::tab::page::navigation; -History::History() -{ +History::History( + const Glib::RefPtr & ACTION__HISTORY_BACK, + const Glib::RefPtr & ACTION__HISTORY_FORWARD +) { add_css_class( "linked" // merge children elements ); - historyBack = Gtk::make_managed(); + historyBack = Gtk::make_managed( + ACTION__HISTORY_BACK + ); append( * historyBack ); - historyForward = Gtk::make_managed(); + historyForward = Gtk::make_managed( + ACTION__HISTORY_FORWARD + ); append( * historyForward diff --git a/src/app/browser/main/tab/page/navigation/history.hpp b/src/app/browser/main/tab/page/navigation/history.hpp index c6c3f4c3..326dec30 100644 --- a/src/app/browser/main/tab/page/navigation/history.hpp +++ b/src/app/browser/main/tab/page/navigation/history.hpp @@ -2,7 +2,9 @@ #define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_HPP #include +#include #include +#include #include #include #include @@ -37,7 +39,10 @@ namespace app::browser::main::tab::page::navigation // Define navigation history storage std::vector memory; - History(); + History( + const Glib::RefPtr & ACTION__HISTORY_BACK, + const Glib::RefPtr & ACTION__HISTORY_FORWARD + ); // Actions void add( 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 d02f4130..640f46da 100644 --- a/src/app/browser/main/tab/page/navigation/history/back.cpp +++ b/src/app/browser/main/tab/page/navigation/history/back.cpp @@ -2,10 +2,11 @@ using namespace app::browser::main::tab::page::navigation::history; -Back::Back() -{ +Back::Back( + const Glib::RefPtr & ACTION__BACK +) { set_action_name( - "win.main_tab_page_navigation_history_back" + "win.main_tab_page_navigation_history_back" // @TODO ); set_icon_name( diff --git a/src/app/browser/main/tab/page/navigation/history/back.hpp b/src/app/browser/main/tab/page/navigation/history/back.hpp index 7519043b..ba8a0023 100644 --- a/src/app/browser/main/tab/page/navigation/history/back.hpp +++ b/src/app/browser/main/tab/page/navigation/history/back.hpp @@ -1,7 +1,9 @@ #ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK_HPP #define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK_HPP +#include #include +#include #include namespace app::browser::main::tab::page::navigation::history @@ -10,7 +12,9 @@ namespace app::browser::main::tab::page::navigation::history { public: - Back(); + Back( + const Glib::RefPtr & ACTION__BACK + ); void refresh( const bool & ENABLED 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 45c66f38..15ace1d8 100644 --- a/src/app/browser/main/tab/page/navigation/history/forward.cpp +++ b/src/app/browser/main/tab/page/navigation/history/forward.cpp @@ -2,10 +2,11 @@ using namespace app::browser::main::tab::page::navigation::history; -Forward::Forward() -{ +Forward::Forward( + const Glib::RefPtr & ACTION__FORWARD +) { set_action_name( - "win.main_tab_page_navigation_history_forward" + "win.main_tab_page_navigation_history_forward" // @TODO ); set_icon_name( diff --git a/src/app/browser/main/tab/page/navigation/history/forward.hpp b/src/app/browser/main/tab/page/navigation/history/forward.hpp index 80b3a338..8defdb4e 100644 --- a/src/app/browser/main/tab/page/navigation/history/forward.hpp +++ b/src/app/browser/main/tab/page/navigation/history/forward.hpp @@ -1,7 +1,9 @@ #ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD_HPP #define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD_HPP +#include #include +#include #include namespace app::browser::main::tab::page::navigation::history @@ -10,7 +12,9 @@ namespace app::browser::main::tab::page::navigation::history { public: - Forward(); + Forward( + const Glib::RefPtr & ACTION__FORWARD + ); void refresh( const bool & ENABLED