[gnome-builder] gui: handle more obscure combinations of file/directory



commit 428d8cc8d7e05832f5bf88893db5929e19c87491
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jan 10 13:19:35 2019 -0800

    gui: handle more obscure combinations of file/directory

 src/libide/gui/ide-workbench.c                     | 22 ++++++++++++++++++++--
 .../buildsystem/gbp-buildsystem-workbench-addin.c  |  1 +
 2 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index f1876b1a1..ef5198def 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -1087,6 +1087,7 @@ ide_workbench_load_project_async (IdeWorkbench        *self,
   const gchar *project_id;
   LoadProject *lp;
   GFile *directory;
+  GFile *file;
 
   IDE_ENTRY;
 
@@ -1122,6 +1123,25 @@ ide_workbench_load_project_async (IdeWorkbench        *self,
       ide_context_set_project_id (self->context, generated);
     }
 
+  if (!ide_project_info_get_directory (project_info) &&
+      !ide_project_info_get_file (project_info))
+    {
+      ide_task_return_new_error (task,
+                                 G_IO_ERROR,
+                                 G_IO_ERROR_NOT_FOUND,
+                                 "No file or directory provided to load as project");
+      IDE_EXIT;
+    }
+
+  /* Fallback to using directory as file if necessary */
+  if (!(file = ide_project_info_get_file (project_info)))
+    {
+      file = ide_project_info_get_directory (project_info);
+      g_assert (G_IS_FILE (file));
+
+      ide_project_info_set_file (project_info, file);
+    }
+
   /*
    * Track the directory root based on project info. If we didn't get a
    * directory set, then take the parent of the project file.
@@ -1133,8 +1153,6 @@ ide_workbench_load_project_async (IdeWorkbench        *self,
     }
   else
     {
-      GFile *file = ide_project_info_get_file (project_info);
-
       if (g_file_query_file_type (file, G_FILE_COPY_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_DIRECTORY)
         {
           ide_context_set_workdir (self->context, file);
diff --git a/src/plugins/buildsystem/gbp-buildsystem-workbench-addin.c 
b/src/plugins/buildsystem/gbp-buildsystem-workbench-addin.c
index 14f25b949..e57fdda39 100644
--- a/src/plugins/buildsystem/gbp-buildsystem-workbench-addin.c
+++ b/src/plugins/buildsystem/gbp-buildsystem-workbench-addin.c
@@ -238,6 +238,7 @@ gbp_buildsystem_workbench_addin_load_project_async (IdeWorkbenchAddin   *addin,
   ide_task_set_task_data (task, g_object_ref (project_info), g_object_unref);
 
   directory = ide_project_info_get_directory (project_info);
+  g_assert (G_IS_FILE (directory));
 
   discover_async (self,
                   directory,


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