[gnome-builder] project-tree: use merge-able menus for context menu
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] project-tree: use merge-able menus for context menu
- Date: Mon, 21 Dec 2015 07:59:40 +0000 (UTC)
commit 0166cbf14ffb5ad1b923a66a20d3aed3f77cb993
Author: Christian Hergert <chergert redhat com>
Date: Fri Dec 4 15:14:19 2015 -0800
project-tree: use merge-able menus for context menu
data/gtk/menus.ui | 112 ------------------------
plugins/project-tree/gb-project-tree-builder.c | 41 +--------
plugins/project-tree/gb-project-tree.c | 4 +
plugins/project-tree/gtk/menus.ui | 98 +++++++++++++++++++++
4 files changed, 106 insertions(+), 149 deletions(-)
---
diff --git a/data/gtk/menus.ui b/data/gtk/menus.ui
index 7a0a84a..edd8e9d 100644
--- a/data/gtk/menus.ui
+++ b/data/gtk/menus.ui
@@ -89,118 +89,6 @@
</section>
-->
</menu>
- <menu id="gb-project-tree-display-options">
- <section id="gb-project-tree-display-options-section">
- <submenu>
- <attribute name="label" translatable="yes">Display Options</attribute>
- <section>
- <item>
- <attribute name="label" translatable="yes">Show Icons</attribute>
- <attribute name="action">project-tree.show-icons</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Show Ignored Files</attribute>
- <attribute name="action">project-tree.show-ignored-files</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Sort Directories First</attribute>
- <attribute name="action">project-tree.sort-directories-first</attribute>
- </item>
- </section>
- <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="gb-project-tree-new">
- <section id="gb-project-tree-new-section">
- <submenu>
- <attribute name="label" translatable="yes">_New</attribute>
- <section>
- <item>
- <attribute name="label" translatable="yes">_Empty File</attribute>
- <attribute name="action">project-tree.new-file</attribute>
- </item>
- </section>
- </submenu>
- </section>
- <section id="gb-project-tree-new-folder-section">
- <item>
- <attribute name="label" translatable="yes">_New Folder</attribute>
- <attribute name="action">project-tree.new-directory</attribute>
- </item>
- </section>
- </menu>
- <menu id="gb-project-tree-open">
- <section id="gb-project-tree-open-section">
- <item>
- <attribute name="label" translatable="yes">_Open</attribute>
- <attribute name="action">project-tree.open</attribute>
- <attribute name="accel">Return</attribute>
- </item>
- <submenu>
- <attribute name="label" translatable="yes">Open _With</attribute>
- <section>
- <item>
- <attribute name="label" translatable="yes">Source Code Editor</attribute>
- <attribute name="action">project-tree.open-with-editor</attribute>
- </item>
- </section>
- <section id="gb-project-tree-open-by-mime-section">
- </section>
- </submenu>
- </section>
- </menu>
- <menu id="gb-project-tree-open-containing">
- <section id="gb-project-tree-open-containing-section">
- <item>
- <attribute name="label" translatable="yes">_Open Containing Folder</attribute>
- <attribute name="action">project-tree.open-containing-folder</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">_Open in Terminal</attribute>
- <attribute name="action">project-tree.open-in-terminal</attribute>
- </item>
- </section>
- </menu>
- <menu id="gb-project-tree-rename">
- <section id="gb-project-tree-rename-section">
- <item>
- <attribute name="label" translatable="yes">_Rename</attribute>
- <attribute name="action">project-tree.rename-file</attribute>
- <attribute name="accel">F2</attribute>
- </item>
- </section>
- </menu>
- <menu id="gb-project-tree-move-to-trash">
- <section id="gb-project-tree-move-to-trash-section">
- <item>
- <attribute name="label" translatable="yes">Mo_ve to Trash</attribute>
- <attribute name="action">project-tree.move-to-trash</attribute>
- <attribute name="accel">Delete</attribute>
- </item>
- </section>
- </menu>
- <menu id="gb-project-tree-build">
- <section id="gb-project-tree-build-section">
- <item>
- <attribute name="label" translatable="yes">_Build</attribute>
- <attribute name="action">workbench.build</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">_Rebuild</attribute>
- <attribute name="action">workbench.rebuild</attribute>
- </item>
- </section>
- </menu>
<menu id="ide-source-view-popup-menu">
<section id="ide-source-view-popup-menu-jump-section">
<item>
diff --git a/plugins/project-tree/gb-project-tree-builder.c b/plugins/project-tree/gb-project-tree-builder.c
index ac4eed0..dab7f99 100644
--- a/plugins/project-tree/gb-project-tree-builder.c
+++ b/plugins/project-tree/gb-project-tree-builder.c
@@ -268,9 +268,7 @@ gb_project_tree_builder_node_popup (IdeTreeBuilder *builder,
IdeTreeNode *node,
GMenu *menu)
{
- GtkApplication *app;
GObject *item;
- GMenu *submenu;
IdeVcs *vcs;
GFile *workdir;
GFile *file;
@@ -279,15 +277,7 @@ gb_project_tree_builder_node_popup (IdeTreeBuilder *builder,
g_assert (IDE_IS_TREE_NODE (node));
g_assert (G_IS_MENU (menu));
- app = GTK_APPLICATION (g_application_get_default ());
item = ide_tree_node_get_item (node);
-
- if (GB_IS_PROJECT_FILE (item))
- {
- submenu = gtk_application_get_menu_by_id (app, "gb-project-tree-build");
- g_menu_prepend_section (menu, NULL, G_MENU_MODEL (submenu));
- }
-
vcs = get_vcs (node);
workdir = ide_vcs_get_working_directory (vcs);
@@ -295,35 +285,12 @@ gb_project_tree_builder_node_popup (IdeTreeBuilder *builder,
(file = gb_project_file_get_file (GB_PROJECT_FILE (item))) &&
!g_file_equal (file, workdir))
{
- submenu = gtk_application_get_menu_by_id (app, "gb-project-tree-move-to-trash");
- g_menu_prepend_section (menu, NULL, G_MENU_MODEL (submenu));
-
- submenu = gtk_application_get_menu_by_id (app, "gb-project-tree-rename");
- g_menu_prepend_section (menu, NULL, G_MENU_MODEL (submenu));
-
- submenu = gtk_application_get_menu_by_id (app, "gb-project-tree-open-containing");
- g_menu_prepend_section (menu, NULL, G_MENU_MODEL (submenu));
-
- submenu = gtk_application_get_menu_by_id (app, "gb-project-tree-open");
- g_menu_prepend_section (menu, NULL, G_MENU_MODEL (submenu));
-
- submenu = gtk_application_get_menu_by_id (app, "gb-project-tree-open-by-mime-section");
- populate_mime_handlers (submenu, GB_PROJECT_FILE (item));
-
- submenu = gtk_application_get_menu_by_id (app, "gb-project-tree-new");
- g_menu_prepend_section (menu, NULL, G_MENU_MODEL (submenu));
- }
- else if (GB_IS_PROJECT_FILE (item))
- {
- submenu = gtk_application_get_menu_by_id (app, "gb-project-tree-open-containing");
- g_menu_prepend_section (menu, NULL, G_MENU_MODEL (submenu));
+ GMenu *mime_section;
- submenu = gtk_application_get_menu_by_id (app, "gb-project-tree-new");
- g_menu_prepend_section (menu, NULL, G_MENU_MODEL (submenu));
+ mime_section = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT,
+ "gb-project-tree-open-by-mime-section");
+ populate_mime_handlers (mime_section, GB_PROJECT_FILE (item));
}
-
- submenu = gtk_application_get_menu_by_id (app, "gb-project-tree-display-options");
- g_menu_append_section (menu, NULL, G_MENU_MODEL (submenu));
}
static gboolean
diff --git a/plugins/project-tree/gb-project-tree.c b/plugins/project-tree/gb-project-tree.c
index aa84e7d..5fd8677 100644
--- a/plugins/project-tree/gb-project-tree.c
+++ b/plugins/project-tree/gb-project-tree.c
@@ -169,6 +169,7 @@ static void
gb_project_tree_init (GbProjectTree *self)
{
IdeTreeBuilder *builder;
+ GMenu *menu;
self->settings = g_settings_new ("org.gnome.builder.project-tree");
@@ -188,6 +189,9 @@ gb_project_tree_init (GbProjectTree *self)
NULL);
gb_project_tree_actions_init (self);
+
+ menu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "gb-project-tree-popup-menu");
+ ide_tree_set_context_menu (IDE_TREE (self), G_MENU_MODEL (menu));
}
gboolean
diff --git a/plugins/project-tree/gtk/menus.ui b/plugins/project-tree/gtk/menus.ui
index a3c240b..6e601ec 100644
--- a/plugins/project-tree/gtk/menus.ui
+++ b/plugins/project-tree/gtk/menus.ui
@@ -8,4 +8,102 @@
</item>
</section>
</menu>
+ <menu id="gb-project-tree-popup-menu">
+ <section id="gb-project-tree-new-section">
+ <submenu id="gb-project-tree-new-section-submenu">
+ <attribute name="label" translatable="yes">_New</attribute>
+ <section id="gb-project-tree-new-empty-file-section">
+ <item>
+ <attribute name="label" translatable="yes">_Empty File</attribute>
+ <attribute name="action">project-tree.new-file</attribute>
+ </item>
+ </section>
+ </submenu>
+ <item>
+ <attribute name="label" translatable="yes">_New Folder</attribute>
+ <attribute name="action">project-tree.new-directory</attribute>
+ </item>
+ </section>
+ <section id="gb-project-tree-open-section">
+ <item>
+ <attribute name="label" translatable="yes">_Open</attribute>
+ <attribute name="action">project-tree.open</attribute>
+ <attribute name="accel">Return</attribute>
+ </item>
+ <submenu id="gb-project-tree-open-with-submenu">
+ <attribute name="label" translatable="yes">Open _With</attribute>
+ <section id="gb-project-tree-open-with-internal-section">
+ <item>
+ <attribute name="label" translatable="yes">Source Code Editor</attribute>
+ <attribute name="action">project-tree.open-with-editor</attribute>
+ </item>
+ </section>
+ <section id="gb-project-tree-open-by-mime-section">
+ </section>
+ </submenu>
+ </section>
+ <section id="gb-project-tree-open-containing-section">
+ <item>
+ <attribute name="label" translatable="yes">_Open Containing Folder</attribute>
+ <attribute name="action">project-tree.open-containing-folder</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Open in Terminal</attribute>
+ <attribute name="action">project-tree.open-in-terminal</attribute>
+ </item>
+ </section>
+ <section id="gb-project-tree-rename-section">
+ <item>
+ <attribute name="label" translatable="yes">_Rename</attribute>
+ <attribute name="action">project-tree.rename-file</attribute>
+ <attribute name="accel">F2</attribute>
+ </item>
+ </section>
+ <section id="gb-project-tree-move-to-trash-section">
+ <item>
+ <attribute name="label" translatable="yes">Mo_ve to Trash</attribute>
+ <attribute name="action">project-tree.move-to-trash</attribute>
+ <attribute name="accel">Delete</attribute>
+ </item>
+ </section>
+ <section id="gb-project-tree-build-section">
+ <item>
+ <attribute name="label" translatable="yes">_Build</attribute>
+ <attribute name="action">workbench.build</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Rebuild</attribute>
+ <attribute name="action">workbench.rebuild</attribute>
+ </item>
+ </section>
+ <section id="gb-project-tree-display-options-section">
+ <submenu id="gb-project-tree-display-options-submenu">
+ <attribute name="label" translatable="yes">Display Options</attribute>
+ <section id="gb-project-tree-display-options-show-section">
+ <item>
+ <attribute name="label" translatable="yes">Show Icons</attribute>
+ <attribute name="action">project-tree.show-icons</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Show Ignored Files</attribute>
+ <attribute name="action">project-tree.show-ignored-files</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Sort Directories First</attribute>
+ <attribute name="action">project-tree.sort-directories-first</attribute>
+ </item>
+ </section>
+ <section id="gb-project-tree-display-options-nodes-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>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]