mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
implement quit menu item
This commit is contained in:
parent
4e914857a2
commit
a9ae983549
3
Makefile
3
Makefile
@ -14,7 +14,8 @@ SRCS = src/main.cpp\
|
||||
src/app/browser/header/bar.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.cpp\
|
||||
src/app/browser/header/bar/menu/main/quit.cpp
|
||||
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
|
88
src/app/browser/header/bar/menu/main/quit.cpp
Normal file
88
src/app/browser/header/bar/menu/main/quit.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
#include "quit.h"
|
||||
|
||||
namespace app::browser::header::bar::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->bar->header->browser->application
|
||||
),
|
||||
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->bar->header->browser->application
|
||||
),
|
||||
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->bar->header->browser->application
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Events
|
||||
void Quit::_activate(
|
||||
GSimpleAction* action,
|
||||
GVariant* parameter,
|
||||
gpointer user_data
|
||||
) {
|
||||
g_application_quit(
|
||||
G_APPLICATION(
|
||||
user_data
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
50
src/app/browser/header/bar/menu/main/quit.h
Normal file
50
src/app/browser/header/bar/menu/main/quit.h
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef APP_BROWSER_HEADER_BAR_MENU_QUIT_H
|
||||
#define APP_BROWSER_HEADER_BAR_MENU_QUIT_H
|
||||
|
||||
#include "../main.h"
|
||||
|
||||
namespace app::browser::header::bar::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.bar.menu.main.quit.activate";
|
||||
|
||||
// Construct
|
||||
Quit(
|
||||
Main *main
|
||||
);
|
||||
|
||||
private:
|
||||
|
||||
// Events
|
||||
static void _activate(
|
||||
GSimpleAction* action,
|
||||
GVariant* parameter,
|
||||
gpointer user_data
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user