Browse Source

draft action dependencies

CPP-GTK4
yggverse 3 months ago
parent
commit
c940e5f7df
  1. 21
      src/app/browser.cpp
  2. 4
      src/app/browser.hpp
  3. 15
      src/app/browser/main.cpp
  4. 9
      src/app/browser/main.hpp
  5. 30
      src/app/browser/main/tab.cpp
  6. 21
      src/app/browser/main/tab.hpp
  7. 11
      src/app/browser/main/tab/label.cpp
  8. 5
      src/app/browser/main/tab/label.hpp
  9. 8
      src/app/browser/main/tab/page.cpp
  10. 5
      src/app/browser/main/tab/page.hpp
  11. 9
      src/app/browser/main/tab/page/navigation.cpp
  12. 6
      src/app/browser/main/tab/page/navigation.hpp
  13. 14
      src/app/browser/main/tab/page/navigation/history.cpp
  14. 7
      src/app/browser/main/tab/page/navigation/history.hpp
  15. 7
      src/app/browser/main/tab/page/navigation/history/back.cpp
  16. 6
      src/app/browser/main/tab/page/navigation/history/back.hpp
  17. 7
      src/app/browser/main/tab/page/navigation/history/forward.cpp
  18. 6
      src/app/browser/main/tab/page/navigation/history/forward.hpp

21
src/app/browser.cpp

