From 6e6f9f0e99cbf24e371a233c83f13ea0eec9d0c0 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sun, 26 May 2024 09:30:02 +0200 Subject: [PATCH] =?UTF-8?q?WIP:=20I=20wish=20a=20functionnal=20upper=20lef?= =?UTF-8?q?t=20toggle=20[RUN/=C3=89DIT]=20button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/ui.h | 1 + src/ui/application.c | 1 + src/ui/events.c | 16 ++++++++++++++++ src/ui/gemgraph.ui | 18 ++++++++++++++---- src/ui/window.c | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/include/ui.h b/include/ui.h index d17fc0e..23a248a 100644 --- a/include/ui.h +++ b/include/ui.h @@ -167,6 +167,7 @@ void ui_set_stack(int mode); void ui_send_internal_notification(const char *message); void ui_close_internal_notification(void); void ui_toggle_sidebar(); +void ui_toggle_run_edit(int mode); // // Graphical stuff diff --git a/src/ui/application.c b/src/ui/application.c index 8745389..07a8f32 100644 --- a/src/ui/application.c +++ b/src/ui/application.c @@ -113,6 +113,7 @@ static void gem_graph_client_application_init(GemGraphClientApplication *self) ui_disable_action("runmode"); ui_disable_action("presentmode"); ui_disable_action("togglesidebar"); + ui_disable_action("toggle_run_edit"); } void ui_send_notification(const char *message) diff --git a/src/ui/events.c b/src/ui/events.c index 3f84ffa..3dd9f98 100644 --- a/src/ui/events.c +++ b/src/ui/events.c @@ -89,6 +89,19 @@ void on_togglesidebar_action(GSimpleAction *action, ui_toggle_sidebar(); } +void on_toggle_run_stop_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GemGraphClientApplication *self = user_data; + + g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self)); + + // Switch on the first letter of the mode, because switch is soooo simple :) + if (EDIT_MODE) ui_toggle_run_edit (RUN_MODE); + else if (RUN_MODE) ui_toggle_run_edit (EDIT_MODE); +} + void on_editmode_action(GSimpleAction *action, GVariant *parameter, gpointer user_data) @@ -166,6 +179,7 @@ void on_closefile_action(GSimpleAction *action, ui_disable_action("editmode"); ui_disable_action("presentmode"); ui_disable_action("togglesidebar"); + ui_disable_action("toggle_run_edit"); ui_set_stack(HOME_MODE); } @@ -362,6 +376,7 @@ void ui_model_loading(GObject *source_object, ui_enable_action("editmode"); ui_enable_action("presentmode"); ui_enable_action("togglesidebar"); + ui_enable_action("toggle_run_edit"); ui_set_stack(RUN_MODE); g_free(basenamestr); @@ -397,6 +412,7 @@ void ui_debug_model_loading (GtkWindow *self, const char *file) ui_enable_action("editmode"); ui_enable_action("presentmode"); ui_enable_action("togglesidebar"); + ui_enable_action("toggle_run_edit"); ui_set_stack(RUN_MODE); ui_toggle_sidebar(); } diff --git a/src/ui/gemgraph.ui b/src/ui/gemgraph.ui index 31fe3e1..f0785f8 100644 --- a/src/ui/gemgraph.ui +++ b/src/ui/gemgraph.ui @@ -19,6 +19,20 @@ main_menu + + + + + system-run-symbolic + Run mode + app.toggle_run_edit + + + + + + + True @@ -33,10 +47,6 @@ sidebar-show-symbolic Display/hide sidebar app.togglesidebar - - - - diff --git a/src/ui/window.c b/src/ui/window.c index 6192a30..ecda1c2 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -45,6 +45,7 @@ struct _GemGraphClientWindow GtkStack *side_stack; GtkPaned *main_paned; GtkMenuButton *main_button_mode; + GtkToggleButton *main_button_run_stop; GtkToggleButton *main_button_sidebar; GtkRevealer *toast_revealer; GtkToggleButton *toast_close_button; @@ -83,6 +84,7 @@ static void gem_graph_client_window_class_init(GemGraphClientWindowClass *klass) gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_stack); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, side_stack); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_paned); + gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_button_run_stop); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_button_mode); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_button_sidebar); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, toast_revealer); @@ -194,3 +196,33 @@ void ui_toggle_sidebar(void) gtk_paned_set_position(window->main_paned, 400); } } +void ui_toggle_run_edit(int mode) +{ + if (window->main_stack == NULL) { + g_printerr("Can't find self->main_stack !\n"); + return; + } + if (window->side_stack == NULL) { + g_printerr("Can't find self->side_stack !\n"); + return; + } + + // Switch on the first letter of the mode, because switch is soooo simple :) + switch(mode) { + case EDIT_MODE: + // gtk_stack_set_visible_child_full(window->main_stack, "edition", GTK_STACK_TRANSITION_TYPE_CROSSFADE); + gtk_stack_set_visible_child_full(window->side_stack, "edition", GTK_STACK_TRANSITION_TYPE_CROSSFADE); + gtk_menu_button_set_icon_name(window->main_button_run_stop, "document-edit-symbolic"); + ui_setup_glarea(EDIT_MODE, GTK_WIDGET(window->edition_glarea_box)); + break; + case RUN_MODE: + // gtk_stack_set_visible_child_full(window->main_stack, "run", GTK_STACK_TRANSITION_TYPE_CROSSFADE); + gtk_stack_set_visible_child_full(window->side_stack, "run", GTK_STACK_TRANSITION_TYPE_CROSSFADE); + gtk_menu_button_set_icon_name(window->main_button_run_stop, "system-run-symbolic"); + ui_setup_glarea(RUN_MODE, GTK_WIDGET(window->run_glarea_box)); + ui_create_tree (GTK_WIDGET (window->run_conditions_tree_box)); + break; + default: + break; + } +}