[gnome-builder/wip/chergert/layout] menus: use DzlMenuButton for run menu button
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/layout] menus: use DzlMenuButton for run menu button
- Date: Tue, 11 Jul 2017 01:39:42 +0000 (UTC)
commit 3befa37a11e365493bf9fae594c081305eef9e1c
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 10 18:37:45 2017 -0700
menus: use DzlMenuButton for run menu button
This is yet another menu we can consolidate. It also allows for
plugins to specify their extensions to the menu without strictly
implementing a run handler (event if it does currently require
duplicating the icon/name entries).
What might be a possibility going forward is to generate the
GMenu entries based on the handler registration.
data/gtk/menus.ui | 12 ++
data/themes/shared.css | 4 +-
libide/runner/ide-run-button.c | 129 +-----------------------
libide/runner/ide-run-button.ui | 27 +----
plugins/sysprof/gtk/menus.ui | 13 +++
plugins/valgrind/gtk/menus.ui | 16 +++
plugins/valgrind/meson.build | 9 ++
plugins/valgrind/valgrind-plugin.gresource.xml | 6 +
8 files changed, 66 insertions(+), 150 deletions(-)
---
diff --git a/data/gtk/menus.ui b/data/gtk/menus.ui
index 46c0206..1968e05 100644
--- a/data/gtk/menus.ui
+++ b/data/gtk/menus.ui
@@ -327,4 +327,16 @@
</item>
</section>
</menu>
+ <menu id="run-menu">
+ <section id="run-menu-section">
+ <item>
+ <attribute name="id">default-run-handler</attribute>
+ <attribute name="action">run-manager.run-with-handler</attribute>
+ <attribute name="target">run</attribute>
+ <attribute name="label" translatable="yes">Run</attribute>
+ <attribute name="verb-icon-name">media-playback-start-symbolic</attribute>
+ <attribute name="accel"><Control>F5</attribute>
+ </item>
+ </section>
+ </menu>
</interface>
diff --git a/data/themes/shared.css b/data/themes/shared.css
index 420377c..32223e1 100644
--- a/data/themes/shared.css
+++ b/data/themes/shared.css
@@ -298,4 +298,6 @@ popover.transfers list row > box {
padding: 10px;
}
-
+button.run-arrow-button {
+ padding: 0px;
+}
diff --git a/libide/runner/ide-run-button.c b/libide/runner/ide-run-button.c
index 6e3145a..cc5ef8d 100644
--- a/libide/runner/ide-run-button.c
+++ b/libide/runner/ide-run-button.c
@@ -33,89 +33,15 @@ struct _IdeRunButton
{
GtkBox parent_instance;
- GtkSizeGroup *accel_size_group;
GtkButton *button;
GtkImage *button_image;
- GtkListBox *list_box;
- GtkMenuButton *menu_button;
- GtkPopover *popover;
+ DzlMenuButton *menu_button;
GtkButton *stop_button;
GtkShortcutsShortcut *run_shortcut;
};
G_DEFINE_TYPE (IdeRunButton, ide_run_button, GTK_TYPE_BOX)
-static GtkWidget *
-create_row (const IdeRunHandlerInfo *info,
- IdeRunButton *self)
-{
- GtkListBoxRow *row;
- GtkLabel *label;
- GtkImage *image;
- GtkBox *box;
-
- g_assert (info != NULL);
- g_assert (IDE_IS_RUN_BUTTON (self));
-
- row = g_object_new (GTK_TYPE_LIST_BOX_ROW,
- "selectable", FALSE,
- "visible", TRUE,
- NULL);
-
- g_object_set_data_full (G_OBJECT (row), "IDE_RUN_HANDLER_ID", g_strdup (info->id), g_free);
-
- box = g_object_new (GTK_TYPE_BOX,
- "visible", TRUE,
- NULL);
- gtk_container_add (GTK_CONTAINER (row), GTK_WIDGET (box));
-
- image = g_object_new (GTK_TYPE_IMAGE,
- "hexpand", FALSE,
- "icon-name", info->icon_name,
- "visible", TRUE,
- NULL);
- gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (image));
-
- label = g_object_new (GTK_TYPE_LABEL,
- "label", info->title,
- "hexpand", TRUE,
- "xalign", 0.0f,
- "visible", TRUE,
- NULL);
- gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (label));
-
- if (info->accel != NULL)
- {
- g_autofree gchar *xaccel = NULL;
- guint accel_key = 0;
- GdkModifierType accel_mod = 0;
-
- gtk_accelerator_parse (info->accel, &accel_key, &accel_mod);
- xaccel = gtk_accelerator_get_label (accel_key, accel_mod);
- label = g_object_new (GTK_TYPE_LABEL,
- "label", xaccel,
- "visible", TRUE,
- "xalign", 0.0f,
- NULL);
- dzl_gtk_widget_add_style_class (GTK_WIDGET (label), "dim-label");
- dzl_gtk_widget_add_style_class (GTK_WIDGET (label), "accel");
- gtk_container_add_with_properties (GTK_CONTAINER (box), GTK_WIDGET (label),
- "pack-type", GTK_PACK_END,
- NULL);
- gtk_size_group_add_widget (self->accel_size_group, GTK_WIDGET (label));
- }
-
- return GTK_WIDGET (row);
-}
-
-static void
-ide_run_button_clear (IdeRunButton *self)
-{
- g_assert (IDE_IS_RUN_BUTTON (self));
-
- gtk_container_foreach (GTK_CONTAINER (self->list_box), (GtkCallback)gtk_widget_destroy, NULL);
-}
-
static void
ide_run_button_handler_set (IdeRunButton *self,
GParamSpec *pspec,
@@ -150,24 +76,11 @@ ide_run_button_load (IdeRunButton *self,
IdeContext *context)
{
IdeRunManager *run_manager;
- const GList *list;
- const GList *iter;
g_assert (IDE_IS_RUN_BUTTON (self));
g_assert (IDE_IS_CONTEXT (context));
run_manager = ide_context_get_run_manager (context);
- list = _ide_run_manager_get_handlers (run_manager);
-
- for (iter = list; iter; iter = iter->next)
- {
- const IdeRunHandlerInfo *info = iter->data;
- GtkWidget *row;
-
- row = create_row (info, self);
-
- gtk_container_add (GTK_CONTAINER (self->list_box), row);
- }
g_object_bind_property (run_manager, "busy", self->button, "visible",
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
@@ -184,35 +97,6 @@ ide_run_button_load (IdeRunButton *self,
}
static void
-ide_run_button_row_activated (IdeRunButton *self,
- GtkListBoxRow *row,
- GtkListBox *list_box)
-{
- IdeContext *context;
- const gchar *id;
-
- g_assert (IDE_IS_RUN_BUTTON (self));
- g_assert (GTK_IS_LIST_BOX_ROW (row));
- g_assert (GTK_IS_LIST_BOX (list_box));
-
- context = ide_widget_get_context (GTK_WIDGET (self));
- id = g_object_get_data (G_OBJECT (row), "IDE_RUN_HANDLER_ID");
-
- if (id != NULL && context != NULL)
- {
- IdeRunManager *run_manager;
-
- /* First change the run action to the selected handler. */
- run_manager = ide_context_get_run_manager (context);
- ide_run_manager_set_handler (run_manager, id);
- gtk_popover_popdown (self->popover);
-
- /* Now run the action */
- dzl_gtk_widget_action (GTK_WIDGET (self), "run-manager", "run-with-handler", g_variant_new_string
(id));
- }
-}
-
-static void
ide_run_button_context_set (GtkWidget *widget,
IdeContext *context)
{
@@ -221,8 +105,6 @@ ide_run_button_context_set (GtkWidget *widget,
g_assert (IDE_IS_RUN_BUTTON (self));
g_assert (!context || IDE_IS_CONTEXT (context));
- ide_run_button_clear (self);
-
if (context != NULL)
ide_run_button_load (self, context);
}
@@ -273,12 +155,9 @@ ide_run_button_class_init (IdeRunButtonClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/ui/ide-run-button.ui");
- gtk_widget_class_bind_template_child (widget_class, IdeRunButton, accel_size_group);
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, button);
gtk_widget_class_bind_template_child (widget_class, IdeRunButton, button_image);
- 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);
}
@@ -288,12 +167,6 @@ ide_run_button_init (IdeRunButton *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
- g_signal_connect_object (self->list_box,
- "row-activated",
- G_CALLBACK (ide_run_button_row_activated),
- self,
- G_CONNECT_SWAPPED);
-
g_signal_connect_object (self->button,
"query-tooltip",
G_CALLBACK (ide_run_button_query_tooltip),
diff --git a/libide/runner/ide-run-button.ui b/libide/runner/ide-run-button.ui
index 5b901d5..3b4efe0 100644
--- a/libide/runner/ide-run-button.ui
+++ b/libide/runner/ide-run-button.ui
@@ -1,15 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <object class="GtkPopover" id="popover">
- <style>
- <class name="popover-selector"/>
- </style>
- <child>
- <object class="GtkListBox" id="list_box">
- <property name="visible">true</property>
- </object>
- </child>
- </object>
<object class="GtkShortcutsShortcut" id="run_shortcut">
</object>
<template class="IdeRunButton" parent="GtkBox">
@@ -51,25 +41,20 @@
</object>
</child>
<child>
- <object class="GtkMenuButton" id="menu_button">
+ <object class="DzlMenuButton" id="menu_button">
<property name="focus-on-click">false</property>
- <property name="popover">popover</property>
+ <property name="icon-name">pan-down-symbolic</property>
+ <property name="menu-id">run-menu</property>
+ <property name="show-accels">true</property>
+ <property name="show-arrow">false</property>
+ <property name="show-icons">true</property>
<property name="tooltip-text" translatable="yes">Change run options</property>
<property name="visible">true</property>
<style>
<class name="image-button"/>
<class name="run-arrow-button"/>
</style>
- <child>
- <object class="GtkImage" id="menu_button_image">
- <property name="icon-name">pan-down-symbolic</property>
- <property name="visible">true</property>
- </object>
- </child>
</object>
</child>
</template>
- <object class="GtkSizeGroup" id="accel_size_group">
- <property name="mode">horizontal</property>
- </object>
</interface>
diff --git a/plugins/sysprof/gtk/menus.ui b/plugins/sysprof/gtk/menus.ui
index 2e1c0f4..80af284 100644
--- a/plugins/sysprof/gtk/menus.ui
+++ b/plugins/sysprof/gtk/menus.ui
@@ -21,4 +21,17 @@
</item>
</section>
</menu>
+ <menu id="run-menu">
+ <section id="run-menu-section">
+ <item>
+ <attribute name="id">profiler-run-handler</attribute>
+ <attribute name="after">default-run-handler</attribute>
+ <attribute name="action">run-manager.run-with-handler</attribute>
+ <attribute name="target">profiler</attribute>
+ <attribute name="label" translatable="yes">Run with Profiler</attribute>
+ <attribute name="verb-icon-name">utilities-system-monitor-symbolic</attribute>
+ <attribute name="accel"><Control>F8</attribute>
+ </item>
+ </section>
+ </menu>
</interface>
diff --git a/plugins/valgrind/gtk/menus.ui b/plugins/valgrind/gtk/menus.ui
new file mode 100644
index 0000000..598a29e
--- /dev/null
+++ b/plugins/valgrind/gtk/menus.ui
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <menu id="run-menu">
+ <section id="run-menu-section">
+ <item>
+ <attribute name="id">valgrind-run-handler</attribute>
+ <attribute name="after">default-run-handler</attribute>
+ <attribute name="action">run-manager.run-with-handler</attribute>
+ <attribute name="target">valgrind</attribute>
+ <attribute name="label" translatable="yes">Run with Valgrind</attribute>
+ <attribute name="verb-icon-name">system-run-symbolic</attribute>
+ <attribute name="accel"><Control>F10</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/plugins/valgrind/meson.build b/plugins/valgrind/meson.build
index 4489ab6..7bcf042 100644
--- a/plugins/valgrind/meson.build
+++ b/plugins/valgrind/meson.build
@@ -2,6 +2,15 @@ if get_option('with_valgrind')
install_data('valgrind_plugin.py', install_dir: plugindir)
+valgrind_resources = gnome.compile_resources(
+ 'valgrind_plugin',
+ 'valgrind-plugin.gresource.xml',
+
+ gresource_bundle: true,
+ install: true,
+ install_dir: plugindir,
+)
+
configure_file(
input: 'valgrind.plugin',
output: 'valgrind.plugin',
diff --git a/plugins/valgrind/valgrind-plugin.gresource.xml b/plugins/valgrind/valgrind-plugin.gresource.xml
new file mode 100644
index 0000000..2c0ad6e
--- /dev/null
+++ b/plugins/valgrind/valgrind-plugin.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/builder/plugins/valgrind_plugin">
+ <file>gtk/menus.ui</file>
+ </gresource>
+</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]