WIP: ^c^v > a toggle_run_edit button

This commit is contained in:
Jean Sirmai 2024-05-27 08:29:45 +02:00
parent 6e6f9f0e99
commit a2bb86c86e
Signed by: jean
GPG Key ID: FB3115C340E057E3
5 changed files with 96 additions and 54 deletions

View File

@ -76,12 +76,18 @@ void ui_enable_action(const char *name);
void ui_disable_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 // Actions
// //
void on_quit_action (GSimpleAction *action, GVariant *parameter, gpointer user_data); void on_quit_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
void on_about_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_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_togglesidebar_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
void on_editmode_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_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 }, { "quit", on_quit_action, NULL, NULL, NULL },
{ "about", on_about_action, NULL, NULL, NULL }, { "about", on_about_action, NULL, NULL, NULL },
{ "preferences", on_preferences_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 }, { "togglesidebar", on_togglesidebar_action, NULL, NULL, NULL },
{ "editmode", on_editmode_action, NULL, NULL, NULL }, { "editmode", on_editmode_action, NULL, NULL, NULL },
{ "runmode", on_runmode_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_send_internal_notification(const char *message);
void ui_close_internal_notification(void); void ui_close_internal_notification(void);
void ui_toggle_runedit_button();
void ui_toggle_runstop_button();
void ui_toggle_sidebar(); void ui_toggle_sidebar();
void ui_toggle_run_edit(int mode);
// //
// Graphical stuff // Graphical stuff

View File

@ -27,6 +27,10 @@
#define COMMUTE 0 // 0 first design (2023) based on <gemgraph.ui> XML data #define COMMUTE 0 // 0 first design (2023) based on <gemgraph.ui> XML data
// 1 2024 May design, free of Builder & templates // 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 */ /* Window actual presentation on screen */
static void gem_graph_client_application_activate (GApplication *app) 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("runmode");
ui_disable_action("presentmode"); ui_disable_action("presentmode");
ui_disable_action("togglesidebar"); ui_disable_action("togglesidebar");
ui_disable_action("toggle_run_edit");
} }
void ui_send_notification(const char *message) void ui_send_notification(const char *message)

View File

@ -78,6 +78,36 @@ void on_preferences_action(GSimpleAction *action,
ui_send_internal_notification("Not implemented !"); 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, void on_togglesidebar_action(GSimpleAction *action,
GVariant *parameter, GVariant *parameter,
gpointer user_data) gpointer user_data)
@ -86,22 +116,11 @@ void on_togglesidebar_action(GSimpleAction *action,
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self)); g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
printf("events on_togglesidebar_action() <><><>\n");
ui_toggle_sidebar(); 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, void on_editmode_action(GSimpleAction *action,
GVariant *parameter, GVariant *parameter,
gpointer user_data) gpointer user_data)
@ -179,7 +198,6 @@ void on_closefile_action(GSimpleAction *action,
ui_disable_action("editmode"); ui_disable_action("editmode");
ui_disable_action("presentmode"); ui_disable_action("presentmode");
ui_disable_action("togglesidebar"); ui_disable_action("togglesidebar");
ui_disable_action("toggle_run_edit");
ui_set_stack(HOME_MODE); ui_set_stack(HOME_MODE);
} }
@ -376,7 +394,6 @@ void ui_model_loading(GObject *source_object,
ui_enable_action("editmode"); ui_enable_action("editmode");
ui_enable_action("presentmode"); ui_enable_action("presentmode");
ui_enable_action("togglesidebar"); ui_enable_action("togglesidebar");
ui_enable_action("toggle_run_edit");
ui_set_stack(RUN_MODE); ui_set_stack(RUN_MODE);
g_free(basenamestr); g_free(basenamestr);
@ -412,7 +429,6 @@ void ui_debug_model_loading (GtkWindow *self, const char *file)
ui_enable_action("editmode"); ui_enable_action("editmode");
ui_enable_action("presentmode"); ui_enable_action("presentmode");
ui_enable_action("togglesidebar"); ui_enable_action("togglesidebar");
ui_enable_action("toggle_run_edit");
ui_set_stack(RUN_MODE); ui_set_stack(RUN_MODE);
ui_toggle_sidebar(); ui_toggle_sidebar();
} }

