[gnome-panel] menu: add hidden System menu item



commit 716791b9e85127fd2da3972750922829e07d194f
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Feb 4 22:46:56 2018 +0200

    menu: add hidden System menu item
    
    It will be visible only if ${XDG_MENU_PREFIX}settings.menu is
    installed / available.

 modules/menu/gp-menu-bar-applet.c |   48 +++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/modules/menu/gp-menu-bar-applet.c b/modules/menu/gp-menu-bar-applet.c
index 3d29312..ca7ece0 100644
--- a/modules/menu/gp-menu-bar-applet.c
+++ b/modules/menu/gp-menu-bar-applet.c
@@ -40,6 +40,9 @@ struct _GpMenuBarApplet
 
   GtkWidget *places_item;
   GtkWidget *places_menu;
+
+  GtkWidget *system_item;
+  GtkWidget *system_menu;
 };
 
 static void gp_action_interface_init (GpActionInterface *iface);
@@ -87,6 +90,18 @@ get_applications_menu (void)
   return g_strdup_printf ("%sapplications.menu", xdg_menu_prefx);
 }
 
+static gchar *
+get_settings_menu (void)
+{
+  const gchar *xdg_menu_prefx;
+
+  xdg_menu_prefx = g_getenv ("XDG_MENU_PREFIX");
+  if (!xdg_menu_prefx || *xdg_menu_prefx == '\0')
+    return NULL;
+
+  return g_strdup_printf ("%ssettings.menu", xdg_menu_prefx);
+}
+
 static void
 panel_icon_size_cb (GpApplet   *applet,
                     GParamSpec *pspec,
@@ -154,6 +169,38 @@ append_places_item (GpMenuBarApplet *applet)
 }
 
 static void
+append_system_item (GpMenuBarApplet *applet)
+{
+  gchar *menu;
+  const gchar *tooltip;
+
+  menu = get_settings_menu ();
+  if (menu == NULL)
+    return;
+
+  applet->system_item = gtk_menu_item_new_with_label (_("System"));
+  gtk_menu_shell_append (GTK_MENU_SHELL (applet->menu_bar), applet->system_item);
+  gtk_widget_show (applet->system_item);
+
+  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);
+  g_free (menu);
+
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (applet->system_item),
+                             applet->system_menu);
+
+  g_object_bind_property (applet->system_menu, "empty",
+                          applet->system_item, "visible",
+                          G_BINDING_DEFAULT | G_BINDING_INVERT_BOOLEAN |
+                          G_BINDING_SYNC_CREATE);
+
+  g_signal_connect (applet->system_menu, "button-press-event",
+                    G_CALLBACK (button_press_event_cb), NULL);
+}
+
+static void
 edit_menus_cb (GSimpleAction *action,
                GVariant      *parameter,
                gpointer       user_data)
@@ -224,6 +271,7 @@ gp_menu_bar_applet_setup (GpMenuBarApplet *menu_bar)
 
   append_applications_item (menu_bar);
   append_places_item (menu_bar);
+  append_system_item (menu_bar);
 
   setup_menu (menu_bar);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]