mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
switch to gtkmm
This commit is contained in:
parent
058aabce26
commit
d3e894e0ac
28 changed files with 50 additions and 1413 deletions
|
|
@ -1,44 +0,0 @@
|
|||
#include "menu.h"
|
||||
|
||||
namespace app::browser::header
|
||||
{
|
||||
// Construct
|
||||
Menu::Menu(
|
||||
Header *header
|
||||
) {
|
||||
// Init dependencies
|
||||
this->header = header;
|
||||
|
||||
// Init GTK
|
||||
this->gtk = gtk_menu_button_new();
|
||||
|
||||
gtk_widget_set_tooltip_text(
|
||||
GTK_WIDGET(
|
||||
this->gtk
|
||||
),
|
||||
Menu::TOOLTIP
|
||||
);
|
||||
|
||||
// Init requirements
|
||||
this->main = new menu::Main(
|
||||
this
|
||||
);
|
||||
|
||||
// Init main popover
|
||||
gtk_menu_button_set_popover(
|
||||
GTK_MENU_BUTTON(
|
||||
this->gtk
|
||||
),
|
||||
GTK_WIDGET(
|
||||
this->main->gtk
|
||||
)
|
||||
);
|
||||
|
||||
// Render
|
||||
gtk_widget_show(
|
||||
GTK_WIDGET(
|
||||
this->gtk
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef APP_BROWSER_HEADER_MENU_H
|
||||
#define APP_BROWSER_HEADER_MENU_H
|
||||
|
||||
// Dependencies
|
||||
#include "../header.h"
|
||||
|
||||
// Requirements
|
||||
#include "menu/main.h"
|
||||
|
||||
namespace app::browser
|
||||
{
|
||||
class Header;
|
||||
|
||||
namespace header
|
||||
{
|
||||
namespace menu
|
||||
{
|
||||
class Main;
|
||||
}
|
||||
|
||||
class Menu
|
||||
{
|
||||
public:
|
||||
|
||||
// GTK
|
||||
GtkWidget *gtk;
|
||||
|
||||
// Dependencies
|
||||
Header *header;
|
||||
|
||||
// Requirements
|
||||
menu::Main *main;
|
||||
|
||||
// Defaults
|
||||
const gchar *TOOLTIP = "Menu";
|
||||
|
||||
// Constructor
|
||||
Menu(
|
||||
Header *header
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
#include "main.h"
|
||||
|
||||
namespace app::browser::header::menu
|
||||
{
|
||||
// Construct
|
||||
Main::Main(
|
||||
Menu *menu
|
||||
) {
|
||||
// Init dependencies
|
||||
this->menu = menu;
|
||||
|
||||
// Init model
|
||||
this->model = g_menu_new();
|
||||
|
||||
// Init tab submenu
|
||||
this->tab = new main::Tab(
|
||||
this
|
||||
);
|
||||
|
||||
g_menu_append_submenu(
|
||||
G_MENU(
|
||||
this->model
|
||||
),
|
||||
this->tab->LABEL,
|
||||
G_MENU_MODEL(
|
||||
this->tab->model
|
||||
)
|
||||
);
|
||||
|
||||
// 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
|
||||
);
|
||||
|
||||
g_menu_append_item(
|
||||
G_MENU(
|
||||
this->model
|
||||
),
|
||||
G_MENU_ITEM(
|
||||
this->quit->item
|
||||
)
|
||||
);
|
||||
|
||||
// Create a new GtkPopoverMenu from the GMenuModel
|
||||
this->gtk = gtk_popover_menu_new_from_model(
|
||||
G_MENU_MODEL(
|
||||
this->model
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef APP_BROWSER_HEADER_MENU_MAIN_H
|
||||
#define APP_BROWSER_HEADER_MENU_MAIN_H
|
||||
|
||||
// Dependencies
|
||||
#include "../menu.h"
|
||||
|
||||
// Requirements
|
||||
#include "main/tab.h"
|
||||
#include "main/debug.h"
|
||||
#include "main/quit.h"
|
||||
|
||||
namespace app::browser::header
|
||||
{
|
||||
class Menu;
|
||||
|
||||
namespace menu
|
||||
{
|
||||
namespace main
|
||||
{
|
||||
class Tab;
|
||||
class Debug;
|
||||
class Quit;
|
||||
};
|
||||
|
||||
class Main
|
||||
{
|
||||
public:
|
||||
|
||||
// GTK
|
||||
GtkWidget *gtk;
|
||||
|
||||
// Gio
|
||||
GMenu* model;
|
||||
|
||||
// Dependencies
|
||||
Menu *menu;
|
||||
|
||||
// Requirements
|
||||
main::Tab *tab;
|
||||
main::Debug *debug;
|
||||
main::Quit *quit;
|
||||
|
||||
// Constructor
|
||||
Main(
|
||||
Menu *menu
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
#include "debug.h"
|
||||
|
||||
namespace app::browser::header::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->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->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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef APP_BROWSER_HEADER_MENU_MAIN_DEBUG_H
|
||||
#define APP_BROWSER_HEADER_MENU_MAIN_DEBUG_H
|
||||
|
||||
#include "../main.h"
|
||||
|
||||
namespace app::browser::header::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.menu.main.debug.activate";
|
||||
|
||||
// Construct
|
||||
Debug(
|
||||
Main *main
|
||||
);
|
||||
|
||||
private:
|
||||
|
||||
// Events
|
||||
static void _activate(
|
||||
GSimpleAction* action,
|
||||
GVariant* parameter,
|
||||
gpointer user_data
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
#include "quit.h"
|
||||
|
||||
namespace app::browser::header::menu::main
|
||||
{
|
||||
// Construct
|
||||
Quit::Quit(
|
||||
Main *main
|
||||
) {
|
||||
// Init dependencies
|
||||
this->main = main;
|
||||
|
||||
// Init action object
|
||||
this->action = g_simple_action_new(
|
||||
Quit::ACTION_ID,
|
||||
NULL
|
||||
);
|
||||
|
||||
g_action_map_add_action(
|
||||
G_ACTION_MAP(
|
||||
this->main->menu->header->browser->app
|
||||
),
|
||||
G_ACTION(
|
||||
this->action
|
||||
)
|
||||
);
|
||||
|
||||
// Init action NS
|
||||
gchar action[255];
|
||||
|
||||
g_snprintf(
|
||||
action,
|
||||
sizeof(
|
||||
action
|
||||
),
|
||||
Quit::ACTION_NS,
|
||||
Quit::ACTION_ID
|
||||
);
|
||||
|
||||
// Init keyboard accelerators
|
||||
// https://docs.gtk.org/gtk4/func.accelerator_parse.html
|
||||
const gchar *accels[] = {
|
||||
Quit::ACCEL_1, // First accelerator
|
||||
Quit::ACCEL_2, // Second accelerator
|
||||
NULL
|
||||
};
|
||||
|
||||
gtk_application_set_accels_for_action(
|
||||
GTK_APPLICATION(
|
||||
this->main->menu->header->browser->app
|
||||
),
|
||||
action,
|
||||
accels
|
||||
);
|
||||
|
||||
// Init menu item object
|
||||
this->item = g_menu_item_new(
|
||||
Quit::LABEL,
|
||||
action
|
||||
);
|
||||
|
||||
// Connect events
|
||||
g_signal_connect(
|
||||
G_SIMPLE_ACTION(
|
||||
this->action
|
||||
),
|
||||
"activate",
|
||||
G_CALLBACK(
|
||||
Quit::_activate
|
||||
),
|
||||
G_APPLICATION(
|
||||
this->main->menu->header->browser->app
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Events
|
||||
void Quit::_activate(
|
||||
GSimpleAction* action,
|
||||
GVariant* parameter,
|
||||
gpointer user_data
|
||||
) {
|
||||
g_application_quit(
|
||||
G_APPLICATION(
|
||||
user_data
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef APP_BROWSER_HEADER_MENU_MAIN_QUIT_H
|
||||
#define APP_BROWSER_HEADER_MENU_MAIN_QUIT_H
|
||||
|
||||
#include "../main.h"
|
||||
|
||||
namespace app::browser::header::menu
|
||||
{
|
||||
class Main;
|
||||
|
||||
namespace main
|
||||
{
|
||||
class Quit
|
||||
{
|
||||
public:
|
||||
|
||||
// GTK
|
||||
GMenuItem *item;
|
||||
|
||||
GSimpleAction *action;
|
||||
|
||||
// Dependencies
|
||||
Main *main;
|
||||
|
||||
// Defaults
|
||||
const gchar *LABEL = "Quit";
|
||||
|
||||
const gchar *ACCEL_1 = "<Control>q";
|
||||
const gchar *ACCEL_2 = "<Control>Q";
|
||||
|
||||
const gchar *ACTION_NS = "app.%s";
|
||||
const gchar *ACTION_ID = "browser.header.menu.main.quit.activate";
|
||||
|
||||
// Construct
|
||||
Quit(
|
||||
Main *main
|
||||
);
|
||||
|
||||
private:
|
||||
|
||||
// Events
|
||||
static void _activate(
|
||||
GSimpleAction* action,
|
||||
GVariant* parameter,
|
||||
gpointer user_data
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#include "tab.h"
|
||||
|
||||
namespace app::browser::header::menu::main
|
||||
{
|
||||
// Construct
|
||||
Tab::Tab(
|
||||
Main *main
|
||||
) {
|
||||
// Init dependencies
|
||||
this->main = 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(
|
||||
this->model
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#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:
|
||||
|
||||
// GTK
|
||||
GtkWidget *gtk;
|
||||
|
||||
// Gio
|
||||
GMenu* model;
|
||||
|
||||
GMenuItem *item;
|
||||
|
||||
// Dependencies
|
||||
Main *main;
|
||||
|
||||
// Requirements
|
||||
tab::Append *append;
|
||||
|
||||
// Defaults
|
||||
const gchar *LABEL = "Tab";
|
||||
|
||||
// Construct
|
||||
Tab(
|
||||
Main *main
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
#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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#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
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#include "tab.h"
|
||||
|
||||
namespace app::browser::header
|
||||
{
|
||||
// Construct
|
||||
Tab::Tab(
|
||||
Header *header
|
||||
) {
|
||||
// Init dependencies
|
||||
this->header = header;
|
||||
|
||||
// Init GTK
|
||||
this->gtk = gtk_button_new();
|
||||
|
||||
gtk_button_set_icon_name(
|
||||
GTK_BUTTON(
|
||||
this->gtk
|
||||
),
|
||||
Tab::ICON
|
||||
);
|
||||
|
||||
gtk_widget_set_tooltip_text(
|
||||
GTK_WIDGET(
|
||||
this->gtk
|
||||
),
|
||||
Tab::TOOLTIP
|
||||
);
|
||||
|
||||
// Render
|
||||
gtk_widget_show(
|
||||
GTK_WIDGET(
|
||||
this->gtk
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef APP_BROWSER_HEADER_TAB_H
|
||||
#define APP_BROWSER_HEADER_TAB_H
|
||||
|
||||
// Dependencies
|
||||
#include "../header.h"
|
||||
|
||||
namespace app::browser
|
||||
{
|
||||
class Header;
|
||||
|
||||
namespace header
|
||||
{
|
||||
class Tab
|
||||
{
|
||||
public:
|
||||
|
||||
// GTK
|
||||
GtkWidget *gtk;
|
||||
|
||||
// Dependencies
|
||||
Header *header;
|
||||
|
||||
// Defaults
|
||||
const gchar *ICON = "tab-new-symbolic";
|
||||
const gchar *TOOLTIP = "New tab";
|
||||
|
||||
// Constructor
|
||||
Tab(
|
||||
Header *header
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue