[gnome-builder] projects: propagate build-system-hint when opening from dialog



commit d80a7bededadc82e27b06eae4e1303f7d95d037d
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jan 14 10:41:28 2019 -0800

    projects: propagate build-system-hint when opening from dialog
    
    If we know the build system to use up-front, such as from the file-chooser
    dialog with filter set, then we can avoid having that overridden by build
    system discovery.
    
    This also adds that hint to the persistent recent-info so that any future
    opening of the project re-selects the same build system plugin.
    
    Fixes #753

 src/libide/greeter/ide-greeter-workspace-actions.c | 13 +++++++
 src/libide/projects/ide-project-info.c             | 40 ++++++++++++++++++++++
 src/libide/projects/ide-project-info.h             |  5 +++
 src/libide/projects/ide-recent-projects.c          |  4 +++
 src/libide/projects/ide-recent-projects.h          | 11 +++---
 .../buildsystem/gbp-buildsystem-workbench-addin.c  | 16 +++++++++
 6 files changed, 84 insertions(+), 5 deletions(-)
---
diff --git a/src/libide/greeter/ide-greeter-workspace-actions.c 
b/src/libide/greeter/ide-greeter-workspace-actions.c
index 344a8ca10..cb4881f34 100644
--- a/src/libide/greeter/ide-greeter-workspace-actions.c
+++ b/src/libide/greeter/ide-greeter-workspace-actions.c
@@ -40,12 +40,21 @@ ide_greeter_workspace_dialog_response (IdeGreeterWorkspace  *self,
     {
       g_autoptr(IdeProjectInfo) project_info = NULL;
       g_autoptr(GFile) project_file = NULL;
+      GtkFileFilter *filter;
 
       project_file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
 
       project_info = ide_project_info_new ();
       ide_project_info_set_file (project_info, project_file);
 
+      if ((filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog))))
+        {
+          const gchar *module_name = g_object_get_data (G_OBJECT (filter), "MODULE_NAME");
+
+          if (module_name != NULL)
+            ide_project_info_set_build_system_hint (project_info, module_name);
+        }
+
       ide_greeter_workspace_open_project (self, project_info);
     }
 
