diff --git a/include/ui.h b/include/ui.h index 23a248a..a4dfd27 100644 --- a/include/ui.h +++ b/include/ui.h @@ -76,12 +76,18 @@ void ui_enable_action(const char *name); void ui_disable_action(const char *name); +void set_run_edit_mode(int prescribed_mode); +int get_run_edit_mode(); + + // // Actions // void on_quit_action (GSimpleAction *action, GVariant *parameter, gpointer user_data); void on_about_action (GSimpleAction *action, GVariant *parameter, gpointer user_data); void on_preferences_action (GSimpleAction *action, GVariant *parameter, gpointer user_data); +void on_togglerunedit_action (GSimpleAction *action, GVariant *parameter, gpointer user_data); +void on_togglerunstop_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); @@ -96,6 +102,8 @@ static const GActionEntry app_actions[] = { { "quit", on_quit_action, NULL, NULL, NULL }, { "about", on_about_action, NULL, NULL, NULL }, { "preferences", on_preferences_action, NULL, NULL, NULL }, + { "togglerunedit", on_togglerunedit_action, NULL, NULL, NULL }, + { "togglerunstop", on_togglerunstop_action, NULL, NULL, NULL }, { "togglesidebar", on_togglesidebar_action, NULL, NULL, NULL }, { "editmode", on_editmode_action, NULL, NULL, NULL }, { "runmode", on_runmode_action, NULL, NULL, NULL }, @@ -166,8 +174,9 @@ void ui_set_stack(int mode); void ui_send_internal_notification(const char *message); void ui_close_internal_notification(void); +void ui_toggle_runedit_button(); +void ui_toggle_runstop_button(); 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 07a8f32..a480e76 100644 --- a/src/ui/application.c +++ b/src/ui/application.c @@ -27,6 +27,10 @@ #define COMMUTE 0 // 0 first design (2023) based on XML data // 1 2024 May design, free of Builder & templates +static int mode = 0; +void set_run_edit_mode(int prescribed_mode) {mode = prescribed_mode;} +int get_run_edit_mode() {return mode;} + /* Window actual presentation on screen */ static void gem_graph_client_application_activate (GApplication *app) { @@ -113,7 +117,6 @@ 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 3dd9f98..c77d8cb 100644 --- a/src/ui/events.c +++ b/src/ui/events.c @@ -78,6 +78,36 @@ void on_preferences_action(GSimpleAction *action, ui_send_internal_notification("Not implemented !"); } +void on_togglerunedit_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GemGraphClientApplication *self = user_data; + + g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self)); + + printf("events on_togglerunedit_action() <><><>\n"); + + ui_toggle_run_edit (); + + /* + if (EDIT_MODE) ui_toggle_run_edit (RUN_MODE); + else if (RUN_MODE) ui_toggle_run_edit (EDIT_MODE); */ +} + +void on_togglerunstop_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GemGraphClientApplication *self = user_data; + + g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self)); + + /* + if (STOP_MODE) ui_toggle_run_edit (RUN_MODE); + else if (RUN_MODE) ui_toggle_run_edit (STOP_MODE); */ +} + void on_togglesidebar_action(GSimpleAction *action, GVariant *parameter, gpointer user_data) @@ -86,22 +116,11 @@ void on_togglesidebar_action(GSimpleAction *action, g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self)); + printf("events on_togglesidebar_action() <><><>\n"); + 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) @@ -179,7 +198,6 @@ 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); } @@ -376,7 +394,6 @@ 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); @@ -412,7 +429,6 @@ 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 f0785f8..63160d2 100644 --- a/src/ui/gemgraph.ui +++ b/src/ui/gemgraph.ui @@ -20,16 +20,23 @@ - + system-run-symbolic Run mode - app.toggle_run_edit + app.togglerunedit + - - + + + + + + + + @@ -47,6 +54,10 @@ sidebar-show-symbolic Display/hide sidebar app.togglesidebar + + + + diff --git a/src/ui/window.c b/src/ui/window.c index ecda1c2..6788943 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -44,8 +44,9 @@ struct _GemGraphClientWindow GtkStack *main_stack; GtkStack *side_stack; GtkPaned *main_paned; + GtkToggleButton *main_button_run_edit; +// GtkToggleButton *main_button_run_stop; GtkMenuButton *main_button_mode; - GtkToggleButton *main_button_run_stop; GtkToggleButton *main_button_sidebar; GtkRevealer *toast_revealer; GtkToggleButton *toast_close_button; @@ -84,7 +85,8 @@ 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_run_edit); +// 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); @@ -153,6 +155,35 @@ void ui_set_stack(int mode) } } +void ui_toggle_run_edit() +{ + if (window->main_button_run_edit == NULL) { + g_printerr("Can't find self->main_button_run_edit !\n"); + return; + } + + printf("window ui_toggle_run_edit() ------ mode = %d", get_run_edit_mode ()); + + switch(get_run_edit_mode()) { + case 1: + // gtk_stack_set_visible_child_full(window->main_button_run_edit, "edition", GTK_STACK_TRANSITION_TYPE_CROSSFADE); + // gtk_menu_button_set_icon_name(window->main_button_run_edit, "document-edit-symbolic"); + set_run_edit_mode (0); // (EDIT_MODE); + // ui_setup_glarea(EDIT_MODE, GTK_WIDGET(window->edition_glarea_box)); + break; + case 0: + // gtk_stack_set_visible_child_full(window->main_button_run_edit, "run", GTK_STACK_TRANSITION_TYPE_CROSSFADE); + // gtk_menu_button_set_icon_name(window->main_button_run_edit, "system-run-symbolic"); + // ui_setup_glarea(RUN_MODE, GTK_WIDGET(window->run_glarea_box)); + // ui_create_tree (GTK_WIDGET (window->run_conditions_tree_box)); + set_run_edit_mode (1); // (RUN_MODE); + break; + default: + break; + } + printf(" > %d\n", get_run_edit_mode ()); +} + void ui_send_internal_notification(const char *message) { if (window->toast_revealer == NULL) { @@ -190,39 +221,11 @@ void ui_toggle_sidebar(void) { int position = gtk_paned_get_position(window->main_paned); + printf("window ui_togglesidebar() ------\n"); + if (position != 0) { gtk_paned_set_position(window->main_paned, 0); } else { 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; - } -}