Browse Source

draft action dependencies

CPP-GTK4
yggverse 4 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( @@ -9,7 +9,7 @@ Browser::Browser(
//const std::shared_ptr<lib::Database> & db
) {
// Init window actions
add_action(
const auto ACTION__REFRESH = add_action(
"refresh",
[this]
{
@ -45,14 +45,12 @@ Browser::Browser( @@ -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( @@ -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( @@ -134,7 +128,12 @@ Browser::Browser(
);
// 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(
* browserMain

4
src/app/browser.hpp

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
#ifndef APP_BROWSER_HPP
#define APP_BROWSER_HPP
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <gtkmm/applicationwindow.h>
#include <gtkmm/object.h>
@ -20,9 +22,11 @@ namespace app @@ -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;

15
src/app/browser/main.cpp

@ -3,8 +3,12 @@ @@ -3,8 +3,12 @@
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
set_orientation(
Gtk::Orientation::VERTICAL
@ -15,7 +19,12 @@ Main::Main() @@ -15,7 +19,12 @@ Main::Main()
);
// 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(
* mainTab

9
src/app/browser/main.hpp

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
#ifndef APP_BROWSER_MAIN_HPP
#define APP_BROWSER_MAIN_HPP
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/box.h>
#include <gtkmm/object.h>
@ -23,7 +25,12 @@ namespace app::browser @@ -23,7 +25,12 @@ namespace app::browser
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
void refresh();

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

@ -4,21 +4,29 @@ @@ -4,21 +4,29 @@
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
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( @@ -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( @@ -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(

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

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
#ifndef APP_BROWSER_MAIN_TAB_HPP
#define APP_BROWSER_MAIN_TAB_HPP
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/notebook.h>
@ -15,9 +17,13 @@ namespace app::browser::main @@ -15,9 +17,13 @@ namespace app::browser::main
class Tab : public Gtk::Notebook
{
const bool REORDERABLE = true;
const bool SCROLLABLE = true;
// Actions
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(
const int & PAGE_NUMBER
);
@ -26,9 +32,18 @@ namespace app::browser::main @@ -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<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
void refresh(

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

@ -3,11 +3,10 @@ @@ -3,11 +3,10 @@
using namespace app::browser::main::tab;
Label::Label(
const Glib::ustring & TEXT
const Glib::RefPtr<Gio::SimpleAction> & 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( @@ -22,9 +21,7 @@ Label::Label(
{
if (n == 2) // double click
{
activate_action(
"win.main_tab_close"
);
action__close->activate();
}
}
);

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

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
#ifndef APP_BROWSER_MAIN_TAB_LABEL_HPP
#define APP_BROWSER_MAIN_TAB_LABEL_HPP
#include <giomm/simpleaction.h>
#include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
@ -11,10 +12,12 @@ namespace app::browser::main::tab @@ -11,10 +12,12 @@ namespace app::browser::main::tab
{
class Label : public Gtk::Label
{
Glib::RefPtr<Gio::SimpleAction> action__close;
public:
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; @@ -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<Gio::SimpleAction> & ACTION__PAGE_NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__PAGE_NAVIGATION_HISTORY_FORWARD
) {
// Init container
set_orientation(
@ -16,7 +18,9 @@ Page::Page( @@ -16,7 +18,9 @@ Page::Page(
// Init components
pageNavigation = Gtk::make_managed<page::Navigation>(
REQUEST
REQUEST,
ACTION__PAGE_NAVIGATION_HISTORY_BACK,
ACTION__PAGE_NAVIGATION_HISTORY_FORWARD
);
append(

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

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

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

@ -8,7 +8,9 @@ @@ -8,7 +8,9 @@
using namespace app::browser::main::tab::page;
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
set_orientation(
@ -42,7 +44,10 @@ Navigation::Navigation( @@ -42,7 +44,10 @@ Navigation::Navigation(
* navigationBase
);
navigationHistory = Gtk::make_managed<navigation::History>();
navigationHistory = Gtk::make_managed<navigation::History>(
ACTION__NAVIGATION_HISTORY_BACK,
ACTION__NAVIGATION_HISTORY_FORWARD
);
append(
* navigationHistory

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

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_HPP
#include <giomm/simpleaction.h>
#include <giomm/simpleactiongroup.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/box.h>
#include <gtkmm/object.h>
@ -33,7 +35,9 @@ namespace app::browser::main::tab::page @@ -33,7 +35,9 @@ namespace app::browser::main::tab::page
public:
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

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

@ -4,19 +4,25 @@ @@ -4,19 +4,25 @@
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(
"linked" // merge children elements
);
historyBack = Gtk::make_managed<history::Back>();
historyBack = Gtk::make_managed<history::Back>(
ACTION__HISTORY_BACK
);
append(
* historyBack
);
historyForward = Gtk::make_managed<history::Forward>();
historyForward = Gtk::make_managed<history::Forward>(
ACTION__HISTORY_FORWARD
);
append(
* historyForward

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

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

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

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

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

@ -1,7 +1,9 @@ @@ -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 <giomm/simpleaction.h>
#include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <gtkmm/button.h>
namespace app::browser::main::tab::page::navigation::history
@ -10,7 +12,9 @@ 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<Gio::SimpleAction> & ACTION__BACK
);
void refresh(
const bool & ENABLED

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

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

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

@ -1,7 +1,9 @@ @@ -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 <giomm/simpleaction.h>
#include <glibmm/i18n.h>
#include <glibmm/refptr.h>
#include <gtkmm/button.h>
namespace app::browser::main::tab::page::navigation::history
@ -10,7 +12,9 @@ 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<Gio::SimpleAction> & ACTION__FORWARD
);
void refresh(
const bool & ENABLED

Loading…
Cancel
Save