@ -9,7 +9,7 @@ Browser::Browser(
//const std::shared_ptr<lib::Database> & db //const std::shared_ptr<lib::Database> & db
) { ) {
// Init window actions // Init window actions
add_action( const auto ACTION__REFRESH = add_action(
"refresh", "refresh",
[this] [this]
{ {
@ -45,14 +45,12 @@ Browser::Browser(
} }
); );
add_action( const auto ACTION__MAIN_TAB_CLOSE = add_action(
"main_tab_close", "main_tab_close",
[this] [this]
{ {
browserMain->tab_close(); browserMain->tab_close();
} }
)->set_enabled(
false
); );
add_action( add_action(
@ -96,24 +94,20 @@ Browser::Browser(
false false
); );
add_action( const auto ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK = add_action(
"main_tab_page_navigation_history_back", "main_tab_page_navigation_history_back",
[this] [this]
{ {
browserMain->tab_page_navigation_history_back(); 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", "main_tab_page_navigation_history_forward",
[this] [this]
{ {
browserMain->tab_page_navigation_history_forward(); browserMain->tab_page_navigation_history_forward();
} }
)->set_enabled(
false
); );
// Init widget // Init widget
@ -134,7 +128,12 @@ Browser::Browser(
); );
// Init main widget // Init main widget
browserMain = Gtk::make_managed<browser::Main>(); browserMain = Gtk::make_managed<browser::Main>(
ACTION__REFRESH,
ACTION__MAIN_TAB_CLOSE,
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD
);
set_child( set_child(
* browserMain * browserMain

4
src/app/browser.hpp

@ -1,7 +1,9 @@
#ifndef APP_BROWSER_HPP #ifndef APP_BROWSER_HPP
#define APP_BROWSER_HPP #define APP_BROWSER_HPP
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <gtkmm/applicationwindow.h> #include <gtkmm/applicationwindow.h>
#include <gtkmm/object.h> #include <gtkmm/object.h>
@ -20,9 +22,11 @@ namespace app
class Browser : public Gtk::ApplicationWindow class Browser : public Gtk::ApplicationWindow
{ {
// Components
app::browser::Header * browserHeader; app::browser::Header * browserHeader;
app::browser::Main * browserMain; app::browser::Main * browserMain;
// Defaults
const int WIDTH = 640; const int WIDTH = 640;
const int HEIGHT = 480; const int HEIGHT = 480;

15
src/app/browser/main.cpp

@ -3,8 +3,12 @@
using namespace app::browser; using namespace app::browser;
Main::Main() Main::Main(
{ const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD
) {
// Init container // Init container
set_orientation( set_orientation(
Gtk::Orientation::VERTICAL Gtk::Orientation::VERTICAL
@ -15,7 +19,12 @@ Main::Main()
); );
// Init tabs // Init tabs
mainTab = Gtk::make_managed<main::Tab>(); mainTab = Gtk::make_managed<main::Tab>(
ACTION__REFRESH,
ACTION__MAIN_TAB_CLOSE,
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD
);
append( append(
* mainTab * mainTab

9
src/app/browser/main.hpp

@ -1,7 +1,9 @@
#ifndef APP_BROWSER_MAIN_HPP #ifndef APP_BROWSER_MAIN_HPP
#define APP_BROWSER_MAIN_HPP #define APP_BROWSER_MAIN_HPP
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <gtkmm/object.h> #include <gtkmm/object.h>
@ -23,7 +25,12 @@ namespace app::browser
public: public:
Main(); Main(
const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_CLOSE,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD
);
// Actions // Actions
void refresh(); void refresh();

30
src/app/browser/main/tab.cpp

@ -4,21 +4,29 @@
using namespace app::browser::main; using namespace app::browser::main;
Tab::Tab() Tab::Tab(
{ const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_CLOSE,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & 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 // Init widget
set_scrollable( set_scrollable(
SCROLLABLE SCROLLABLE
); );
// Init events // Init event listeners
signal_switch_page().connect( signal_switch_page().connect(
[this](Gtk::Widget*, guint) [this](Gtk::Widget*, guint)
{ {
// Refresh window elements, e.g. tab label to header bar // Refresh window elements, e.g. tab label to header bar
activate_action( action__refresh->activate();
"win.refresh"
);
} }
); );
} }
@ -31,7 +39,9 @@ void Tab::refresh(
PAGE_NUMBER PAGE_NUMBER
); );
get_tabLabel(PAGE_NUMBER)->set_label( get_tabLabel(
PAGE_NUMBER
)->set_label(
tabPage->get_title() tabPage->get_title()
); );
} }
@ -45,11 +55,13 @@ void Tab::append(
auto tabPage = new tab::Page( auto tabPage = new tab::Page(
TITLE, TITLE,
SUBTITLE, SUBTITLE,
REQUEST REQUEST,
action__tab_page_navigation_history_back,
action__tab_page_navigation_history_forward
); );
auto tabLabel = new tab::Label( auto tabLabel = new tab::Label(
TITLE action__tab_close
); );
int page_number = append_page( int page_number = append_page(

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

@ -1,7 +1,9 @@
#ifndef APP_BROWSER_MAIN_TAB_HPP #ifndef APP_BROWSER_MAIN_TAB_HPP
#define APP_BROWSER_MAIN_TAB_HPP #define APP_BROWSER_MAIN_TAB_HPP
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <gtkmm/notebook.h> #include <gtkmm/notebook.h>
@ -15,9 +17,13 @@ namespace app::browser::main
class Tab : public Gtk::Notebook class Tab : public Gtk::Notebook
{ {
const bool REORDERABLE = true; // Actions
const bool SCROLLABLE = true; Glib::RefPtr<Gio::SimpleAction> action__refresh,
action__tab_close,
action__tab_page_navigation_history_back,
action__tab_page_navigation_history_forward;
// Components
tab::Label * get_tabLabel( tab::Label * get_tabLabel(
const int & PAGE_NUMBER const int & PAGE_NUMBER
); );
@ -26,9 +32,18 @@ namespace app::browser::main
const int & PAGE_NUMBER const int & PAGE_NUMBER
); );
// Defaults
const bool REORDERABLE = true;
const bool SCROLLABLE = true;
public: public:
Tab(); Tab(
const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_CLOSE,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_PAGE_NAVIGATION_HISTORY_FORWARD
);
// Actions // Actions
void refresh( void refresh(

11
src/app/browser/main/tab/label.cpp

@ -3,11 +3,10 @@
using namespace app::browser::main::tab; using namespace app::browser::main::tab;
Label::Label( Label::Label(
const Glib::ustring & TEXT const Glib::RefPtr<Gio::SimpleAction> & ACTION__CLOSE
) { ) {
set_text( // Init actions
TEXT action__close = ACTION__CLOSE;
);
// Setup label controller // Setup label controller
auto GtkGestureClick = Gtk::GestureClick::create(); auto GtkGestureClick = Gtk::GestureClick::create();
@ -22,9 +21,7 @@ Label::Label(
{ {
if (n == 2) // double click if (n == 2) // double click
{ {
activate_action( action__close->activate();
"win.main_tab_close"
);
} }
} }
); );

5
src/app/browser/main/tab/label.hpp

@ -1,6 +1,7 @@
#ifndef APP_BROWSER_MAIN_TAB_LABEL_HPP #ifndef APP_BROWSER_MAIN_TAB_LABEL_HPP
#define APP_BROWSER_MAIN_TAB_LABEL_HPP #define APP_BROWSER_MAIN_TAB_LABEL_HPP
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
#include <glibmm/refptr.h> #include <glibmm/refptr.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
@ -11,10 +12,12 @@ namespace app::browser::main::tab
{ {
class Label : public Gtk::Label class Label : public Gtk::Label
{ {
Glib::RefPtr<Gio::SimpleAction> action__close;
public: public:
Label( Label(
const Glib::ustring & TEXT const Glib::RefPtr<Gio::SimpleAction> & ACTION__CLOSE
); );
}; };
} }

8
src/app/browser/main/tab/page.cpp

@ -7,7 +7,9 @@ using namespace app::browser::main::tab;
Page::Page( Page::Page(
const Glib::ustring & TITLE, const Glib::ustring & TITLE,
const Glib::ustring & SUBTITLE, const Glib::ustring & SUBTITLE,
const Glib::ustring & REQUEST const Glib::ustring & REQUEST,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__PAGE_NAVIGATION_HISTORY_FORWARD
) { ) {
// Init container // Init container
set_orientation( set_orientation(
@ -16,7 +18,9 @@ Page::Page(
// Init components // Init components
pageNavigation = Gtk::make_managed<page::Navigation>( pageNavigation = Gtk::make_managed<page::Navigation>(
REQUEST REQUEST,
ACTION__PAGE_NAVIGATION_HISTORY_BACK,
ACTION__PAGE_NAVIGATION_HISTORY_FORWARD
); );
append( append(

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

@ -4,6 +4,7 @@
#include <giomm/asyncresult.h> #include <giomm/asyncresult.h>
#include <giomm/inputstream.h> #include <giomm/inputstream.h>
#include <giomm/outputstream.h> #include <giomm/outputstream.h>
#include <giomm/simpleaction.h>
#include <giomm/socketclient.h> #include <giomm/socketclient.h>
#include <giomm/socketconnection.h> #include <giomm/socketconnection.h>
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
@ -43,7 +44,9 @@ namespace app::browser::main::tab
Page( Page(
const Glib::ustring & TITLE, const Glib::ustring & TITLE,
const Glib::ustring & SUBTITLE, const Glib::ustring & SUBTITLE,
const Glib::ustring & REQUEST const Glib::ustring & REQUEST,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__PAGE_NAVIGATION_HISTORY_FORWARD
); );
// Actions // Actions

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

@ -8,7 +8,9 @@
using namespace app::browser::main::tab::page; using namespace app::browser::main::tab::page;
Navigation::Navigation( Navigation::Navigation(
const Glib::ustring & REQUEST const Glib::ustring & REQUEST,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_FORWARD
) { ) {
// Init container // Init container
set_orientation( set_orientation(
@ -42,7 +44,10 @@ Navigation::Navigation(
* navigationBase * navigationBase
); );
navigationHistory = Gtk::make_managed<navigation::History>(); navigationHistory = Gtk::make_managed<navigation::History>(
ACTION__NAVIGATION_HISTORY_BACK,
ACTION__NAVIGATION_HISTORY_FORWARD
);
append( append(
* navigationHistory * navigationHistory

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

@ -1,7 +1,9 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HPP #ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HPP #define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HPP
#include <giomm/simpleaction.h>
#include <giomm/simpleactiongroup.h> #include <giomm/simpleactiongroup.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <gtkmm/object.h> #include <gtkmm/object.h>
@ -33,7 +35,9 @@ namespace app::browser::main::tab::page
public: public:
Navigation( Navigation(
const Glib::ustring & REQUEST const Glib::ustring & REQUEST,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_FORWARD
); );
// Actions // Actions

14
src/app/browser/main/tab/page/navigation/history.cpp

@ -4,19 +4,25 @@
using namespace app::browser::main::tab::page::navigation; using namespace app::browser::main::tab::page::navigation;
History::History() History::History(
{ const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_FORWARD
) {
add_css_class( add_css_class(
"linked" // merge children elements "linked" // merge children elements
); );
historyBack = Gtk::make_managed<history::Back>(); historyBack = Gtk::make_managed<history::Back>(
ACTION__HISTORY_BACK
);
append( append(
* historyBack * historyBack
); );
historyForward = Gtk::make_managed<history::Forward>(); historyForward = Gtk::make_managed<history::Forward>(
ACTION__HISTORY_FORWARD
);
append( append(
* historyForward * historyForward

7
src/app/browser/main/tab/page/navigation/history.hpp

@ -2,7 +2,9 @@
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_HPP #define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_HPP
#include <ctime> #include <ctime>
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <gtkmm/object.h> #include <gtkmm/object.h>
@ -37,7 +39,10 @@ namespace app::browser::main::tab::page::navigation
// Define navigation history storage // Define navigation history storage
std::vector<Memory> memory; std::vector<Memory> memory;
History(); History(
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_FORWARD
);
// Actions // Actions
void add( void add(

7
src/app/browser/main/tab/page/navigation/history/back.cpp

@ -2,10 +2,11 @@
using namespace app::browser::main::tab::page::navigation::history; using namespace app::browser::main::tab::page::navigation::history;
Back::Back() Back::Back(
{ const Glib::RefPtr<Gio::SimpleAction> & ACTION__BACK
) {
set_action_name( set_action_name(
"win.main_tab_page_navigation_history_back" "win.main_tab_page_navigation_history_back" // @TODO
); );
set_icon_name( set_icon_name(

6
src/app/browser/main/tab/page/navigation/history/back.hpp

@ -1,7 +1,9 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK_HPP #ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK_HPP #define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK_HPP
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <gtkmm/button.h> #include <gtkmm/button.h>
namespace app::browser::main::tab::page::navigation::history namespace app::browser::main::tab::page::navigation::history
@ -10,7 +12,9 @@ namespace app::browser::main::tab::page::navigation::history
{ {
public: public:
Back(); Back(
const Glib::RefPtr<Gio::SimpleAction> & ACTION__BACK
);
void refresh( void refresh(
const bool & ENABLED const bool & ENABLED

7
src/app/browser/main/tab/page/navigation/history/forward.cpp

@ -2,10 +2,11 @@
using namespace app::browser::main::tab::page::navigation::history; using namespace app::browser::main::tab::page::navigation::history;
Forward::Forward() Forward::Forward(
{ const Glib::RefPtr<Gio::SimpleAction> & ACTION__FORWARD
) {
set_action_name( set_action_name(
"win.main_tab_page_navigation_history_forward" "win.main_tab_page_navigation_history_forward" // @TODO
); );
set_icon_name( set_icon_name(

6
src/app/browser/main/tab/page/navigation/history/forward.hpp

@ -1,7 +1,9 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD_HPP #ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD_HPP #define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD_HPP
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <gtkmm/button.h> #include <gtkmm/button.h>
namespace app::browser::main::tab::page::navigation::history namespace app::browser::main::tab::page::navigation::history
@ -10,7 +12,9 @@ namespace app::browser::main::tab::page::navigation::history
{ {
public: public:
Forward(); Forward(
const Glib::RefPtr<Gio::SimpleAction> & ACTION__FORWARD
);
void refresh( void refresh(
const bool & ENABLED const bool & ENABLED

Loading…
Cancel
Save