@@ -150,6 +159,10 @@ ide_greeter_workspace_actions_open (GSimpleAction *action,
       filter = gtk_file_filter_new ();
 
       gtk_file_filter_set_name (filter, name);
+      g_object_set_data_full (G_OBJECT (filter),
+                              "MODULE_NAME",
+                              g_strdup (peas_plugin_info_get_module_name (plugin_info)),
+                              g_free);
 
       for (i = 0; patterns [i] != NULL; i++)
         {
diff --git a/src/libide/projects/ide-project-info.c b/src/libide/projects/ide-project-info.c
index 290e2b64b..57b52ea38 100644
--- a/src/libide/projects/ide-project-info.c
+++ b/src/libide/projects/ide-project-info.c
@@ -52,6 +52,7 @@ struct _IdeProjectInfo
   GFile      *directory;
   GFile      *file;
   gchar      *build_system_name;
+  gchar      *build_system_hint;
   gchar      *name;
   gchar      *description;
   gchar     **languages;
@@ -66,6 +67,7 @@ G_DEFINE_TYPE (IdeProjectInfo, ide_project_info, G_TYPE_OBJECT)
 
 enum {
   PROP_0,
+  PROP_BUILD_SYSTEM_HINT,
   PROP_BUILD_SYSTEM_NAME,
   PROP_DESCRIPTION,
   PROP_DIRECTORY,
@@ -211,6 +213,28 @@ ide_project_info_get_last_modified_at (IdeProjectInfo *self)
   return self->last_modified_at;
 }
 
+const gchar *
+ide_project_info_get_build_system_hint (IdeProjectInfo *self)
+{
+  g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL);
+
+  return self->build_system_hint;
+}
+
+void
+ide_project_info_set_build_system_hint (IdeProjectInfo *self,
+                                        const gchar    *build_system_hint)
+{
+  g_return_if_fail (IDE_IS_PROJECT_INFO (self));
+
+  if (!ide_str_equal0 (self->build_system_hint, build_system_hint))
+    {
+      g_free (self->build_system_hint);
+      self->build_system_hint = g_strdup (build_system_hint);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUILD_SYSTEM_HINT]);
+    }
+}
+
 const gchar *
 ide_project_info_get_build_system_name (IdeProjectInfo *self)
 {
@@ -343,6 +367,7 @@ ide_project_info_finalize (GObject *object)
 
   g_clear_pointer (&self->id, g_free);
   g_clear_pointer (&self->last_modified_at, g_date_time_unref);
+  g_clear_pointer (&self->build_system_hint, g_free);
   g_clear_pointer (&self->build_system_name, g_free);
   g_clear_pointer (&self->description, g_free);
   g_clear_pointer (&self->languages, g_strfreev);
@@ -363,6 +388,10 @@ ide_project_info_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_BUILD_SYSTEM_HINT:
+      g_value_set_string (value, ide_project_info_get_build_system_hint (self));
+      break;
+
     case PROP_BUILD_SYSTEM_NAME:
       g_value_set_string (value, ide_project_info_get_build_system_name (self));
       break;
@@ -426,6 +455,10 @@ ide_project_info_set_property (GObject      *object,
 
   switch (prop_id)
     {
+    case PROP_BUILD_SYSTEM_HINT:
+      ide_project_info_set_build_system_hint (self, g_value_get_string (value));
+      break;
+
     case PROP_BUILD_SYSTEM_NAME:
       ide_project_info_set_build_system_name (self, g_value_get_string (value));
       break;
@@ -488,6 +521,13 @@ ide_project_info_class_init (IdeProjectInfoClass *klass)
   object_class->get_property = ide_project_info_get_property;
   object_class->set_property = ide_project_info_set_property;
 
+  properties [PROP_BUILD_SYSTEM_HINT] =
+    g_param_spec_string ("build-system-hint",
+                         "Build System hint",
+                         "Build System hint",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_BUILD_SYSTEM_NAME] =
     g_param_spec_string ("build-system-name",
                          "Build System name",
diff --git a/src/libide/projects/ide-project-info.h b/src/libide/projects/ide-project-info.h
index b47307b19..cd897dc9b 100644
--- a/src/libide/projects/ide-project-info.h
+++ b/src/libide/projects/ide-project-info.h
@@ -57,6 +57,8 @@ IDE_AVAILABLE_IN_3_32
 void                 ide_project_info_set_doap              (IdeProjectInfo  *self,
                                                              IdeDoap         *doap);
 IDE_AVAILABLE_IN_3_32
+const gchar         *ide_project_info_get_build_system_hint (IdeProjectInfo  *self);
+IDE_AVAILABLE_IN_3_32
 const gchar         *ide_project_info_get_build_system_name (IdeProjectInfo  *self);
 IDE_AVAILABLE_IN_3_32
 const gchar         *ide_project_info_get_description       (IdeProjectInfo  *self);
@@ -81,6 +83,9 @@ IDE_AVAILABLE_IN_3_32
 void                 ide_project_info_set_file              (IdeProjectInfo  *self,
                                                              GFile           *file);
 IDE_AVAILABLE_IN_3_32
+void                 ide_project_info_set_build_system_hint (IdeProjectInfo  *self,
+                                                             const gchar     *build_system_hint);
+IDE_AVAILABLE_IN_3_32
 void                 ide_project_info_set_build_system_name (IdeProjectInfo  *self,
                                                              const gchar     *build_system_name);
 IDE_AVAILABLE_IN_3_32
diff --git a/src/libide/projects/ide-recent-projects.c b/src/libide/projects/ide-recent-projects.c
index 53ccbfca5..9d880bda2 100644
--- a/src/libide/projects/ide-recent-projects.c
+++ b/src/libide/projects/ide-recent-projects.c
@@ -155,6 +155,7 @@ ide_recent_projects_load_recent (IdeRecentProjects *self)
       g_autoptr(IdeProjectInfo) project_info = NULL;
       g_autofree gchar *name = NULL;
       g_autofree gchar *description = NULL;
+      const gchar *build_system_hint = NULL;
       const gchar *build_system_name = NULL;
       const gchar *uri = uris[z];
       const gchar *diruri = NULL;
@@ -205,10 +206,13 @@ ide_recent_projects_load_recent (IdeRecentProjects *self)
             g_ptr_array_add (languages, groups [i] + strlen (IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX));
           else if (g_str_has_prefix (groups [i], IDE_RECENT_PROJECTS_BUILD_SYSTEM_GROUP_PREFIX))
             build_system_name = groups [i] + strlen (IDE_RECENT_PROJECTS_BUILD_SYSTEM_GROUP_PREFIX);
+          else if (g_str_has_prefix (groups [i], IDE_RECENT_PROJECTS_BUILD_SYSTEM_HINT_GROUP_PREFIX))
+            build_system_hint = groups [i] + strlen (IDE_RECENT_PROJECTS_BUILD_SYSTEM_HINT_GROUP_PREFIX);
         }
       g_ptr_array_add (languages, NULL);
 
       project_info = g_object_new (IDE_TYPE_PROJECT_INFO,
+                                   "build-system-hint", build_system_hint,
                                    "build-system-name", build_system_name,
                                    "description", description,
                                    "directory", directory,
diff --git a/src/libide/projects/ide-recent-projects.h b/src/libide/projects/ide-recent-projects.h
index d5f4c2435..2da66266d 100644
--- a/src/libide/projects/ide-recent-projects.h
+++ b/src/libide/projects/ide-recent-projects.h
@@ -27,11 +27,12 @@ G_BEGIN_DECLS
 
 #define IDE_TYPE_RECENT_PROJECTS (ide_recent_projects_get_type())
 
-#define IDE_RECENT_PROJECTS_GROUP                     "X-GNOME-Builder-Project"
-#define IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX     "X-GNOME-Builder-Language:"
-#define IDE_RECENT_PROJECTS_BUILD_SYSTEM_GROUP_PREFIX "X-GNOME-Builder-Build-System:"
-#define IDE_RECENT_PROJECTS_DIRECTORY                 "X-GNOME-Builder-Directory:"
-#define IDE_RECENT_PROJECTS_BOOKMARK_FILENAME         "recent-projects.xbel"
+#define IDE_RECENT_PROJECTS_GROUP                          "X-GNOME-Builder-Project"
+#define IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX          "X-GNOME-Builder-Language:"
+#define IDE_RECENT_PROJECTS_BUILD_SYSTEM_GROUP_PREFIX      "X-GNOME-Builder-Build-System:"
+#define IDE_RECENT_PROJECTS_BUILD_SYSTEM_HINT_GROUP_PREFIX "X-GNOME-Builder-Build-System-Hint:"
+#define IDE_RECENT_PROJECTS_DIRECTORY                      "X-GNOME-Builder-Directory:"
+#define IDE_RECENT_PROJECTS_BOOKMARK_FILENAME              "recent-projects.xbel"
 
 IDE_AVAILABLE_IN_3_32
 G_DECLARE_FINAL_TYPE (IdeRecentProjects, ide_recent_projects, IDE, RECENT_PROJECTS, GObject)
diff --git a/src/plugins/buildsystem/gbp-buildsystem-workbench-addin.c 
b/src/plugins/buildsystem/gbp-buildsystem-workbench-addin.c
index 7d7bbcbc7..9ed422c04 100644
--- a/src/plugins/buildsystem/gbp-buildsystem-workbench-addin.c
+++ b/src/plugins/buildsystem/gbp-buildsystem-workbench-addin.c
@@ -113,6 +113,7 @@ discovery_worker (IdeTask      *task,
 static void
 discover_async (GbpBuildsystemWorkbenchAddin *self,
                 GFile                        *directory,
+                const gchar                  *hint,
                 GCancellable                 *cancellable,
                 GAsyncReadyCallback           callback,
                 gpointer                      user_data)
@@ -138,6 +139,17 @@ discover_async (GbpBuildsystemWorkbenchAddin *self,
                                               peas_engine_get_default (),
                                               IDE_TYPE_BUILD_SYSTEM_DISCOVERY,
                                               NULL, NULL);
+
+  /* If we have a hint here, we want to lock in this build system
+   * instead of allowing another to override it. So in that case,
+   * raise the priority (by lowering the value).
+   */
+  if (hint != NULL)
+    {
+      state->best_match = g_intern_string (hint);
+      state->best_match_priority = G_MININT;
+    }
+
   ide_task_set_task_data (task, state, discovery_free);
   ide_task_run_in_thread (task, discovery_worker);
 }
@@ -232,6 +244,7 @@ gbp_buildsystem_workbench_addin_load_project_async (IdeWorkbenchAddin   *addin,
 {
   GbpBuildsystemWorkbenchAddin *self = (GbpBuildsystemWorkbenchAddin *)addin;
   g_autoptr(IdeTask) task = NULL;
+  const gchar *hint;
   GFile *directory;
 
   g_assert (IDE_IS_MAIN_THREAD ());
@@ -247,8 +260,11 @@ gbp_buildsystem_workbench_addin_load_project_async (IdeWorkbenchAddin   *addin,
   directory = ide_project_info_get_directory (project_info);
   g_assert (G_IS_FILE (directory));
 
+  hint = ide_project_info_get_build_system_hint (project_info);
+
   discover_async (self,
                   directory,
+                  hint,
                   cancellable,
                   discover_cb,
                   g_steal_pointer (&task));


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