[gnome-builder] gui: Use a single run button instead of GtkStack -like double hidden buttons
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] gui: Use a single run button instead of GtkStack -like double hidden buttons
- Date: Wed, 7 Jul 2021 23:19:36 +0000 (UTC)
commit 6f9affe7b19c27d1d52e675ede3654aaae198f47
Author: vanadiae <vanadiae35 gmail com>
Date: Wed Jul 7 22:55:12 2021 +0200
gui: Use a single run button instead of GtkStack -like double hidden buttons
Currently when clicking the run button, a slight border radius animation due
to the linked style class happens. This is because there's actually two buttons,
one for the "stop build" and one to "run build".
While we could just be disabling transitions to avoid this issue, there's not
much reasons to have two buttons like that. We could be using a stack instead,
but that won't work with the linked style class, which basically expects
the "box.linked > button" CSS selector here. So instead, this commit listens
for changes of "busy state" of the run manager, and the run handler change
to change both the Run button icon and the action name triggered by the button.
src/libide/gui/ide-run-button.c | 50 ++++++++++++++++++++++++++++++++--------
src/libide/gui/ide-run-button.ui | 18 +--------------
2 files changed, 42 insertions(+), 26 deletions(-)
---
diff --git a/src/libide/gui/ide-run-button.c b/src/libide/gui/ide-run-button.c
index 6b69341ba..4b0d6bf5c 100644
--- a/src/libide/gui/ide-run-button.c
+++ b/src/libide/gui/ide-run-button.c
@@ -38,10 +38,11 @@ struct _IdeRunButton
GtkButton *button;
GtkImage *button_image;
DzlMenuButton *menu_button;
- GtkButton *stop_button;
GtkShortcutsShortcut *run_shortcut;
GtkLabel *run_tooltip_message;
DzlShortcutTooltip *tooltip;
+
+ char *run_handler_icon_name;
};
G_DEFINE_TYPE (IdeRunButton, ide_run_button, GTK_TYPE_BOX)
@@ -67,14 +68,39 @@ ide_run_button_handler_set (IdeRunButton *self,
if (g_strcmp0 (info->id, handler) == 0)
{
- g_object_set (self->button_image,
- "icon-name", info->icon_name,
- NULL);
+ self->run_handler_icon_name = g_strdup (info->icon_name);
+ g_object_set (self->button_image, "icon-name", info->icon_name, NULL);
break;
}
}
}
+static void
+on_run_busy_state_changed_cb (IdeRunButton *self,
+ GParamSpec *pspec,
+ IdeRunManager *run_manager)
+{
+ const char *icon_name;
+ const char *action_name;
+
+ g_assert (IDE_IS_RUN_BUTTON (self));
+ g_assert (IDE_IS_RUN_MANAGER (run_manager));
+
+ if (!ide_run_manager_get_busy (run_manager))
+ {
+ icon_name = self->run_handler_icon_name;
+ action_name = "run-manager.run";
+ }
+ else
+ {
+ icon_name = "builder-run-stop-symbolic";
+ action_name = "run-manager.stop";
+ }
+
+ g_object_set (self->button_image, "icon-name", icon_name, NULL);
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (self->button), action_name);
+}
+
static void
ide_run_button_load (IdeRunButton *self,
IdeContext *context)
@@ -86,10 +112,11 @@ ide_run_button_load (IdeRunButton *self,
run_manager = ide_run_manager_from_context (context);
- g_object_bind_property (run_manager, "busy", self->button, "visible",
- G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
- g_object_bind_property (run_manager, "busy", self->stop_button, "visible",
- G_BINDING_SYNC_CREATE);
+ g_signal_connect_object (run_manager,
+ "notify::busy",
+ G_CALLBACK (on_run_busy_state_changed_cb),
+ self,
+ G_CONNECT_SWAPPED);
g_signal_connect_object (run_manager,
"notify::handler",
@@ -136,6 +163,12 @@ ide_run_button_query_tooltip (IdeRunButton *self,
handler = ide_run_manager_get_handler (run_manager);
list = _ide_run_manager_get_handlers (run_manager);
+ if (ide_run_manager_get_busy (run_manager))
+ {
+ gtk_tooltip_set_text (tooltip, _("Stop running"));
+ return TRUE;
+ }
+
for (iter = list; iter; iter = iter->next)
{
const IdeRunHandlerInfo *info = iter->data;
@@ -180,7 +213,6 @@ ide_run_button_class_init (IdeRunButtonClass *klass)
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, button_image);
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, menu_button);
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, run_shortcut);
- gtk_widget_class_bind_template_child (widget_class, IdeRunButton, stop_button);
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, run_tooltip_message);
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, tooltip);
}
diff --git a/src/libide/gui/ide-run-button.ui b/src/libide/gui/ide-run-button.ui
index 9a5092f71..f75308b9f 100644
--- a/src/libide/gui/ide-run-button.ui
+++ b/src/libide/gui/ide-run-button.ui
@@ -13,10 +13,10 @@
</style>
<child>
<object class="GtkButton" id="button">
- <property name="action-name">run-manager.run</property>
<property name="focus-on-click">false</property>
<property name="has-tooltip">true</property>
<property name="visible">true</property>
+ <property name="action-name">run-manager.run</property>
<style>
<class name="image-button"/>
</style>
@@ -28,22 +28,6 @@
</child>
</object>
</child>
- <child>
- <object class="GtkButton" id="stop_button">
- <property name="action-name">run-manager.stop</property>
- <property name="focus-on-click">false</property>
- <property name="tooltip-text" translatable="yes">Stop running</property>
- <style>
- <class name="image-button"/>
- </style>
- <child>
- <object class="GtkImage">
- <property name="icon-name">builder-run-stop-symbolic</property>
- <property name="visible">true</property>
- </object>
- </child>
- </object>
- </child>
<child>
<object class="DzlMenuButton" id="menu_button">
<property name="focus-on-click">false</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]