[gnome-builder] run-button: add tooltips for run button
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] run-button: add tooltips for run button
- Date: Sat, 18 Feb 2017 17:18:24 +0000 (UTC)
commit 3d7ba529482de7e74db9f40e8a26af5a0cc91205
Author: Christian Hergert <chergert redhat com>
Date: Sat Feb 18 09:03:52 2017 -0800
run-button: add tooltips for run button
This adds a tooltip for the drop down menu as well as the run button
itself. This re-uses the GtkShortcutsShortcut so that we get fancy icon
styling on the shortcut.
https://bugzilla.gnome.org/show_bug.cgi?id=778864
libide/runner/ide-run-button.c | 69 ++++++++++++++++++++++++++++++++-------
libide/runner/ide-run-button.ui | 4 ++
2 files changed, 61 insertions(+), 12 deletions(-)
---
diff --git a/libide/runner/ide-run-button.c b/libide/runner/ide-run-button.c
index 59a31aa..f71a7fa 100644
--- a/libide/runner/ide-run-button.c
+++ b/libide/runner/ide-run-button.c
@@ -30,15 +30,16 @@
struct _IdeRunButton
{
- GtkBox parent_instance;
-
- GtkSizeGroup *accel_size_group;
- GtkButton *button;
- GtkImage *button_image;
- GtkListBox *list_box;
- GtkMenuButton *menu_button;
- GtkPopover *popover;
- GtkButton *stop_button;
+ GtkBox parent_instance;
+
+ GtkSizeGroup *accel_size_group;
+ GtkButton *button;
+ GtkImage *button_image;
+ GtkListBox *list_box;
+ GtkMenuButton *menu_button;
+ GtkPopover *popover;
+ GtkButton *stop_button;
+ GtkShortcutsShortcut *run_shortcut;
};
G_DEFINE_TYPE (IdeRunButton, ide_run_button, GTK_TYPE_BOX)
@@ -139,9 +140,6 @@ ide_run_button_handler_set (IdeRunButton *self,
g_object_set (self->button_image,
"icon-name", info->icon_name,
NULL);
- g_object_set (self->button,
- "tooltip-text", info->title,
- NULL);
break;
}
}
@@ -230,6 +228,46 @@ ide_run_button_context_set (GtkWidget *widget,
}
static void
+ide_run_button_query_tooltip (IdeRunButton *self,
+ gint x,
+ gint y,
+ gboolean keyboard_tooltip,
+ GtkTooltip *tooltip,
+ GtkButton *button)
+{
+ IdeRunManager *run_manager;
+ const GList *list;
+ const GList *iter;
+ const gchar *handler;
+ IdeContext *context;
+
+ g_assert (IDE_IS_RUN_BUTTON (self));
+ g_assert (GTK_IS_TOOLTIP (tooltip));
+ g_assert (GTK_IS_BUTTON (button));
+
+ context = ide_widget_get_context (GTK_WIDGET (self));
+ run_manager = ide_context_get_run_manager (context);
+ handler = ide_run_manager_get_handler (run_manager);
+ list = _ide_run_manager_get_handlers (run_manager);
+
+ for (iter = list; iter; iter = iter->next)
+ {
+ const IdeRunHandlerInfo *info = iter->data;
+
+ if (g_strcmp0 (info->id, handler) == 0)
+ {
+ g_object_set (self->run_shortcut,
+ "accelerator", info->accel,
+ "title", info->title,
+ "visible", TRUE,
+ NULL);
+ gtk_tooltip_set_custom (tooltip, GTK_WIDGET (self->run_shortcut));
+ break;
+ }
+ }
+}
+
+static void
ide_run_button_class_init (IdeRunButtonClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
@@ -241,6 +279,7 @@ ide_run_button_class_init (IdeRunButtonClass *klass)
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, list_box);
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, menu_button);
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, popover);
+ gtk_widget_class_bind_template_child (widget_class, IdeRunButton, run_shortcut);
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, stop_button);
}
@@ -255,5 +294,11 @@ ide_run_button_init (IdeRunButton *self)
self,
G_CONNECT_SWAPPED);
+ g_signal_connect_object (self->button,
+ "query-tooltip",
+ G_CALLBACK (ide_run_button_query_tooltip),
+ self,
+ G_CONNECT_SWAPPED);
+
ide_widget_set_context_handler (self, ide_run_button_context_set);
}
diff --git a/libide/runner/ide-run-button.ui b/libide/runner/ide-run-button.ui
index 440a026..5b901d5 100644
--- a/libide/runner/ide-run-button.ui
+++ b/libide/runner/ide-run-button.ui
@@ -10,6 +10,8 @@
</object>
</child>
</object>
+ <object class="GtkShortcutsShortcut" id="run_shortcut">
+ </object>
<template class="IdeRunButton" parent="GtkBox">
<property name="orientation">horizontal</property>
<style>
@@ -19,6 +21,7 @@
<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>
<style>
<class name="image-button"/>
@@ -51,6 +54,7 @@
<object class="GtkMenuButton" id="menu_button">
<property name="focus-on-click">false</property>
<property name="popover">popover</property>
+ <property name="tooltip-text" translatable="yes">Change run options</property>
<property name="visible">true</property>
<style>
<class name="image-button"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]