[gnome-builder] devices: make device GMenu private to IdeContext
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] devices: make device GMenu private to IdeContext
- Date: Thu, 15 Mar 2018 01:32:32 +0000 (UTC)
commit 24e8d783bed2e2dda42fdbf46b23ad75505c6b91
Author: Christian Hergert <chergert redhat com>
Date: Wed Mar 14 18:32:00 2018 -0700
devices: make device GMenu private to IdeContext
We can't use a global GMenu since that will result in duplicate entries
when secondary workbenches are opened. This uses a private GMenu owned
by the IdeDeviceManager and uses that from the omnibar.
src/libide/devices/ide-device-manager.c | 31 +++++++++++++++++++++++++------
src/libide/devices/ide-device-private.h | 27 +++++++++++++++++++++++++++
src/libide/gtk/menus.ui | 5 -----
src/libide/workbench/ide-omni-bar.c | 6 ++++++
src/libide/workbench/ide-omni-bar.ui | 1 -
5 files changed, 58 insertions(+), 12 deletions(-)
---
diff --git a/src/libide/devices/ide-device-manager.c b/src/libide/devices/ide-device-manager.c
index f84d6e23f..a42c7c6d5 100644
--- a/src/libide/devices/ide-device-manager.c
+++ b/src/libide/devices/ide-device-manager.c
@@ -30,6 +30,7 @@
#include "devices/ide-deploy-strategy.h"
#include "devices/ide-device.h"
#include "devices/ide-device-manager.h"
+#include "devices/ide-device-private.h"
#include "devices/ide-device-provider.h"
#include "local/ide-local-device.h"
#include "plugins/ide-extension-util.h"
@@ -58,6 +59,14 @@ struct _IdeDeviceManager
*/
PeasExtensionSet *providers;
+ /*
+ * Our menu that contains our list of devices for the user to select. This
+ * is "per-IdeContext" so that it is not global to the system (which would
+ * result in duplicates for each workbench opened).
+ */
+ GMenu *menu;
+ GMenu *menu_section;
+
/*
* Our progress in a deployment. Simplifies binding to the progress bar
* in the omnibar.
@@ -121,7 +130,6 @@ ide_device_manager_provider_device_added_cb (IdeDeviceManager *self,
const gchar *display_name;
const gchar *icon_name;
const gchar *device_id;
- GMenu *menu;
guint position;
IDE_ENTRY;
@@ -141,15 +149,13 @@ ide_device_manager_provider_device_added_cb (IdeDeviceManager *self,
g_ptr_array_add (self->devices, g_object_ref (device));
/* Now add a new menu item to our selection model */
- menu = dzl_application_get_menu_by_id (DZL_APPLICATION (IDE_APPLICATION_DEFAULT),
- "ide-device-manager-menu-section");
menu_item = g_menu_item_new (display_name, NULL);
g_menu_item_set_attribute (menu_item, "id", "s", device_id);
g_menu_item_set_attribute (menu_item, "verb-icon-name", "s", icon_name ?: "computer-symbolic");
g_menu_item_set_action_and_target_value (menu_item,
"device-manager.device",
g_variant_new_string (device_id));
- g_menu_append_item (menu, menu_item);
+ g_menu_append_item (self->menu_section, menu_item);
/* Now notify about the new device */
g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
@@ -174,8 +180,7 @@ ide_device_manager_provider_device_removed_cb (IdeDeviceManager *self,
device_id = ide_device_get_id (device);
- menu = dzl_application_get_menu_by_id (DZL_APPLICATION (IDE_APPLICATION_DEFAULT),
- "ide-device-manager-menu-section");
+ menu = self->menu_section;
n_items = g_menu_model_get_n_items (G_MENU_MODEL (menu));
for (guint i = 0; i < n_items; i++)
@@ -449,6 +454,8 @@ ide_device_manager_finalize (GObject *object)
IdeDeviceManager *self = (IdeDeviceManager *)object;
g_clear_pointer (&self->devices, g_ptr_array_unref);
+ g_clear_object (&self->menu);
+ g_clear_object (&self->menu_section);
G_OBJECT_CLASS (ide_device_manager_parent_class)->finalize (object);
}
@@ -564,6 +571,10 @@ static void
ide_device_manager_init (IdeDeviceManager *self)
{
self->devices = g_ptr_array_new_with_free_func (g_object_unref);
+
+ self->menu = g_menu_new ();
+ self->menu_section = g_menu_new ();
+ g_menu_append_section (self->menu, _("Devices"), G_MENU_MODEL (self->menu_section));
}
/**
@@ -988,3 +999,11 @@ ide_device_manager_get_progress (IdeDeviceManager *self)
return self->progress;
}
+
+GMenu *
+_ide_device_manager_get_menu (IdeDeviceManager *self)
+{
+ g_return_val_if_fail (IDE_IS_DEVICE_MANAGER (self), NULL);
+
+ return self->menu;
+}
diff --git a/src/libide/devices/ide-device-private.h b/src/libide/devices/ide-device-private.h
new file mode 100644
index 000000000..710b32449
--- /dev/null
+++ b/src/libide/devices/ide-device-private.h
@@ -0,0 +1,27 @@
+/* ide-device-private.h
+ *
+ * Copyright 2018 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "ide-device-manager.h"
+
+G_BEGIN_DECLS
+
+GMenu *_ide_device_manager_get_menu (IdeDeviceManager *self);
+
+G_END_DECLS
diff --git a/src/libide/gtk/menus.ui b/src/libide/gtk/menus.ui
index 09ce71d60..478b7c42f 100644
--- a/src/libide/gtk/menus.ui
+++ b/src/libide/gtk/menus.ui
@@ -247,9 +247,4 @@
</submenu>
</section>
</menu>
- <menu id="ide-device-manager-menu">
- <section id="ide-device-manager-menu-section">
- <attribute name="label" translatable="yes">Devices</attribute>
- </section>
- </menu>
</interface>
diff --git a/src/libide/workbench/ide-omni-bar.c b/src/libide/workbench/ide-omni-bar.c
index b92d0762d..92f7d1af4 100644
--- a/src/libide/workbench/ide-omni-bar.c
+++ b/src/libide/workbench/ide-omni-bar.c
@@ -30,6 +30,7 @@
#include "config/ide-configuration.h"
#include "config/ide-configuration-manager.h"
#include "devices/ide-device-manager.h"
+#include "devices/ide-device-private.h"
#include "projects/ide-project.h"
#include "runtimes/ide-runtime.h"
#include "util/ide-gtk.h"
@@ -135,6 +136,7 @@ struct _IdeOmniBar
GtkButton *cancel_button;
GtkLabel *config_name_label;
GtkLabel *config_ready_label;
+ DzlMenuButton *device_button;
GtkStack *message_stack;
DzlListBox *pausables;
GtkPopover *popover;
@@ -269,6 +271,7 @@ ide_omni_bar_context_set (GtkWidget *widget,
GListModel *pausables = NULL;
IdeProject *project = NULL;
IdeVcs *vcs = NULL;
+ GMenu *menu = NULL;
IDE_ENTRY;
@@ -285,6 +288,7 @@ ide_omni_bar_context_set (GtkWidget *widget,
project = ide_context_get_project (context);
pausables = _ide_context_get_pausables (context);
device_manager = ide_context_get_device_manager (context);
+ menu = _ide_device_manager_get_menu (device_manager);
}
dzl_binding_group_set_source (self->build_manager_bindings, build_manager);
@@ -294,6 +298,7 @@ ide_omni_bar_context_set (GtkWidget *widget,
dzl_binding_group_set_source (self->project_bindings, project);
dzl_binding_group_set_source (self->vcs_bindings, vcs);
dzl_list_box_set_model (self->pausables, pausables);
+ dzl_menu_button_set_model (self->device_button, G_MENU_MODEL (menu));
if (config_manager != NULL)
{
@@ -638,6 +643,7 @@ ide_omni_bar_class_init (IdeOmniBarClass *klass)
gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, cancel_button);
gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, config_name_label);
gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, config_ready_label);
+ gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, device_button);
gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, event_box);
gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, message_stack);
gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, pausables);
diff --git a/src/libide/workbench/ide-omni-bar.ui b/src/libide/workbench/ide-omni-bar.ui
index 8a501474a..101f93287 100644
--- a/src/libide/workbench/ide-omni-bar.ui
+++ b/src/libide/workbench/ide-omni-bar.ui
@@ -6,7 +6,6 @@
</style>
<child>
<object class="DzlMenuButton" id="device_button">
- <property name="menu-id">ide-device-manager-menu</property>
<property name="icon-name">computer-symbolic</property>
<property name="focus-on-click">false</property>
<property name="show-arrow">false</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]