View File

@ -25,11 +25,18 @@
<object class="GtkToggleButton" id="main_button_run_edit"> <object class="GtkToggleButton" id="main_button_run_edit">
<property name="icon-name">system-run-symbolic</property> <property name="icon-name">system-run-symbolic</property>
<property name="tooltip-text" translatable="yes">Run mode</property> <property name="tooltip-text" translatable="yes">Run mode</property>
<property name="action-name">app.toggle_run_edit</property> <property name="action-name">app.togglerunedit</property>
<!-- property name="color">rgb(255,128,0)</property -->
<!-- applications should be compiled with the -Wl,--export-dynamic argument inside their compiler flags --> <!-- applications should be compiled with the -Wl,--export-dynamic argument inside their compiler flags -->
<!-- and linked against gmodule-export-2.0 --> <!-- and linked against gmodule-export-2.0 -->
<!-- A GtkBuilder reads XML descriptions of a user interface and instantiates the described objects. -->
<!-- https://docs.gtk.org/gtk4/class.Builder.html --> <!-- https://docs.gtk.org/gtk4/class.Builder.html -->
<!--signal name="clicked" handler="ui_toggle_run_edit" on_toggle_run_stop_action /--> <!-- https://docs.gtk.org/gtk4/css-properties.html -->
<!-- https://docs.gtk.org/gtk4/class.Widget.html#building-composite-widgets-from-template-xml -->
<!-- unlike the <object> tag, the <template> tag does not contain an “id” attribute -->
<!-- https://developer.gnome.org/documentation/tutorials/widget-templates.html -->
<!-- https://developer.gnome.org/documentation/tutorials/application.html -->
<!-- signal name="clicked" handler="ui_toggle_run_edit"/ -->
</object> </object>
</child> </child>
@ -47,6 +54,10 @@
<property name="icon-name">sidebar-show-symbolic</property> <property name="icon-name">sidebar-show-symbolic</property>
<property name="tooltip-text" translatable="yes">Display/hide sidebar</property> <property name="tooltip-text" translatable="yes">Display/hide sidebar</property>
<property name="action-name">app.togglesidebar</property> <property name="action-name">app.togglesidebar</property>
<!-- applications should be compiled with the -Wl,--export-dynamic argument inside their compiler flags -->
<!-- and linked against gmodule-export-2.0 -->
<!-- https://docs.gtk.org/gtk4/class.Builder.html -->
<!--signal name="clicked" handler="ui_toggle_sidebar" /-->
</object> </object>
</child> </child>
</object> </object>

View File

@ -44,8 +44,9 @@ struct _GemGraphClientWindow
GtkStack *main_stack; GtkStack *main_stack;
GtkStack *side_stack; GtkStack *side_stack;
GtkPaned *main_paned; GtkPaned *main_paned;
GtkToggleButton *main_button_run_edit;
// GtkToggleButton *main_button_run_stop;
GtkMenuButton *main_button_mode; GtkMenuButton *main_button_mode;
GtkToggleButton *main_button_run_stop;
GtkToggleButton *main_button_sidebar; GtkToggleButton *main_button_sidebar;
GtkRevealer *toast_revealer; GtkRevealer *toast_revealer;
GtkToggleButton *toast_close_button; 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, main_stack);
gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, side_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_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_mode);
gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_button_sidebar); gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, main_button_sidebar);
gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, toast_revealer); 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) void ui_send_internal_notification(const char *message)
{ {
if (window->toast_revealer == NULL) { if (window->toast_revealer == NULL) {
@ -190,39 +221,11 @@ void ui_toggle_sidebar(void)
{ {
int position = gtk_paned_get_position(window->main_paned); int position = gtk_paned_get_position(window->main_paned);
printf("window ui_togglesidebar() ------\n");
if (position != 0) { if (position != 0) {
gtk_paned_set_position(window->main_paned, 0); gtk_paned_set_position(window->main_paned, 0);
} else { } else {
gtk_paned_set_position(window->main_paned, 400); 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;
}
}