From ee890b98594d2d132d5fb32c6cd0156387a7b933 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 11 Aug 2024 22:04:34 +0300 Subject: [PATCH] draft main tab features --- Makefile | 3 +- po/POTFILES.in | 6 ++-- src/app/browser.cpp | 34 +++++++++++++++++++++- src/app/browser.hpp | 13 +++++++++ src/app/browser/header/menu.cpp | 4 +-- src/app/browser/header/tab.hpp | 4 +-- src/app/browser/main.cpp | 28 ++++++++++++++++++ src/app/browser/main.hpp | 27 +++++++++++++++++ src/app/browser/main/tab.cpp | 22 ++++++++++++++ src/app/browser/{page.hpp => main/tab.hpp} | 18 ++++++------ src/app/browser/page.cpp | 10 ------- 11 files changed, 142 insertions(+), 27 deletions(-) create mode 100644 src/app/browser/main.cpp create mode 100644 src/app/browser/main.hpp create mode 100644 src/app/browser/main/tab.cpp rename src/app/browser/{page.hpp => main/tab.hpp} (61%) delete mode 100644 src/app/browser/page.cpp diff --git a/Makefile b/Makefile index 6085aea8..f7b62f4e 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ SRCS = src/main.cpp\ src/app/browser/header.cpp\ src/app/browser/header/menu.cpp\ src/app/browser/header/tab.cpp\ - src/app/browser/page.cpp\ + src/app/browser/main.cpp\ + src/app/browser/main/tab.cpp\ src/lib/database.cpp\ src/lib/database/session.cpp diff --git a/po/POTFILES.in b/po/POTFILES.in index e55efb63..463ffd71 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -6,8 +6,10 @@ src/app/browser/header/menu.cpp src/app/browser/header/menu.hpp src/app/browser/header/tab.cpp src/app/browser/header/tab.hpp -src/app/browser/page.cpp -src/app/browser/page.hpp +src/app/browser/main.cpp +src/app/browser/main.hpp +src/app/browser/main/tab.cpp +src/app/browser/main/tab.hpp src/lib/database.cpp src/lib/database.hpp src/lib/database/session.cpp diff --git a/src/app/browser.cpp b/src/app/browser.cpp index f064596a..853874a2 100644 --- a/src/app/browser.cpp +++ b/src/app/browser.cpp @@ -1,5 +1,6 @@ #include "browser.hpp" #include "browser/header.hpp" +#include "browser/main.hpp" using namespace app; @@ -7,6 +8,7 @@ Browser::Browser( const Glib::RefPtr & app, const lib::Database & db ) { + // Init window set_title( TITLE ); @@ -16,8 +18,27 @@ Browser::Browser( HEIGHT ); + // Init header widget + header = new browser::Header(); + set_titlebar( - * new browser::Header() + * header + ); + + // Init main widget + main = new browser::Main(); + + set_child( + * main + ); + + // Init actions + add_action( + "tab", + sigc::mem_fun( + * this, + & Browser::mainTabAppend + ) ); add_action( @@ -28,12 +49,23 @@ Browser::Browser( ) ); + // Init + app->set_accel_for_action( + "win.tab", + "t" + ); + app->set_accel_for_action( "win.debug", "i" ); } +void Browser::mainTabAppend() +{ + main->tabAppend(); +}; + void Browser::debug() { gtk_window_set_interactive_debugging( diff --git a/src/app/browser.hpp b/src/app/browser.hpp index a0ba2a66..51bc0ad1 100644 --- a/src/app/browser.hpp +++ b/src/app/browser.hpp @@ -11,8 +11,19 @@ namespace lib namespace app { + namespace browser + { + class Header; + class Main; + } + class Browser : public Gtk::ApplicationWindow { + private: + + app::browser::Header * header; + app::browser::Main * main; + public: const char * TITLE = _("Yoda"); @@ -24,6 +35,8 @@ namespace app const lib::Database & db ); + void mainTabAppend(); + void debug(); }; } diff --git a/src/app/browser/header/menu.cpp b/src/app/browser/header/menu.cpp index 35c0af0c..ab574f17 100644 --- a/src/app/browser/header/menu.cpp +++ b/src/app/browser/header/menu.cpp @@ -13,8 +13,8 @@ Menu::Menu() auto tab = Gio::Menu::create(); tab->append( - _("New tab"), - "tab.new" + _("New tab.."), + "win.tab" ); // Build tool submenu diff --git a/src/app/browser/header/tab.hpp b/src/app/browser/header/tab.hpp index 3ea3550d..e8456ed8 100644 --- a/src/app/browser/header/tab.hpp +++ b/src/app/browser/header/tab.hpp @@ -2,11 +2,11 @@ #define APP_BROWSER_HEADER_TAB_H #include -#include +#include namespace app::browser::header { - class Tab : public Gtk::MenuButton + class Tab : public Gtk::Button { public: diff --git a/src/app/browser/main.cpp b/src/app/browser/main.cpp new file mode 100644 index 00000000..6117b6b6 --- /dev/null +++ b/src/app/browser/main.cpp @@ -0,0 +1,28 @@ +#include "main.hpp" +#include "main/tab.hpp" + +using namespace app::browser; + +Main::Main() +{ + // Init container + set_homogeneous( + true + ); + + // Init tabs + tab = new main::Tab(); + + append( + * tab + ); +} + +void Main::tabAppend() +{ + tab->append( + nullptr, + true, + true + ); +}; \ No newline at end of file diff --git a/src/app/browser/main.hpp b/src/app/browser/main.hpp new file mode 100644 index 00000000..99f54b9a --- /dev/null +++ b/src/app/browser/main.hpp @@ -0,0 +1,27 @@ +#ifndef APP_BROWSER_MAIN_H +#define APP_BROWSER_MAIN_H + +#include + +namespace app::browser +{ + namespace main + { + class Tab; + } + + class Main : public Gtk::Box + { + private: + + app::browser::main::Tab * tab; + + public: + + Main(); + + void tabAppend(); + }; +} + +#endif // APP_BROWSER_MAIN_H \ No newline at end of file diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp new file mode 100644 index 00000000..faeaead0 --- /dev/null +++ b/src/app/browser/main/tab.cpp @@ -0,0 +1,22 @@ +#include "tab.hpp" +#include "gtkmm/label.h" + +using namespace app::browser::main; + +Tab::Tab() +{ + set_scrollable( + SCROLLABLE + ); +} + +void Tab::append( + const char * request, + bool open, + bool focus +) { + append_page( // @TODO + * new Gtk::Label("data"), + * new Gtk::Label("tab") + ); +}; \ No newline at end of file diff --git a/src/app/browser/page.hpp b/src/app/browser/main/tab.hpp similarity index 61% rename from src/app/browser/page.hpp rename to src/app/browser/main/tab.hpp index 3fa6e1d7..75563fae 100644 --- a/src/app/browser/page.hpp +++ b/src/app/browser/main/tab.hpp @@ -1,11 +1,11 @@ -#ifndef APP_BROWSER_PAGE_H -#define APP_BROWSER_PAGE_H +#ifndef APP_BROWSER_MAIN_TAB_H +#define APP_BROWSER_MAIN_TAB_H #include -namespace app::browser +namespace app::browser::main { - class Page : public Gtk::Notebook + class Tab : public Gtk::Notebook { public: @@ -26,16 +26,16 @@ namespace app::browser Body(); }; - Page(); + Tab(); void append( - char* request, - bool open = true, - bool focus = false + const char * request, + bool open, + bool focus ); void update(); }; } -#endif // APP_BROWSER_PAGE_H \ No newline at end of file +#endif // APP_BROWSER_MAIN_TAB_H \ No newline at end of file diff --git a/src/app/browser/page.cpp b/src/app/browser/page.cpp deleted file mode 100644 index e96a15da..00000000 --- a/src/app/browser/page.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "page.hpp" - -using namespace app::browser; - -Page::Page() -{ - set_scrollable( - SCROLLABLE - ); -} \ No newline at end of file