diff --git a/Makefile b/Makefile index 2a919bad..cdf22534 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ SRCS = src/main.cpp\ src/app/browser/header/bar/title.cpp\ src/app/browser/header/bar/menu.cpp\ src/app/browser/header/bar/menu/main.cpp\ + src/app/browser/header/bar/menu/main/debug.cpp\ src/app/browser/header/bar/menu/main/quit.cpp OBJS = $(SRCS:.cpp=.o) diff --git a/src/app/browser/header/bar/menu/main.cpp b/src/app/browser/header/bar/menu/main.cpp index 610e4019..2eed90bb 100644 --- a/src/app/browser/header/bar/menu/main.cpp +++ b/src/app/browser/header/bar/menu/main.cpp @@ -9,10 +9,24 @@ namespace app::browser::header::bar::menu // Init dependencies this->menu = menu; - // Init GMenu Model + // Init model this->_model = g_menu_new(); - // Init menu items + // Init debug menu + this->debug = new main::Debug( + this + ); + + g_menu_append_item( + G_MENU( + this->_model + ), + G_MENU_ITEM( + this->debug->item + ) + ); + + // Init quit menu this->quit = new main::Quit( this ); diff --git a/src/app/browser/header/bar/menu/main.h b/src/app/browser/header/bar/menu/main.h index b91f5d22..fee7f56b 100644 --- a/src/app/browser/header/bar/menu/main.h +++ b/src/app/browser/header/bar/menu/main.h @@ -5,6 +5,7 @@ #include "../menu.h" // Requirements +#include "main/debug.h" #include "main/quit.h" namespace app::browser::header::bar @@ -15,6 +16,7 @@ namespace app::browser::header::bar { namespace main { + class Debug; class Quit; }; @@ -33,6 +35,7 @@ namespace app::browser::header::bar Menu *menu; // Requirements + main::Debug *debug; main::Quit *quit; // Constructor diff --git a/src/app/browser/header/bar/menu/main/debug.cpp b/src/app/browser/header/bar/menu/main/debug.cpp new file mode 100644 index 00000000..5e2084b6 --- /dev/null +++ b/src/app/browser/header/bar/menu/main/debug.cpp @@ -0,0 +1,84 @@ +#include "debug.h" + +namespace app::browser::header::bar::menu::main +{ + // Construct + Debug::Debug( + Main *main + ) { + // Init dependencies + this->main = main; + + // Init action object + this->action = g_simple_action_new( + Debug::ACTION_ID, + NULL + ); + + g_action_map_add_action( + G_ACTION_MAP( + this->main->menu->bar->header->browser->app + ), + G_ACTION( + this->action + ) + ); + + // Init action NS + gchar action[255]; + + g_snprintf( + action, + sizeof( + action + ), + Debug::ACTION_NS, + Debug::ACTION_ID + ); + + // Init keyboard accelerators + // https://docs.gtk.org/gtk4/func.accelerator_parse.html + const gchar *accels[] = { + Debug::ACCEL_1, // First accelerator + Debug::ACCEL_2, // Second accelerator + NULL + }; + + gtk_application_set_accels_for_action( + GTK_APPLICATION( + this->main->menu->bar->header->browser->app + ), + action, + accels + ); + + // Init menu item object + this->item = g_menu_item_new( + Debug::LABEL, + action + ); + + // Connect events + g_signal_connect( + G_SIMPLE_ACTION( + this->action + ), + "activate", + G_CALLBACK( + Debug::_activate + ), + NULL + ); + } + + // Events + void Debug::_activate( + GSimpleAction* action, + GVariant* parameter, + gpointer user_data + ) { + gtk_window_set_interactive_debugging( + true + ); + } +} diff --git a/src/app/browser/header/bar/menu/main/debug.h b/src/app/browser/header/bar/menu/main/debug.h new file mode 100644 index 00000000..bc96a63c --- /dev/null +++ b/src/app/browser/header/bar/menu/main/debug.h @@ -0,0 +1,50 @@ +#ifndef APP_BROWSER_HEADER_BAR_MENU_DEBUG_H +#define APP_BROWSER_HEADER_BAR_MENU_DEBUG_H + +#include "../main.h" + +namespace app::browser::header::bar::menu +{ + class Main; + + namespace main + { + class Debug + { + public: + + // GTK + GMenuItem *item; + + GSimpleAction *action; + + // Dependencies + Main *main; + + // Defaults + const gchar *LABEL = "Debug"; + + const gchar *ACCEL_1 = "i"; + const gchar *ACCEL_2 = "I"; + + const gchar *ACTION_NS = "app.%s"; + const gchar *ACTION_ID = "browser.header.bar.menu.main.debug.activate"; + + // Construct + Debug( + Main *main + ); + + private: + + // Events + static void _activate( + GSimpleAction* action, + GVariant* parameter, + gpointer user_data + ); + }; + }; +}; + +#endif \ No newline at end of file