[gnome-panel] menu: don't pass GpApplet object to GpMenu
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] menu: don't pass GpApplet object to GpMenu
- Date: Mon, 17 Sep 2018 14:57:19 +0000 (UTC)
commit 315999a7505672a3ace7b5962992788241e84bef
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Sep 16 15:47:15 2018 +0300
menu: don't pass GpApplet object to GpMenu
modules/menu/gp-menu-bar-applet.c | 34 +++++++-
modules/menu/gp-menu-button-applet.c | 19 ++++-
modules/menu/gp-menu.c | 157 +++++++++++++++++++----------------
modules/menu/gp-menu.h | 4 +-
4 files changed, 136 insertions(+), 78 deletions(-)
---
diff --git a/modules/menu/gp-menu-bar-applet.c b/modules/menu/gp-menu-bar-applet.c
index 5346a28e0..2cfc0a021 100644
--- a/modules/menu/gp-menu-bar-applet.c
+++ b/modules/menu/gp-menu-bar-applet.c
@@ -126,9 +126,24 @@ append_applications_item (GpMenuBarApplet *applet)
menu = gp_menu_utils_get_applications_menu ();
- applet->applications_menu = gp_menu_new (GP_APPLET (applet), menu, TRUE);
+ applet->applications_menu = gp_menu_new (menu, TRUE);
g_free (menu);
+ g_object_bind_property (applet, "enable-tooltips",
+ applet->applications_menu, "enable-tooltips",
+ G_BINDING_DEFAULT |
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (applet, "locked-down",
+ applet->applications_menu, "locked-down",
+ G_BINDING_DEFAULT |
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (applet, "menu-icon-size",
+ applet->applications_menu, "menu-icon-size",
+ G_BINDING_DEFAULT |
+ G_BINDING_SYNC_CREATE);
+
gtk_menu_item_set_submenu (GTK_MENU_ITEM (applet->applications_item),
applet->applications_menu);
@@ -173,9 +188,24 @@ append_system_item (GpMenuBarApplet *applet)
tooltip = _("Change system appearance and behavior, or get help");
gtk_widget_set_tooltip_text (applet->system_item, tooltip);
- applet->system_menu = gp_menu_new (GP_APPLET (applet), menu, FALSE);
+ applet->system_menu = gp_menu_new (menu, FALSE);
g_free (menu);
+ g_object_bind_property (applet, "enable-tooltips",
+ applet->system_menu, "enable-tooltips",
+ G_BINDING_DEFAULT |
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (applet, "locked-down",
+ applet->system_menu, "locked-down",
+ G_BINDING_DEFAULT |
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (applet, "menu-icon-size",
+ applet->system_menu, "menu-icon-size",
+ G_BINDING_DEFAULT |
+ G_BINDING_SYNC_CREATE);
+
gtk_menu_item_set_submenu (GTK_MENU_ITEM (applet->system_item),
applet->system_menu);
diff --git a/modules/menu/gp-menu-button-applet.c b/modules/menu/gp-menu-button-applet.c
index 24bfcccb2..45945b04a 100644
--- a/modules/menu/gp-menu-button-applet.c
+++ b/modules/menu/gp-menu-button-applet.c
@@ -288,7 +288,7 @@ update_menu (GpMenuButtonApplet *menu_button)
menu_file = NULL;
if (validate_scheme (scheme, &menu_file))
{
- priv->menu = gp_menu_new (GP_APPLET (menu_button), menu_file, TRUE);
+ priv->menu = gp_menu_new (menu_file, TRUE);
gp_menu_set_path (GP_MENU (priv->menu), path);
priv->custom_menu = TRUE;
@@ -307,7 +307,7 @@ update_menu (GpMenuButtonApplet *menu_button)
gchar *menu_file;
menu_file = gp_menu_utils_get_applications_menu ();
- priv->menu = gp_menu_new (GP_APPLET (menu_button), menu_file, TRUE);
+ priv->menu = gp_menu_new (menu_file, TRUE);
g_free (menu_file);
g_assert (priv->lock_logout == NULL);
@@ -323,6 +323,21 @@ update_menu (GpMenuButtonApplet *menu_button)
priv->custom_menu = FALSE;
}
+ g_object_bind_property (menu_button, "enable-tooltips",
+ priv->menu, "enable-tooltips",
+ G_BINDING_DEFAULT |
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (menu_button, "locked-down",
+ priv->menu, "locked-down",
+ G_BINDING_DEFAULT |
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (menu_button, "menu-icon-size",
+ priv->menu, "menu-icon-size",
+ G_BINDING_DEFAULT |
+ G_BINDING_SYNC_CREATE);
+
g_object_ref_sink (priv->menu);
}
diff --git a/modules/menu/gp-menu.c b/modules/menu/gp-menu.c
index 03b260a6f..9256be80a 100644
--- a/modules/menu/gp-menu.c
+++ b/modules/menu/gp-menu.c
@@ -29,9 +29,12 @@ struct _GpMenu
GtkMenu parent;
gchar *name;
- GpApplet *applet;
gboolean required;
+ gboolean enable_tooltips;
+ gboolean locked_down;
+ guint menu_icon_size;
+
GMenuTree *tree;
gboolean loaded;
@@ -42,9 +45,6 @@ struct _GpMenu
guint reload_id;
- gulong locked_down_id;
- gulong menu_icon_size_id;
-
gchar *path;
};
@@ -62,9 +62,12 @@ enum
PROP_0,
PROP_NAME,
- PROP_APPLET,
PROP_REQUIRED,
+ PROP_ENABLE_TOOLTIPS,
+ PROP_LOCKED_DOWN,
+ PROP_MENU_ICON_SIZE,
+
PROP_EMPTY,
LAST_PROP
@@ -119,13 +122,11 @@ append_directory (GtkMenuShell *shell,
if (icon != NULL)
{
GtkWidget *image;
- guint icon_size;
image = gtk_image_new ();
- icon_size = gp_applet_get_menu_icon_size (menu->applet);
gtk_image_set_from_gicon (GTK_IMAGE (image), icon, GTK_ICON_SIZE_MENU);
- gtk_image_set_pixel_size (GTK_IMAGE (image), icon_size);
+ gtk_image_set_pixel_size (GTK_IMAGE (image), menu->menu_icon_size);
gp_image_menu_item_set_image (GP_IMAGE_MENU_ITEM (item), image);
}
@@ -182,13 +183,11 @@ append_entry (GtkMenuShell *shell,
if (icon != NULL)
{
GtkWidget *image;
- guint icon_size;
image = gtk_image_new ();
- icon_size = gp_applet_get_menu_icon_size (menu->applet);
gtk_image_set_from_gicon (GTK_IMAGE (image), icon, GTK_ICON_SIZE_MENU);
- gtk_image_set_pixel_size (GTK_IMAGE (image), icon_size);
+ gtk_image_set_pixel_size (GTK_IMAGE (image), menu->menu_icon_size);
gp_image_menu_item_set_image (GP_IMAGE_MENU_ITEM (item), image);
}
@@ -200,13 +199,13 @@ append_entry (GtkMenuShell *shell,
{
gtk_widget_set_tooltip_text (item, description);
- g_object_bind_property (menu->applet, "enable-tooltips",
+ g_object_bind_property (menu, "enable-tooltips",
item, "has-tooltip",
G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
}
- if (!gp_applet_get_locked_down (menu->applet))
+ if (!menu->locked_down)
{
static const GtkTargetEntry drag_targets[] =
{
@@ -386,22 +385,6 @@ menu_tree_changed_cb (GMenuTree *tree,
queue_reload (menu);
}
-static void
-locked_down_cb (GpApplet *applet,
- GParamSpec *pspec,
- GpMenu *menu)
-{
- queue_reload (menu);
-}
-
-static void
-menu_icon_size_cb (GpApplet *applet,
- GParamSpec *pspec,
- GpMenu *menu)
-{
- queue_reload (menu);
-}
-
static void
gp_menu_constructed (GObject *object)
{
@@ -418,14 +401,6 @@ gp_menu_constructed (GObject *object)
g_signal_connect (menu->tree, "changed",
G_CALLBACK (menu_tree_changed_cb), menu);
- menu->locked_down_id = g_signal_connect (menu->applet, "notify::locked-down",
- G_CALLBACK (locked_down_cb), menu);
-
- menu->menu_icon_size_id = g_signal_connect (menu->applet,
- "notify::menu-icon-size",
- G_CALLBACK (menu_icon_size_cb),
- menu);
-
queue_reload (menu);
}
@@ -444,20 +419,6 @@ gp_menu_dispose (GObject *object)
menu->reload_id = 0;
}
- if (menu->locked_down_id != 0)
- {
- g_signal_handler_disconnect (menu->applet, menu->locked_down_id);
- menu->locked_down_id = 0;
- }
-
- if (menu->menu_icon_size_id != 0)
- {
- g_signal_handler_disconnect (menu->applet, menu->menu_icon_size_id);
- menu->menu_icon_size_id = 0;
- }
-
- menu->applet = NULL;
-
G_OBJECT_CLASS (gp_menu_parent_class)->dispose (object);
}
@@ -486,15 +447,14 @@ gp_menu_get_property (GObject *object,
switch (property_id)
{
case PROP_NAME:
+ case PROP_REQUIRED:
+ case PROP_LOCKED_DOWN:
+ case PROP_MENU_ICON_SIZE:
g_assert_not_reached ();
break;
- case PROP_APPLET:
- g_assert_not_reached ();
- break;
-
- case PROP_REQUIRED:
- g_assert_not_reached ();
+ case PROP_ENABLE_TOOLTIPS:
+ g_value_set_boolean (value, menu->enable_tooltips);
break;
case PROP_EMPTY:
@@ -507,6 +467,41 @@ gp_menu_get_property (GObject *object,
}
}
+static void
+set_enable_tooltips (GpMenu *menu,
+ gboolean enable_tooltips)
+{
+ if (menu->enable_tooltips == enable_tooltips)
+ return;
+
+ menu->enable_tooltips = enable_tooltips;
+
+ g_object_notify_by_pspec (G_OBJECT (menu),
+ menu_properties[PROP_ENABLE_TOOLTIPS]);
+}
+
+static void
+set_locked_down (GpMenu *menu,
+ gboolean locked_down)
+{
+ if (menu->locked_down == locked_down)
+ return;
+
+ menu->locked_down = locked_down;
+ queue_reload (menu);
+}
+
+static void
+set_menu_icon_size (GpMenu *menu,
+ guint menu_icon_size)
+{
+ if (menu->menu_icon_size == menu_icon_size)
+ return;
+
+ menu->menu_icon_size = menu_icon_size;
+ queue_reload (menu);
+}
+
static void
gp_menu_set_property (GObject *object,
guint property_id,
@@ -524,15 +519,22 @@ gp_menu_set_property (GObject *object,
menu->name = g_value_dup_string (value);
break;
- case PROP_APPLET:
- g_assert (menu->applet == NULL);
- menu->applet = g_value_get_object (value);
- break;
-
case PROP_REQUIRED:
menu->required = g_value_get_boolean (value);
break;
+ case PROP_ENABLE_TOOLTIPS:
+ set_enable_tooltips (menu, g_value_get_boolean (value));
+ break;
+
+ case PROP_LOCKED_DOWN:
+ set_locked_down (menu, g_value_get_boolean (value));
+ break;
+
+ case PROP_MENU_ICON_SIZE:
+ set_menu_icon_size (menu, g_value_get_uint (value));
+ break;
+
case PROP_EMPTY:
g_assert_not_reached ();
break;
@@ -552,18 +554,33 @@ install_properties (GObjectClass *object_class)
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
G_PARAM_STATIC_STRINGS);
- menu_properties[PROP_APPLET] =
- g_param_spec_object ("applet", "Applet", "Applet",
- GP_TYPE_APPLET,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
- G_PARAM_STATIC_STRINGS);
-
menu_properties[PROP_REQUIRED] =
g_param_spec_boolean ("required", "Required", "Required",
TRUE,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
G_PARAM_STATIC_STRINGS);
+ menu_properties[PROP_ENABLE_TOOLTIPS] =
+ g_param_spec_boolean ("enable-tooltips", "Enable Tooltips", "Enable Tooltips",
+ TRUE,
+ G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
+ G_PARAM_EXPLICIT_NOTIFY |
+ G_PARAM_STATIC_STRINGS);
+
+ menu_properties[PROP_LOCKED_DOWN] =
+ g_param_spec_boolean ("locked-down", "Locked Down", "Locked Down",
+ FALSE,
+ G_PARAM_CONSTRUCT | G_PARAM_WRITABLE |
+ G_PARAM_EXPLICIT_NOTIFY |
+ G_PARAM_STATIC_STRINGS);
+
+ menu_properties[PROP_MENU_ICON_SIZE] =
+ g_param_spec_uint ("menu-icon-size", "Menu Icon Size", "Menu Icon Size",
+ 16, 24, 16,
+ G_PARAM_CONSTRUCT | G_PARAM_WRITABLE |
+ G_PARAM_EXPLICIT_NOTIFY |
+ G_PARAM_STATIC_STRINGS);
+
menu_properties[PROP_EMPTY] =
g_param_spec_boolean ("empty", "Empty", "Empty",
TRUE,
@@ -604,12 +621,10 @@ gp_menu_init (GpMenu *menu)
}
GtkWidget *
-gp_menu_new (GpApplet *applet,
- const gchar *name,
+gp_menu_new (const gchar *name,
gboolean required)
{
return g_object_new (GP_TYPE_MENU,
- "applet", applet,
"name", name,
"required", required,
NULL);
diff --git a/modules/menu/gp-menu.h b/modules/menu/gp-menu.h
index 5ceea69be..d6b77adbb 100644
--- a/modules/menu/gp-menu.h
+++ b/modules/menu/gp-menu.h
@@ -19,15 +19,13 @@
#define GP_MENU_H
#include "gp-menu-utils.h"
-#include <libgnome-panel/gp-applet.h>
G_BEGIN_DECLS
#define GP_TYPE_MENU (gp_menu_get_type ())
G_DECLARE_FINAL_TYPE (GpMenu, gp_menu, GP, MENU, GtkMenu)
-GtkWidget *gp_menu_new (GpApplet *applet,
- const gchar *name,
+GtkWidget *gp_menu_new (const gchar *name,
gboolean required);
void gp_menu_set_path (GpMenu *menu,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]