From 0f96ff851ec59c7d586b6b1846be925fc9954934 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 10 Aug 2024 17:57:15 +0300 Subject: [PATCH] use separated class files, use hpp header extension, update include model --- Makefile | 7 ++- po/POTFILES.in | 12 +++- src/app/browser.cpp | 45 +-------------- src/app/browser.h | 98 --------------------------------- src/app/browser.hpp | 21 +++++++ src/app/browser/header.cpp | 20 +++++++ src/app/browser/header.hpp | 18 ++++++ src/app/browser/header/menu.cpp | 48 ++++++++++++++++ src/app/browser/header/menu.hpp | 21 +++++++ src/app/browser/header/tab.cpp | 14 +++++ src/app/browser/header/tab.hpp | 20 +++++++ src/app/browser/page.cpp | 10 ++++ src/app/browser/page.hpp | 41 ++++++++++++++ src/main.cpp | 3 +- src/{main.h => main.hpp} | 2 +- 15 files changed, 235 insertions(+), 145 deletions(-) delete mode 100644 src/app/browser.h create mode 100644 src/app/browser.hpp create mode 100644 src/app/browser/header.cpp create mode 100644 src/app/browser/header.hpp create mode 100644 src/app/browser/header/menu.cpp create mode 100644 src/app/browser/header/menu.hpp create mode 100644 src/app/browser/header/tab.cpp create mode 100644 src/app/browser/header/tab.hpp create mode 100644 src/app/browser/page.cpp create mode 100644 src/app/browser/page.hpp rename src/{main.h => main.hpp} (79%) diff --git a/Makefile b/Makefile index 4c62f03..53049a7 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,12 @@ LDFLAGS = `pkg-config --libs gtkmm-4.0 glibmm-2.68` # Define target executable and source files TARGET = bin/Yoda -SRCS = src/main.cpp $(wildcard src/app/*.cpp) +SRCS = src/main.cpp\ + src/app/browser.cpp\ + src/app/browser/header.cpp\ + src/app/browser/header/menu.cpp\ + src/app/browser/header/tab.cpp\ + src/app/browser/page.cpp OBJS = $(SRCS:.cpp=.o) diff --git a/po/POTFILES.in b/po/POTFILES.in index 3fbea41..1f3feba 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,4 +1,12 @@ src/app/browser.cpp -src/app/browser.h +src/app/browser.hpp +src/app/browser/header.cpp +src/app/browser/header.hpp +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/main.cpp -src/main.h \ No newline at end of file +src/main.hpp \ No newline at end of file diff --git a/src/app/browser.cpp b/src/app/browser.cpp index bcaac5b..f53d67f 100644 --- a/src/app/browser.cpp +++ b/src/app/browser.cpp @@ -1,4 +1,5 @@ -#include "browser.h" +#include "browser.hpp" +#include "browser/header.hpp" using namespace app; @@ -14,46 +15,6 @@ Browser::Browser() ); set_titlebar( - * new Header() - ); -} - -Browser::Header::Header() -{ - set_show_title_buttons( - SHOW_TITLE_BUTTONS - ); - - pack_start( - * new Menu() - ); - - pack_start( - * new Tab() - ); -} - -Browser::Header::Menu::Menu() -{ - set_tooltip_text( - TOOLTIP - ); -} - -Browser::Header::Tab::Tab() -{ - set_tooltip_text( - TOOLTIP - ); - - set_icon_name( - ICON - ); -} - -Browser::Container::Container() -{ - set_scrollable( - SCROLLABLE + * new browser::Header() ); } \ No newline at end of file diff --git a/src/app/browser.h b/src/app/browser.h deleted file mode 100644 index 6bb136d..0000000 --- a/src/app/browser.h +++ /dev/null @@ -1,98 +0,0 @@ -#ifndef APP_BROWSER_H -#define APP_BROWSER_H - -#include - -#include -#include -#include -#include -#include - -namespace app -{ - class Browser : public Gtk::ApplicationWindow - { - public: - - const char* TITLE = _("Yoda"); - const int WIDTH = 640; - const int HEIGHT = 480; - - Browser(); - - class Header : public Gtk::HeaderBar - { - public: - - const bool SHOW_TITLE_BUTTONS = true; - - Header(); - - class Menu : public Gtk::MenuButton - { - public: - - const char* TOOLTIP = _("Menu"); - - Menu(); - }; - - class Tab : public Gtk::MenuButton - { - public: - - const char* ICON = "tab-new-symbolic"; - const char* TOOLTIP = _("New tab"); - - Tab(); - }; - }; - - class Container : public Gtk::Notebook - { - public: - - class Page - { - public: - - class Navbar - { - public: - - Navbar(); - }; - - class Body - { - public: - - Body(); - }; - - Page(); - - private: - - Navbar _navbar; - Body _body; - }; - - const bool SCROLLABLE = true; - const bool REORDERABLE = true; - - Container(); - - Page append( - char* request, - bool open = true, - bool focus = false - ); - - void update(); - }; - }; -} - -#endif // APP_BROWSER_H \ No newline at end of file diff --git a/src/app/browser.hpp b/src/app/browser.hpp new file mode 100644 index 0000000..755a027 --- /dev/null +++ b/src/app/browser.hpp @@ -0,0 +1,21 @@ +#ifndef APP_BROWSER_H +#define APP_BROWSER_H + +#include +#include + +namespace app +{ + class Browser : public Gtk::ApplicationWindow + { + public: + + const char * TITLE = _("Yoda"); + const int WIDTH = 640; + const int HEIGHT = 480; + + Browser(); + }; +} + +#endif // APP_BROWSER_H \ No newline at end of file diff --git a/src/app/browser/header.cpp b/src/app/browser/header.cpp new file mode 100644 index 0000000..e6e0e16 --- /dev/null +++ b/src/app/browser/header.cpp @@ -0,0 +1,20 @@ +#include "header.hpp" +#include "header/menu.hpp" +#include "header/tab.hpp" + +using namespace app::browser; + +Header::Header() +{ + set_show_title_buttons( + SHOW_TITLE_BUTTONS + ); + + pack_start( + * new header::Menu() + ); + + pack_start( + * new header::Tab() + ); +} \ No newline at end of file diff --git a/src/app/browser/header.hpp b/src/app/browser/header.hpp new file mode 100644 index 0000000..6e5f061 --- /dev/null +++ b/src/app/browser/header.hpp @@ -0,0 +1,18 @@ +#ifndef APP_BROWSER_HEADER_H +#define APP_BROWSER_HEADER_H + +#include + +namespace app::browser +{ + class Header : public Gtk::HeaderBar + { + public: + + const bool SHOW_TITLE_BUTTONS = true; + + Header(); + }; +} + +#endif // APP_BROWSER_HEADER_H \ No newline at end of file diff --git a/src/app/browser/header/menu.cpp b/src/app/browser/header/menu.cpp new file mode 100644 index 0000000..4ce142d --- /dev/null +++ b/src/app/browser/header/menu.cpp @@ -0,0 +1,48 @@ +#include "menu.hpp" + +using namespace app::browser::header; + +Menu::Menu() +{ + set_tooltip_text( + TOOLTIP + ); + + // Build tab submenu + auto tab = Gio::Menu::create(); + + tab->append( + _("New tab"), + "app.tab.new" + ); + + // Build tool submenu + auto tool = Gio::Menu::create(); + + tool->append( + _("Debug"), + "app.tool.debug" + ); + + // Build main menu + auto main = Gio::Menu::create(); + + main->append_submenu( + _("Tab"), + tab + ); + + main->append_submenu( + _("Tool"), + tool + ); + + main->append( + _("Quit"), + "win.quit" + ); + + set_menu_model( + main + ); +} \ No newline at end of file diff --git a/src/app/browser/header/menu.hpp b/src/app/browser/header/menu.hpp new file mode 100644 index 0000000..b4c9fc1 --- /dev/null +++ b/src/app/browser/header/menu.hpp @@ -0,0 +1,21 @@ +#ifndef APP_BROWSER_HEADER_MENU_H +#define APP_BROWSER_HEADER_MENU_H + +#include + +#include +#include + +namespace app::browser::header +{ + class Menu : public Gtk::MenuButton + { + public: + + const char* TOOLTIP = _("Menu"); + + Menu(); + }; +} + +#endif // APP_BROWSER_HEADER_MENU_H \ No newline at end of file diff --git a/src/app/browser/header/tab.cpp b/src/app/browser/header/tab.cpp new file mode 100644 index 0000000..edd3993 --- /dev/null +++ b/src/app/browser/header/tab.cpp @@ -0,0 +1,14 @@ +#include "tab.hpp" + +using namespace app::browser::header; + +Tab::Tab() +{ + set_tooltip_text( + TOOLTIP + ); + + set_icon_name( + ICON + ); +} \ No newline at end of file diff --git a/src/app/browser/header/tab.hpp b/src/app/browser/header/tab.hpp new file mode 100644 index 0000000..3ea3550 --- /dev/null +++ b/src/app/browser/header/tab.hpp @@ -0,0 +1,20 @@ +#ifndef APP_BROWSER_HEADER_TAB_H +#define APP_BROWSER_HEADER_TAB_H + +#include +#include + +namespace app::browser::header +{ + class Tab : public Gtk::MenuButton + { + public: + + const char* ICON = "tab-new-symbolic"; + const char* TOOLTIP = _("New tab"); + + Tab(); + }; +} + +#endif // APP_BROWSER_HEADER_TAB_H \ No newline at end of file diff --git a/src/app/browser/page.cpp b/src/app/browser/page.cpp new file mode 100644 index 0000000..e96a15d --- /dev/null +++ b/src/app/browser/page.cpp @@ -0,0 +1,10 @@ +#include "page.hpp" + +using namespace app::browser; + +Page::Page() +{ + set_scrollable( + SCROLLABLE + ); +} \ No newline at end of file diff --git a/src/app/browser/page.hpp b/src/app/browser/page.hpp new file mode 100644 index 0000000..3fa6e1d --- /dev/null +++ b/src/app/browser/page.hpp @@ -0,0 +1,41 @@ +#ifndef APP_BROWSER_PAGE_H +#define APP_BROWSER_PAGE_H + +#include + +namespace app::browser +{ + class Page : public Gtk::Notebook + { + public: + + const bool SCROLLABLE = true; + const bool REORDERABLE = true; + + class Navbar + { + public: + + Navbar(); + }; + + class Body + { + public: + + Body(); + }; + + Page(); + + void append( + char* request, + bool open = true, + bool focus = false + ); + + void update(); + }; +} + +#endif // APP_BROWSER_PAGE_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0650b75..ea53d41 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ -#include "main.h" +#include "main.hpp" +#include "app/browser.hpp" int main( int argc, diff --git a/src/main.h b/src/main.hpp similarity index 79% rename from src/main.h rename to src/main.hpp index 81c0111..3f75d90 100644 --- a/src/main.h +++ b/src/main.hpp @@ -1,4 +1,4 @@ -#include "app/browser.h" +#include const Glib::ustring APPLICATION_ID = "io.github.yggverse.Yoda";