[gnome-panel] menu: add gp_menu_set_path



commit 143b2a499d24330cb06d09d0ce2d2fae4df7f1ea
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Sep 12 01:29:46 2018 +0300

    menu: add gp_menu_set_path

 modules/menu/gp-menu.c | 23 ++++++++++++++++++++++-
 modules/menu/gp-menu.h |  3 +++
 2 files changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/modules/menu/gp-menu.c b/modules/menu/gp-menu.c
index ecb63719a..89ef0172f 100644
--- a/modules/menu/gp-menu.c
+++ b/modules/menu/gp-menu.c
@@ -43,6 +43,8 @@ struct _GpMenu
 
   gulong                 locked_down_id;
   gulong                 menu_icon_size_id;
+
+  gchar                 *path;
 };
 
 enum
@@ -309,9 +311,18 @@ menu_reload (GpMenu *menu)
 
   if (loaded)
     {
+      const gchar *path;
       GMenuTreeDirectory *directory;
 
-      directory = gmenu_tree_get_directory_from_path (menu->tree, "/");
+      path = menu->path && *menu->path != '\0' ? menu->path : "/";
+      directory = gmenu_tree_get_directory_from_path (menu->tree, path);
+
+      if (directory == NULL)
+        {
+          g_warning ("Menu path '%s' does not exist!", path);
+          directory = gmenu_tree_get_directory_from_path (menu->tree, "/");
+        }
+
       directory_to_menu_items (directory, GTK_WIDGET (menu), menu);
       gmenu_tree_item_unref (directory);
 
@@ -584,6 +595,16 @@ gp_menu_new (GpApplet    *applet,
                        NULL);
 }
 
+void
+gp_menu_set_path (GpMenu      *menu,
+                  const gchar *path)
+{
+  g_free (menu->path);
+  menu->path = g_strdup (path);
+
+  queue_reload (menu);
+}
+
 void
 gp_menu_set_append_func (GpMenu                *menu,
                          GpAppendMenuItemsFunc  append_func,
diff --git a/modules/menu/gp-menu.h b/modules/menu/gp-menu.h
index 01b2de60d..0b8511bd4 100644
--- a/modules/menu/gp-menu.h
+++ b/modules/menu/gp-menu.h
@@ -30,6 +30,9 @@ GtkWidget *gp_menu_new             (GpApplet              *applet,
                                     const gchar           *name,
                                     gboolean               required);
 
+void       gp_menu_set_path        (GpMenu                *menu,
+                                    const gchar           *path);
+
 void       gp_menu_set_append_func (GpMenu                *menu,
                                     GpAppendMenuItemsFunc  append_func,
                                     gpointer               user_data);


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