From 555478c783d29f6da4417d15459efa6e063618bc Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 25 Jan 2023 15:25:04 +0100 Subject: [PATCH] WIP: new actions --- include/ui.h | 58 ++++++++++++++++++++++++++++++++++++++++++++ src/ui/application.c | 51 ++++++-------------------------------- src/ui/gemgraph.ui | 3 +++ src/ui/window.c | 2 +- 4 files changed, 70 insertions(+), 44 deletions(-) diff --git a/include/ui.h b/include/ui.h index df974d7..28fe558 100644 --- a/include/ui.h +++ b/include/ui.h @@ -56,3 +56,61 @@ GemGraphClientApplication *gem_graph_client_application_new(const char *applicat GApplicationFlags flags); G_END_DECLS + + +// +// Actions +// +void on_about_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + +void on_quit_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + +void on_preferences_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + +void on_togglesidebar_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + +void on_editmode_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + +void on_runmode_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + +void on_presentmode_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + +void on_openfile_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + +void on_closefile_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + +void on_savefile_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + + +static const GActionEntry app_actions[] = { + { "quit", on_quit_action }, + { "about", on_about_action }, + { "preferences", on_preferences_action }, + { "togglesidebar", on_togglesidebar_action }, + { "editmode", on_editmode_action }, + { "runmode", on_runmode_action }, + { "presentmode", on_presentmode_action }, + { "openfile", on_openfile_action }, + { "closefile", on_closefile_action }, + { "savefile", on_savefile_action }, +}; diff --git a/src/ui/application.c b/src/ui/application.c index ef17f26..47d3f78 100644 --- a/src/ui/application.c +++ b/src/ui/application.c @@ -69,54 +69,19 @@ static void gem_graph_client_application_class_init( app_class->activate = gem_graph_client_application_activate; } -static void -gem_graph_client_application_about_action (GSimpleAction *action, - GVariant *parameter, - gpointer user_data) -{ - static const char *authors[] = { "Adrien Bourmault ", - "Jean Sirmai ", - NULL}; - GemGraphClientApplication *self = user_data; - GtkWindow *window = NULL; - - g_assert (GEM_GRAPH_CLIENT_IS_APPLICATION(self)); - - window = gtk_application_get_active_window(GTK_APPLICATION (self)); - - gtk_show_about_dialog(window, - "program-name", "Gem-graph", - "logo-icon-name", "application-x-executable", - "authors", authors, - "version", "0.1.0", - "copyright", "Copyright © 2022 Libre en Communs", - NULL); -} - -static void gem_graph_client_application_quit_action (GSimpleAction *action, - GVariant *parameter, - gpointer user_data) -{ - GemGraphClientApplication *self = user_data; - - g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self)); - - g_application_quit(G_APPLICATION(self)); -} - -static const GActionEntry app_actions[] = { - { "quit", gem_graph_client_application_quit_action }, - { "about", gem_graph_client_application_about_action }, -}; static void gem_graph_client_application_init(GemGraphClientApplication *self) { - g_action_map_add_action_entries(G_ACTION_MAP(self), + g_action_map_add_action_entries(G_ACTION_MAP(self), app_actions, G_N_ELEMENTS(app_actions), self); - gtk_application_set_accels_for_action(GTK_APPLICATION (self), - "app.quit", - (const char *[]) { "q", NULL }); + + gtk_application_set_accels_for_action(GTK_APPLICATION (self), + "app.quit", + (const char *[]) { "q", NULL }); + } + +// XXX changer tous les noms diff --git a/src/ui/gemgraph.ui b/src/ui/gemgraph.ui index 2aeba62..edfe3b9 100644 --- a/src/ui/gemgraph.ui +++ b/src/ui/gemgraph.ui @@ -9,6 +9,9 @@ 1080 application-x-executable GemGraph 0.1.0 + diff --git a/src/ui/window.c b/src/ui/window.c index aeca3b7..31082bc 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -247,5 +247,5 @@ static void gem_graph_client_window_class_init(GemGraphClientWindowClass *klass) static void gem_graph_client_window_init(GemGraphClientWindow *self) { - gtk_widget_init_template(GTK_WIDGET (self)); + gtk_widget_init_template(GTK_WIDGET(self)); }