[gnome-builder] tree: only add open items for IdeProjectFile items



commit 05a4c24710f50a4599e0a8a408a3a3f671c773ce
Author: Christian Hergert <christian hergert me>
Date:   Sun Apr 5 21:14:23 2015 -0700

    tree: only add open items for IdeProjectFile items

 data/gtk/menus.ui                  |   36 ++++++++++++++++++++----------------
 src/tree/gb-project-tree-builder.c |   30 ++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 16 deletions(-)
---
diff --git a/data/gtk/menus.ui b/data/gtk/menus.ui
index 27dc579..90567b6 100644
--- a/data/gtk/menus.ui
+++ b/data/gtk/menus.ui
@@ -109,7 +109,24 @@
     </section>
 -->
   </menu>
-  <menu id="project-tree-menu">
+  <menu id="gb-tree-display-options">
+    <section id="display-options">
+      <submenu>
+        <attribute name="label" translatable="yes">Display Options</attribute>
+        <section>
+          <item>
+            <attribute name="label" translatable="yes">_Collapse All Nodes</attribute>
+            <attribute name="action">project-tree.collapse-all-nodes</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">_Refresh</attribute>
+            <attribute name="action">project-tree.refresh</attribute>
+          </item>
+        </section>
+      </submenu>
+    </section>
+  </menu>
+  <menu id="project-tree-open">
     <section id="open-section">
       <item>
         <attribute name="label" translatable="yes">_Open</attribute>
@@ -127,26 +144,13 @@
         </section>
       </submenu>
     </section>
+  </menu>
+  <menu id="project-tree-open-containing">
     <section id="open-containing-section">
       <item>
         <attribute name="label" translatable="yes">_Open Containing Folder</attribute>
         <attribute name="action">project-tree.open-containing-folder</attribute>
       </item>
     </section>
-    <section id="display-options">
-      <submenu>
-        <attribute name="label" translatable="yes">Display Options</attribute>
-        <section>
-          <item>
-            <attribute name="label" translatable="yes">_Collapse All Nodes</attribute>
-            <attribute name="action">project-tree.collapse-all-nodes</attribute>
-          </item>
-          <item>
-            <attribute name="label" translatable="yes">_Refresh</attribute>
-            <attribute name="action">project-tree.refresh</attribute>
-          </item>
-        </section>
-      </submenu>
-    </section>
   </menu>
 </interface>
diff --git a/src/tree/gb-project-tree-builder.c b/src/tree/gb-project-tree-builder.c
index f5ec654..59fb8a3 100644
--- a/src/tree/gb-project-tree-builder.c
+++ b/src/tree/gb-project-tree-builder.c
@@ -283,6 +283,35 @@ gb_project_tree_builder_build_node (GbTreeBuilder *builder,
     build_files (self, node);
 }
 
+static void
+gb_project_tree_builder_node_popup (GbTreeBuilder *builder,
+                                    GbTreeNode    *node,
+                                    GMenu         *menu)
+{
+  GbProjectTreeBuilder *self = (GbProjectTreeBuilder *)builder;
+  GObject *item;
+
+  g_assert (GB_IS_PROJECT_TREE_BUILDER (self));
+  g_assert (GB_IS_TREE_NODE (node));
+  g_assert (G_IS_MENU (menu));
+
+  item = gb_tree_node_get_item (node);
+
+  if (IDE_IS_PROJECT_FILE (item))
+    {
+      GtkApplication *app;
+      GMenu *submenu;
+
+      app = GTK_APPLICATION (g_application_get_default ());
+
+      submenu = gtk_application_get_menu_by_id (app, "project-tree-open-containing");
+      g_menu_prepend_section (menu, NULL, G_MENU_MODEL (submenu));
+
+      submenu = gtk_application_get_menu_by_id (app, "project-tree-open");
+      g_menu_prepend_section (menu, NULL, G_MENU_MODEL (submenu));
+    }
+}
+
 static gboolean
 gb_project_tree_builder_node_activated (GbTreeBuilder *builder,
                                         GbTreeNode    *node)
@@ -387,6 +416,7 @@ gb_project_tree_builder_class_init (GbProjectTreeBuilderClass *klass)
 
   tree_builder_class->build_node = gb_project_tree_builder_build_node;
   tree_builder_class->node_activated = gb_project_tree_builder_node_activated;
+  tree_builder_class->node_popup = gb_project_tree_builder_node_popup;
 
   gParamSpecs [PROP_CONTEXT] =
     g_param_spec_object ("context",


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