diff --git a/Makefile b/Makefile index b0b74614..59482c45 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ SRCS = src/main.cpp\ src/app/browser/header/menu.cpp\ src/app/browser/header/menu/main.cpp\ src/app/browser/header/menu/main/tab.cpp\ + src/app/browser/header/menu/main/tab/append.cpp\ src/app/browser/header/menu/main/debug.cpp\ src/app/browser/header/menu/main/quit.cpp diff --git a/src/app/browser/header/menu/main/tab.cpp b/src/app/browser/header/menu/main/tab.cpp index 27a27240..8febd4e5 100644 --- a/src/app/browser/header/menu/main/tab.cpp +++ b/src/app/browser/header/menu/main/tab.cpp @@ -12,6 +12,20 @@ namespace app::browser::header::menu::main // Init model this->model = g_menu_new(); + // Init new tab menu + this->append = new tab::Append( + this + ); + + g_menu_append_item( + G_MENU( + this->model + ), + G_MENU_ITEM( + this->append->item + ) + ); + // Init menu this->gtk = gtk_popover_menu_new_from_model( G_MENU_MODEL( diff --git a/src/app/browser/header/menu/main/tab.h b/src/app/browser/header/menu/main/tab.h index 278ea626..009fb1bf 100644 --- a/src/app/browser/header/menu/main/tab.h +++ b/src/app/browser/header/menu/main/tab.h @@ -1,14 +1,23 @@ #ifndef APP_BROWSER_HEADER_MENU_MAIN_TAB_H #define APP_BROWSER_HEADER_MENU_MAIN_TAB_H +// Dependencies #include "../main.h" +// Requirements +#include "tab/append.h" + namespace app::browser::header::menu { class Main; namespace main { + namespace tab + { + class Append; + } + class Tab { public: @@ -24,6 +33,9 @@ namespace app::browser::header::menu // Dependencies Main *main; + // Requirements + tab::Append *append; + // Defaults const gchar *LABEL = "Tab"; diff --git a/src/app/browser/header/menu/main/tab/append.cpp b/src/app/browser/header/menu/main/tab/append.cpp new file mode 100644 index 00000000..91fff684 --- /dev/null +++ b/src/app/browser/header/menu/main/tab/append.cpp @@ -0,0 +1,84 @@ +#include "append.h" + +namespace app::browser::header::menu::main::tab +{ + // Construct + Append::Append( + Tab *tab + ) { + // Init dependencies + this->tab = tab; + + // Init action object + this->action = g_simple_action_new( + Append::ACTION_ID, + NULL + ); + + g_action_map_add_action( + G_ACTION_MAP( + this->tab->main->menu->header->browser->app + ), + G_ACTION( + this->action + ) + ); + + // Init action NS + gchar action[255]; + + g_snprintf( + action, + sizeof( + action + ), + Append::ACTION_NS, + Append::ACTION_ID + ); + + // Init keyboard accelerators + // https://docs.gtk.org/gtk4/func.accelerator_parse.html + const gchar *accels[] = { + Append::ACCEL_1, // First accelerator + Append::ACCEL_2, // Second accelerator + NULL + }; + + gtk_application_set_accels_for_action( + GTK_APPLICATION( + this->tab->main->menu->header->browser->app + ), + action, + accels + ); + + // Init menu item object + this->item = g_menu_item_new( + Append::LABEL, + action + ); + + // Connect events + g_signal_connect( + G_SIMPLE_ACTION( + this->action + ), + "activate", + G_CALLBACK( + Append::_activate + ), + G_APPLICATION( + this->tab->main->menu->header->browser->app + ) + ); + } + + // Events + void Append::_activate( + GSimpleAction* action, + GVariant* parameter, + gpointer user_data + ) { + // @TODO + } +} diff --git a/src/app/browser/header/menu/main/tab/append.h b/src/app/browser/header/menu/main/tab/append.h new file mode 100644 index 00000000..ad63a790 --- /dev/null +++ b/src/app/browser/header/menu/main/tab/append.h @@ -0,0 +1,51 @@ +#ifndef APP_BROWSER_HEADER_MENU_MAIN_TAB_APPEND_H +#define APP_BROWSER_HEADER_MENU_MAIN_TAB_APPEND_H + +#include "../tab.h" + +namespace app::browser::header::menu::main +{ + class Tab; + + namespace tab + { + class Append + { + public: + + // GTK + GMenuItem *item; + + // Gio + GSimpleAction *action; + + // Dependencies + Tab *tab; + + // Defaults + const gchar *LABEL = "New tab"; + + const gchar *ACCEL_1 = "t"; + const gchar *ACCEL_2 = "T"; + + const gchar *ACTION_NS = "app.%s"; + const gchar *ACTION_ID = "browser.header.menu.main.tab.append.activate"; + + // Construct + Append( + Tab *tab + ); + + private: + + // Events + static void _activate( + GSimpleAction* action, + GVariant* parameter, + gpointer user_data + ); + }; + }; +}; + +#endif \ No newline at end of file