Browse Source

init new tab submenu

CPP-GTK4
yggverse 4 months ago
parent
commit
cde5eff9b8
  1. 1
      Makefile
  2. 14
      src/app/browser/header/menu/main/tab.cpp
  3. 12
      src/app/browser/header/menu/main/tab.h
  4. 84
      src/app/browser/header/menu/main/tab/append.cpp
  5. 51
      src/app/browser/header/menu/main/tab/append.h

1
Makefile

@ -15,6 +15,7 @@ SRCS = src/main.cpp\
src/app/browser/header/menu.cpp\ src/app/browser/header/menu.cpp\
src/app/browser/header/menu/main.cpp\ src/app/browser/header/menu/main.cpp\
src/app/browser/header/menu/main/tab.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/debug.cpp\
src/app/browser/header/menu/main/quit.cpp src/app/browser/header/menu/main/quit.cpp

14
src/app/browser/header/menu/main/tab.cpp

@ -12,6 +12,20 @@ namespace app::browser::header::menu::main
// Init model // Init model
this->model = g_menu_new(); 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 // Init menu
this->gtk = gtk_popover_menu_new_from_model( this->gtk = gtk_popover_menu_new_from_model(
G_MENU_MODEL( G_MENU_MODEL(

12
src/app/browser/header/menu/main/tab.h

@ -1,14 +1,23 @@
#ifndef APP_BROWSER_HEADER_MENU_MAIN_TAB_H #ifndef APP_BROWSER_HEADER_MENU_MAIN_TAB_H
#define APP_BROWSER_HEADER_MENU_MAIN_TAB_H #define APP_BROWSER_HEADER_MENU_MAIN_TAB_H
// Dependencies
#include "../main.h" #include "../main.h"
// Requirements
#include "tab/append.h"
namespace app::browser::header::menu namespace app::browser::header::menu
{ {
class Main; class Main;
namespace main namespace main
{ {
namespace tab
{
class Append;
}
class Tab class Tab
{ {
public: public:
@ -24,6 +33,9 @@ namespace app::browser::header::menu
// Dependencies // Dependencies
Main *main; Main *main;
// Requirements
tab::Append *append;
// Defaults // Defaults
const gchar *LABEL = "Tab"; const gchar *LABEL = "Tab";

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

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