[gnome-builder] project-tree: add open-with-hint action



commit 962399e649f94c0adafefcc7abe63f495cabdb82
Author: Christian Hergert <chergert redhat com>
Date:   Sat Oct 20 07:28:02 2018 -0700

    project-tree: add open-with-hint action
    
    This allows specifying a workbench-addin that can open the file by
    providing the hint matching the addins identifier.

 src/plugins/project-tree/gb-project-tree-actions.c | 31 +++++++++++++++++-----
 src/plugins/project-tree/gtk/menus.ui              |  4 ++-
 2 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/src/plugins/project-tree/gb-project-tree-actions.c 
b/src/plugins/project-tree/gb-project-tree-actions.c
index 0c9c21a7e..866de9053 100644
--- a/src/plugins/project-tree/gb-project-tree-actions.c
+++ b/src/plugins/project-tree/gb-project-tree-actions.c
@@ -199,18 +199,22 @@ gb_project_tree_actions_open_with (GSimpleAction *action,
 }
 
 static void
-gb_project_tree_actions_open_with_editor (GSimpleAction *action,
-                                          GVariant      *variant,
-                                          gpointer       user_data)
+gb_project_tree_actions_open_with_hint (GSimpleAction *action,
+                                        GVariant      *variant,
+                                        gpointer       user_data)
 {
   IdeWorkbench *workbench;
   GbProjectTree *self = user_data;
-  GFileInfo *file_info;
-  GFile *file;
   DzlTreeNode *selected;
+  GFileInfo *file_info;
   GObject *item;
+  GFile *file;
+  const gchar *hint;
 
+  g_assert (G_IS_SIMPLE_ACTION (action));
   g_assert (GB_IS_PROJECT_TREE (self));
+  g_assert (variant != NULL);
+  g_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING));
 
   if (!(selected = dzl_tree_get_selected (DZL_TREE (self))) ||
       !(item = dzl_tree_node_get_item (selected)) ||
@@ -221,7 +225,17 @@ gb_project_tree_actions_open_with_editor (GSimpleAction *action,
       !(workbench = ide_widget_get_workbench (GTK_WIDGET (self))))
     return;
 
-  ide_workbench_open_files_async (workbench, &file, 1, "editor", IDE_WORKBENCH_OPEN_FLAGS_NONE, NULL, NULL, 
NULL);
+  hint = g_variant_get_string (variant, NULL);
+  ide_workbench_open_files_async (workbench, &file, 1, hint, IDE_WORKBENCH_OPEN_FLAGS_NONE, NULL, NULL, 
NULL);
+}
+
+static void
+gb_project_tree_actions_open_with_editor (GSimpleAction *action,
+                                          GVariant      *variant,
+                                          gpointer       user_data)
+{
+  g_autoptr(GVariant) param = g_variant_take_ref (g_variant_new_string ("editor"));
+  gb_project_tree_actions_open_with_hint (action, param, user_data);
 }
 
 static void
@@ -831,6 +845,7 @@ static GActionEntry GbProjectTreeActions[] = {
   { "open-in-terminal",       gb_project_tree_actions_open_in_terminal },
   { "open-with",              gb_project_tree_actions_open_with, "s" },
   { "open-with-editor",       gb_project_tree_actions_open_with_editor },
+  { "open-with-hint",         gb_project_tree_actions_open_with_hint, "s" },
   { "refresh",                gb_project_tree_actions_refresh },
   { "rename-file",            gb_project_tree_actions_rename_file },
 };
@@ -907,6 +922,10 @@ gb_project_tree_actions_update (GbProjectTree *self)
   action_set (group, "open-with-editor",
               "enabled", (GB_IS_PROJECT_FILE (item) && !project_file_is_directory (item)),
               NULL);
+  /* TODO: use the hint to determine visibility */
+  action_set (group, "open-with-hint",
+              "enabled", (GB_IS_PROJECT_FILE (item) && !project_file_is_directory (item)),
+              NULL);
   action_set (group, "open-containing-folder",
               "enabled", GB_IS_PROJECT_FILE (item),
               NULL);
diff --git a/src/plugins/project-tree/gtk/menus.ui b/src/plugins/project-tree/gtk/menus.ui
index 325f7065d..ae30ee1c0 100644
--- a/src/plugins/project-tree/gtk/menus.ui
+++ b/src/plugins/project-tree/gtk/menus.ui
@@ -29,8 +29,10 @@
         <attribute name="label" translatable="yes">Open _With</attribute>
         <section id="gb-project-tree-open-with-internal-section">
           <item>
+            <attribute name="id">gb-project-tree-open-with-editor</attribute>
             <attribute name="label" translatable="yes">Source Code Editor</attribute>
-            <attribute name="action">project-tree.open-with-editor</attribute>
+            <attribute name="action">project-tree.open-with-hint</attribute>
+            <attribute name="target" type="s">"editor"</attribute>
           </item>
         </section>
         <section id="gb-project-tree-open-by-mime-section">


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