[gnome-builder] project-tree: add project-tree to editor workspaces



commit 42228fa829eaada5740df8b17310acf19d3df95a
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 20 00:06:52 2019 -0800

    project-tree: add project-tree to editor workspaces
    
    This allows use of the project-tree from editor workspace windows. However,
    it does not include project-related items unless a project is loaded in the
    IdeContext.
    
    The workdir is used, which is the top-level directory found when opening
    files from the command-line (or the project workdir in the case a project
    was opened).

 src/plugins/buildui/gbp-buildui-tree-addin.c       | 21 +++++++++++++++++
 src/plugins/project-tree/gbp-project-tree-addin.c  | 10 ---------
 .../gbp-project-tree-workspace-addin.c             |  6 +++--
 src/plugins/project-tree/project-tree.plugin       |  2 +-
 src/plugins/testui/gbp-test-tree-addin.c           | 26 +++++++++++++++++-----
 5 files changed, 46 insertions(+), 19 deletions(-)
---
diff --git a/src/plugins/buildui/gbp-buildui-tree-addin.c b/src/plugins/buildui/gbp-buildui-tree-addin.c
index 579d80729..3eb533999 100644
--- a/src/plugins/buildui/gbp-buildui-tree-addin.c
+++ b/src/plugins/buildui/gbp-buildui-tree-addin.c
@@ -134,6 +134,7 @@ gbp_buildui_tree_addin_build_children_async (IdeTreeAddin        *addin,
 {
   GbpBuilduiTreeAddin *self = (GbpBuilduiTreeAddin *)addin;
   g_autoptr(IdeTask) task = NULL;
+  IdeContext *context;
 
   g_assert (IDE_IS_MAIN_THREAD ());
   g_assert (IDE_IS_TREE_ADDIN (self));
@@ -143,6 +144,14 @@ gbp_buildui_tree_addin_build_children_async (IdeTreeAddin        *addin,
   task = ide_task_new (self, cancellable, callback, user_data);
   ide_task_set_source_tag (task, gbp_buildui_tree_addin_build_children_async);
 
+  context = ide_object_get_context (IDE_OBJECT (self->model));
+
+  if (!ide_context_has_project (context))
+    {
+      ide_task_return_boolean (task, TRUE);
+      return;
+    }
+
   if (ide_tree_node_holds (node, IDE_TYPE_CONTEXT))
     {
       g_autoptr(IdeTreeNode) targets = NULL;
@@ -296,6 +305,7 @@ gbp_buildui_tree_addin_load (IdeTreeAddin *addin,
 {
   GbpBuilduiTreeAddin *self = (GbpBuilduiTreeAddin *)addin;
   g_autoptr(GSimpleActionGroup) group = NULL;
+  IdeContext *context;
   static const GActionEntry actions[] = {
     { "build", gbp_buildui_tree_addin_action_build },
     { "rebuild", gbp_buildui_tree_addin_action_rebuild },
@@ -310,6 +320,11 @@ gbp_buildui_tree_addin_load (IdeTreeAddin *addin,
   self->model = model;
   self->tree = tree;
 
+  context = ide_object_get_context (IDE_OBJECT (self->model));
+
+  if (!ide_context_has_project (context))
+    return;
+
   group = g_simple_action_group_new ();
   g_action_map_add_action_entries (G_ACTION_MAP (group),
                                    actions,
@@ -342,11 +357,17 @@ gbp_buildui_tree_addin_selection_changed (IdeTreeAddin *addin,
 {
   GbpBuilduiTreeAddin *self = (GbpBuilduiTreeAddin *)addin;
   IdeBuildTarget *target;
+  IdeContext *context;
 
   g_assert (IDE_IS_MAIN_THREAD ());
   g_assert (GBP_IS_BUILDUI_TREE_ADDIN (self));
   g_assert (!node || IDE_IS_TREE_NODE (node));
 
+  context = ide_object_get_context (IDE_OBJECT (self->model));
+
+  if (!ide_context_has_project (context))
+    return;
+
   dzl_gtk_widget_action_set (GTK_WIDGET (self->tree), "buildui", "build",
                              "enabled", node && ide_tree_node_holds (node, IDE_TYPE_BUILD_TARGET),
                              NULL);
diff --git a/src/plugins/project-tree/gbp-project-tree-addin.c 
b/src/plugins/project-tree/gbp-project-tree-addin.c
index 809879189..fe9da3642 100644
--- a/src/plugins/project-tree/gbp-project-tree-addin.c
+++ b/src/plugins/project-tree/gbp-project-tree-addin.c
@@ -189,22 +189,12 @@ gbp_project_tree_addin_build_children_async (IdeTreeAddin        *addin,
       IdeContext *context = ide_tree_node_get_item (node);
       g_autoptr(IdeTreeNode) files = NULL;
       g_autoptr(IdeTreeNode) targets = NULL;
-      //g_autoptr(IdeTreeNode) tests = NULL;
       g_autoptr(IdeProjectFile) root_file = NULL;
       g_autoptr(GFile) workdir = ide_context_ref_workdir (context);
       g_autoptr(GFile) parent = g_file_get_parent (workdir);
       g_autoptr(GFileInfo) info = NULL;
       g_autofree gchar *name = NULL;
 
-#if 0
-      tests = g_object_new (IDE_TYPE_TREE_NODE,
-                            "icon-name", "builder-unit-tests-symbolic",
-                            "item", NULL,
-                            "display-name", _("Unit Tests"),
-                            "children-possible", TRUE,
-                            NULL);
-      ide_tree_node_append (node, tests);
-#endif
 
       info = g_file_info_new ();
       name = g_file_get_basename (workdir);
diff --git a/src/plugins/project-tree/gbp-project-tree-workspace-addin.c 
b/src/plugins/project-tree/gbp-project-tree-workspace-addin.c
index 394bf326a..3aecea2bf 100644
--- a/src/plugins/project-tree/gbp-project-tree-workspace-addin.c
+++ b/src/plugins/project-tree/gbp-project-tree-workspace-addin.c
@@ -44,7 +44,8 @@ gbp_project_tree_workspace_addin_load (IdeWorkspaceAddin *addin,
   IdeSurface *surface;
 
   g_assert (GBP_IS_PROJECT_TREE_WORKSPACE_ADDIN (self));
-  g_assert (IDE_IS_PRIMARY_WORKSPACE (workspace));
+  g_assert (IDE_IS_PRIMARY_WORKSPACE (workspace) ||
+            IDE_IS_EDITOR_WORKSPACE (workspace));
 
   surface = ide_workspace_get_surface_by_name (workspace, "editor");
   g_assert (IDE_IS_EDITOR_SURFACE (surface));
@@ -75,7 +76,8 @@ gbp_project_tree_workspace_addin_unload (IdeWorkspaceAddin *addin,
   GbpProjectTreeWorkspaceAddin *self = (GbpProjectTreeWorkspaceAddin *)addin;
 
   g_assert (GBP_IS_PROJECT_TREE_WORKSPACE_ADDIN (self));
-  g_assert (IDE_IS_PRIMARY_WORKSPACE (workspace));
+  g_assert (IDE_IS_PRIMARY_WORKSPACE (workspace) ||
+            IDE_IS_EDITOR_WORKSPACE (workspace));
 
   if (self->pane != NULL)
     gtk_widget_destroy (GTK_WIDGET (self->pane));
diff --git a/src/plugins/project-tree/project-tree.plugin b/src/plugins/project-tree/project-tree.plugin
index 8e7566092..f17aa52a7 100644
--- a/src/plugins/project-tree/project-tree.plugin
+++ b/src/plugins/project-tree/project-tree.plugin
@@ -8,5 +8,5 @@ Embedded=_gbp_project_tree_register_types
 Hidden=true
 Module=project-tree
 Name=Project Tree
-X-Workspace-Kind=primary;
+X-Workspace-Kind=primary;editor;
 X-Tree-Kind=project-tree;
diff --git a/src/plugins/testui/gbp-test-tree-addin.c b/src/plugins/testui/gbp-test-tree-addin.c
index f6a541566..f21f3f760 100644
--- a/src/plugins/testui/gbp-test-tree-addin.c
+++ b/src/plugins/testui/gbp-test-tree-addin.c
@@ -127,6 +127,7 @@ gbp_test_tree_addin_build_children_async (IdeTreeAddin        *addin,
 {
   GbpTestTreeAddin *self = (GbpTestTreeAddin *)addin;
   g_autoptr(IdeTask) task = NULL;
+  IdeContext *context;
 
   g_assert (IDE_IS_MAIN_THREAD ());
   g_assert (GBP_IS_TEST_TREE_ADDIN (self));
@@ -137,14 +138,20 @@ gbp_test_tree_addin_build_children_async (IdeTreeAddin        *addin,
   ide_task_set_source_tag (task, gbp_test_tree_addin_build_children_async);
   ide_task_set_task_data (task, g_object_ref (node), g_object_unref);
 
+  context = ide_object_get_context (IDE_OBJECT (self->model));
+
+  if (!ide_context_has_project (context))
+    {
+      ide_task_return_boolean (task, TRUE);
+      return;
+    }
+
   if (ide_tree_node_holds (node, IDE_TYPE_CONTEXT))
     {
       g_autoptr(IdeTreeNode) child = NULL;
       g_autoptr(GbpTestPath) path = NULL;
       IdeTestManager *test_manager;
-      IdeContext *context;
 
-      context = ide_tree_node_get_item (node);
       test_manager = ide_test_manager_from_context (context);
       path = gbp_test_path_new (test_manager, NULL);
 
@@ -157,7 +164,6 @@ gbp_test_tree_addin_build_children_async (IdeTreeAddin        *addin,
     }
   else if (ide_tree_node_holds (node, GBP_TYPE_TEST_PATH))
     {
-      IdeContext *context = ide_widget_get_context (GTK_WIDGET (self->tree));
       IdeTestManager *test_manager = ide_test_manager_from_context (context);
 
       ide_test_manager_ensure_loaded_async (test_manager,
@@ -246,6 +252,10 @@ gbp_test_tree_addin_load (IdeTreeAddin *addin,
   self->model = model;
 
   context = ide_object_get_context (IDE_OBJECT (model));
+
+  if (!ide_context_has_project (context))
+    return;
+
   test_manager = ide_test_manager_from_context (context);
 
   g_signal_connect_object (test_manager,
@@ -269,14 +279,18 @@ gbp_test_tree_addin_unload (IdeTreeAddin *addin,
   g_assert (IDE_IS_TREE (tree));
   g_assert (IDE_IS_TREE_MODEL (model));
 
+  self->tree = NULL;
+  self->model = NULL;
+
   context = ide_object_get_context (IDE_OBJECT (model));
+
+  if (!ide_context_has_project (context))
+    return;
+
   test_manager = ide_test_manager_from_context (context);
   g_signal_handlers_disconnect_by_func (test_manager,
                                         G_CALLBACK (gbp_test_tree_addin_notify_loading),
                                         self);
-
-  self->tree = NULL;
-  self->model = NULL;
 }
 
 static void


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