From a8df7e1ebeccb7e559a58b8538f32fe53b62069e Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 12 Aug 2024 09:45:22 +0300 Subject: [PATCH] implement destructors --- src/app/browser.cpp | 11 +++++++++++ src/app/browser.hpp | 2 ++ src/app/browser/header.cpp | 30 ++++++++++++++++++++++++++++-- src/app/browser/header.hpp | 13 +++++++++++++ src/app/browser/header/menu.cpp | 10 ++++++---- src/app/browser/header/menu.hpp | 8 ++++++++ src/app/browser/header/tab.cpp | 4 +++- src/app/browser/header/tab.hpp | 2 ++ src/app/browser/main.cpp | 11 +++++++++++ src/app/browser/main.hpp | 2 ++ src/app/browser/main/tab.cpp | 2 ++ src/app/browser/main/tab.hpp | 2 ++ 12 files changed, 90 insertions(+), 7 deletions(-) diff --git a/src/app/browser.cpp b/src/app/browser.cpp index 853874a2..d86ef398 100644 --- a/src/app/browser.cpp +++ b/src/app/browser.cpp @@ -61,6 +61,17 @@ Browser::Browser( ); } +Browser::~Browser() +{ + destroy(); + + delete header; + header = nullptr; + + delete main; + main = nullptr; +} + void Browser::mainTabAppend() { main->tabAppend(); diff --git a/src/app/browser.hpp b/src/app/browser.hpp index 51bc0ad1..3932f665 100644 --- a/src/app/browser.hpp +++ b/src/app/browser.hpp @@ -35,6 +35,8 @@ namespace app const lib::Database & db ); + ~Browser(); + void mainTabAppend(); void debug(); diff --git a/src/app/browser/header.cpp b/src/app/browser/header.cpp index e6e0e160..1fdd4bec 100644 --- a/src/app/browser/header.cpp +++ b/src/app/browser/header.cpp @@ -6,15 +6,41 @@ using namespace app::browser; Header::Header() { + // Init header bar set_show_title_buttons( SHOW_TITLE_BUTTONS ); + // Init menu + menu = new header::Menu(); + pack_start( - * new header::Menu() + * menu ); + // Init tab + tab = new header::Tab(); + pack_start( - * new header::Tab() + * tab + ); +} + +Header::~Header() +{ + // Menu + remove( + * menu ); + + delete menu; + menu = nullptr; + + // Tab + remove( + * tab + ); + + delete tab; + tab = nullptr; } \ No newline at end of file diff --git a/src/app/browser/header.hpp b/src/app/browser/header.hpp index 6e5f061b..9b5098a1 100644 --- a/src/app/browser/header.hpp +++ b/src/app/browser/header.hpp @@ -5,13 +5,26 @@ namespace app::browser { + namespace header + { + class Menu; + class Tab; + } + class Header : public Gtk::HeaderBar { + private: + + app::browser::header::Menu * menu; + app::browser::header::Tab * tab; + public: const bool SHOW_TITLE_BUTTONS = true; Header(); + + ~Header(); }; } diff --git a/src/app/browser/header/menu.cpp b/src/app/browser/header/menu.cpp index ab574f17..094f7172 100644 --- a/src/app/browser/header/menu.cpp +++ b/src/app/browser/header/menu.cpp @@ -10,7 +10,7 @@ Menu::Menu() ); // Build tab submenu - auto tab = Gio::Menu::create(); + tab = Gio::Menu::create(); tab->append( _("New tab.."), @@ -18,7 +18,7 @@ Menu::Menu() ); // Build tool submenu - auto tool = Gio::Menu::create(); + tool = Gio::Menu::create(); tool->append( _("Debug"), @@ -26,7 +26,7 @@ Menu::Menu() ); // Build main menu - auto main = Gio::Menu::create(); + main = Gio::Menu::create(); main->append_submenu( _("Tab"), @@ -46,4 +46,6 @@ Menu::Menu() set_menu_model( main ); -} \ No newline at end of file +} + +Menu::~Menu() = default; \ No newline at end of file diff --git a/src/app/browser/header/menu.hpp b/src/app/browser/header/menu.hpp index d27cde4f..ac3774ac 100644 --- a/src/app/browser/header/menu.hpp +++ b/src/app/browser/header/menu.hpp @@ -9,11 +9,19 @@ namespace app::browser::header { class Menu : public Gtk::MenuButton { + private: + + Glib::RefPtr tab, + tool, + main; + public: const char* TOOLTIP = _("Menu"); Menu(); + + ~Menu(); }; } diff --git a/src/app/browser/header/tab.cpp b/src/app/browser/header/tab.cpp index edd39932..6db62733 100644 --- a/src/app/browser/header/tab.cpp +++ b/src/app/browser/header/tab.cpp @@ -11,4 +11,6 @@ Tab::Tab() set_icon_name( ICON ); -} \ No newline at end of file +} + +Tab::~Tab() = default; \ No newline at end of file diff --git a/src/app/browser/header/tab.hpp b/src/app/browser/header/tab.hpp index e8456ed8..de26112e 100644 --- a/src/app/browser/header/tab.hpp +++ b/src/app/browser/header/tab.hpp @@ -14,6 +14,8 @@ namespace app::browser::header const char* TOOLTIP = _("New tab"); Tab(); + + ~Tab(); }; } diff --git a/src/app/browser/main.cpp b/src/app/browser/main.cpp index 6117b6b6..5a869f9f 100644 --- a/src/app/browser/main.cpp +++ b/src/app/browser/main.cpp @@ -18,6 +18,17 @@ Main::Main() ); } +Main::~Main() +{ + remove( + * tab + ); + + delete tab; + + tab = nullptr; +} + void Main::tabAppend() { tab->append( diff --git a/src/app/browser/main.hpp b/src/app/browser/main.hpp index 99f54b9a..451b0fda 100644 --- a/src/app/browser/main.hpp +++ b/src/app/browser/main.hpp @@ -20,6 +20,8 @@ namespace app::browser Main(); + ~Main(); + void tabAppend(); }; } diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index faeaead0..5dee1fa7 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -10,6 +10,8 @@ Tab::Tab() ); } +Tab::~Tab() = default; + void Tab::append( const char * request, bool open, diff --git a/src/app/browser/main/tab.hpp b/src/app/browser/main/tab.hpp index 75563fae..1c6f6194 100644 --- a/src/app/browser/main/tab.hpp +++ b/src/app/browser/main/tab.hpp @@ -28,6 +28,8 @@ namespace app::browser::main Tab(); + ~Tab(); + void append( const char * request, bool open,