Browse Source

implement debug menu item

CPP-GTK4
yggverse 4 months ago
parent
commit
6b1c3b84ee
  1. 1
      Makefile
  2. 18
      src/app/browser/header/bar/menu/main.cpp
  3. 3
      src/app/browser/header/bar/menu/main.h
  4. 84
      src/app/browser/header/bar/menu/main/debug.cpp
  5. 50
      src/app/browser/header/bar/menu/main/debug.h

1
Makefile

@ -15,6 +15,7 @@ SRCS = src/main.cpp\
src/app/browser/header/bar/title.cpp\ src/app/browser/header/bar/title.cpp\
src/app/browser/header/bar/menu.cpp\ src/app/browser/header/bar/menu.cpp\
src/app/browser/header/bar/menu/main.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 src/app/browser/header/bar/menu/main/quit.cpp
OBJS = $(SRCS:.cpp=.o) OBJS = $(SRCS:.cpp=.o)

18
src/app/browser/header/bar/menu/main.cpp

@ -9,10 +9,24 @@ namespace app::browser::header::bar::menu
// Init dependencies // Init dependencies
this->menu = menu; this->menu = menu;
// Init GMenu Model // Init model
this->_model = g_menu_new(); 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->quit = new main::Quit(
this this
); );

3
src/app/browser/header/bar/menu/main.h

@ -5,6 +5,7 @@
#include "../menu.h" #include "../menu.h"
// Requirements // Requirements
#include "main/debug.h"
#include "main/quit.h" #include "main/quit.h"
namespace app::browser::header::bar namespace app::browser::header::bar
@ -15,6 +16,7 @@ namespace app::browser::header::bar
{ {
namespace main namespace main
{ {
class Debug;
class Quit; class Quit;
}; };
@ -33,6 +35,7 @@ namespace app::browser::header::bar
Menu *menu; Menu *menu;
// Requirements // Requirements
main::Debug *debug;
main::Quit *quit; main::Quit *quit;
// Constructor // Constructor

84
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
);
}
}

50
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 = "<Control><Shift>i";
const gchar *ACCEL_2 = "<Control><Shift>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
Loading…
Cancel
Save