1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:37:35 +00:00

LibGUI: Add GAction class and make GMenu deal in actions rather than strings.

This commit is contained in:
Andreas Kling 2019-02-12 14:09:48 +01:00
parent a5a7ea3d1e
commit 3085e400bc
9 changed files with 103 additions and 43 deletions

View file

@ -14,6 +14,7 @@
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GAction.h>
static void make_shell(int ptm_fd)
{
@ -95,38 +96,28 @@ int main(int argc, char** argv)
auto menubar = make<GMenuBar>();
auto app_menu = make<GMenu>("Terminal");
app_menu->add_item(0, "Quit");
app_menu->on_item_activation = [] (unsigned identifier) {
if (identifier == 0) {
dbgprintf("Terminal: Quit menu activated!\n");
GApplication::the().exit(0);
return;
}
};
app_menu->add_action(make<GAction>("Quit", String(), [] (const GAction&) {
dbgprintf("Terminal: Quit menu activated!\n");
GApplication::the().exit(0);
return;
}));
menubar->add_menu(move(app_menu));
auto font_menu = make<GMenu>("Font");
font_menu->add_item(0, "Liza Thin");
font_menu->add_item(1, "Liza Regular");
font_menu->add_item(2, "Liza Bold");
font_menu->on_item_activation = [&terminal] (unsigned identifier) {
switch (identifier) {
case 0:
terminal.set_font(Font::load_from_file("/res/fonts/LizaThin8x10.font"));
break;
case 1:
terminal.set_font(Font::load_from_file("/res/fonts/LizaRegular8x10.font"));
break;
case 2:
terminal.set_font(Font::load_from_file("/res/fonts/LizaBold8x10.font"));
break;
}
auto handle_font_selection = [&terminal] (const GAction& action) {
terminal.set_font(Font::load_from_file(action.custom_data()));
terminal.force_repaint();
};
font_menu->add_action(make<GAction>("Liza Thin", "/res/fonts/LizaThin8x10.font", move(handle_font_selection)));
font_menu->add_action(make<GAction>("Liza Regular", "/res/fonts/LizaRegular8x10.font", move(handle_font_selection)));
font_menu->add_action(make<GAction>("Liza Bold", "/res/fonts/LizaBold8x10.font", move(handle_font_selection)));
menubar->add_menu(move(font_menu));
auto help_menu = make<GMenu>("Help");
help_menu->add_item(0, "About");
help_menu->add_action(make<GAction>("About", [] (const GAction&) {
dbgprintf("FIXME: Implement Help/About\n");
}));
menubar->add_menu(move(help_menu));
app.set_menubar(move(menubar));