[gnome-builder] greeter: Add build system tag to projects



commit 166ff99da9950219d97668dea4a7104b2f9503db
Author: Matthew Leeds <mleeds redhat com>
Date:   Wed Mar 29 18:41:20 2017 -0500

    greeter: Add build system tag to projects
    
    In Builder projects can be opened using different build systems
    depending on the project file that is chosen, which means the same
    project can appear twice in the "Recent Projects" list of the greeter,
    with no apparent difference. This commit adds a tag to each project so
    the user knows what build system it uses, in addition to the tags
    showing the language(s).

 libide/greeter/ide-greeter-project-row.c  |   26 +++++++++++---
 libide/greeter/ide-greeter-project-row.ui |    2 +-
 libide/ide-context.c                      |   11 ++++++
 libide/projects/ide-project-info.c        |   40 ++++++++++++++++++++++
 libide/projects/ide-project-info.h        |   53 +++++++++++++++-------------
 libide/projects/ide-recent-projects.c     |    4 ++
 libide/projects/ide-recent-projects.h     |    1 +
 7 files changed, 105 insertions(+), 32 deletions(-)
---
diff --git a/libide/greeter/ide-greeter-project-row.c b/libide/greeter/ide-greeter-project-row.c
index 36b71d6..0ed387e 100644
--- a/libide/greeter/ide-greeter-project-row.c
+++ b/libide/greeter/ide-greeter-project-row.c
@@ -24,6 +24,7 @@
 #include <glib/gi18n.h>
 
 #include "greeter/ide-greeter-project-row.h"
+#include "ide-macros.h"
 
 struct _IdeGreeterProjectRow
 {
@@ -35,7 +36,7 @@ struct _IdeGreeterProjectRow
 
   GtkLabel        *date_label;
   GtkLabel        *description_label;
-  GtkBox          *languages_box;
+  GtkBox          *tags_box;
   GtkLabel        *location_label;
   GtkLabel        *title_label;
   GtkCheckButton  *checkbox;
@@ -137,10 +138,11 @@ ide_greeter_project_row_create_search_text (IdeGreeterProjectRow *self,
 }
 
 static void
-ide_greeter_project_row_add_languages (IdeGreeterProjectRow *self,
-                                       IdeProjectInfo       *project_info)
+ide_greeter_project_row_add_tags (IdeGreeterProjectRow *self,
+                                  IdeProjectInfo       *project_info)
 {
   const gchar * const *languages;
+  const gchar *build_system_name;
 
   g_return_if_fail (IDE_IS_GREETER_PROJECT_ROW (self));
   g_return_if_fail (IDE_IS_PROJECT_INFO (project_info));
@@ -161,9 +163,21 @@ ide_greeter_project_row_add_languages (IdeGreeterProjectRow *self,
                                "visible", TRUE,
                                "label", name,
                                NULL);
-          gtk_container_add (GTK_CONTAINER (self->languages_box), pill);
+          gtk_container_add (GTK_CONTAINER (self->tags_box), pill);
         }
     }
+
+  build_system_name = ide_project_info_get_build_system_name (project_info);
+  if (!ide_str_empty0 (build_system_name))
+    {
+      GtkWidget *pill;
+
+      pill = g_object_new (EGG_TYPE_PILL_BOX,
+                           "visible", TRUE,
+                           "label", build_system_name,
+                           NULL);
+      gtk_container_add (GTK_CONTAINER (self->tags_box), pill);
+    }
 }
 
 static void
@@ -179,7 +193,7 @@ ide_greeter_project_row_set_project_info (IdeGreeterProjectRow *self,
 
       if (project_info != NULL)
         {
-          ide_greeter_project_row_add_languages (self, project_info);
+          ide_greeter_project_row_add_tags (self, project_info);
           ide_greeter_project_row_create_search_text (self, project_info);
         }
 
@@ -328,7 +342,7 @@ ide_greeter_project_row_class_init (IdeGreeterProjectRowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeGreeterProjectRow, date_label);
   gtk_widget_class_bind_template_child (widget_class, IdeGreeterProjectRow, description_label);
   gtk_widget_class_bind_template_child (widget_class, IdeGreeterProjectRow, location_label);
-  gtk_widget_class_bind_template_child (widget_class, IdeGreeterProjectRow, languages_box);
+  gtk_widget_class_bind_template_child (widget_class, IdeGreeterProjectRow, tags_box);
   gtk_widget_class_bind_template_child (widget_class, IdeGreeterProjectRow, title_label);
 
   properties [PROP_SELECTED] =
diff --git a/libide/greeter/ide-greeter-project-row.ui b/libide/greeter/ide-greeter-project-row.ui
index 6ec004b..7d525da 100644
--- a/libide/greeter/ide-greeter-project-row.ui
+++ b/libide/greeter/ide-greeter-project-row.ui
@@ -73,7 +73,7 @@
                   </object>
                 </child>
                 <child>
-                  <object class="GtkBox" id="languages_box">
+                  <object class="GtkBox" id="tags_box">
                     <property name="spacing">3</property>
                     <property name="orientation">horizontal</property>
                     <property name="visible">true</property>
diff --git a/libide/ide-context.c b/libide/ide-context.c
index adb5114..0d170e1 100644
--- a/libide/ide-context.c
+++ b/libide/ide-context.c
@@ -1373,6 +1373,17 @@ ide_context_init_add_recent (gpointer             source_object,
 
   g_bookmark_file_set_groups (projects_file, uri, (const gchar **)groups->pdata, groups->len);
 
+  {
+    IdeBuildSystem *build_system;
+    g_autofree gchar *build_system_name = NULL;
+    g_autofree gchar *build_system_group = NULL;
+
+    build_system = ide_context_get_build_system (self);
+    build_system_name = ide_build_system_get_display_name (build_system);
+    build_system_group = g_strdup_printf ("%s%s", IDE_RECENT_PROJECTS_BUILD_SYSTEM_GROUP_PREFIX, 
build_system_name);
+    g_bookmark_file_add_group (projects_file, uri, build_system_group);
+  }
+
   IDE_TRACE_MSG ("Registering %s as recent project.", uri);
 
   /* ensure the containing directory exists */
diff --git a/libide/projects/ide-project-info.c b/libide/projects/ide-project-info.c
index 138bdfb..a85456a 100644
--- a/libide/projects/ide-project-info.c
+++ b/libide/projects/ide-project-info.c
@@ -45,6 +45,7 @@ struct _IdeProjectInfo
   GDateTime  *last_modified_at;
   GFile      *directory;
   GFile      *file;
+  gchar      *build_system_name;
   gchar      *name;
   gchar      *description;
   gchar     **languages;
@@ -58,6 +59,7 @@ G_DEFINE_TYPE (IdeProjectInfo, ide_project_info, G_TYPE_OBJECT)
 
 enum {
   PROP_0,
+  PROP_BUILD_SYSTEM_NAME,
   PROP_DESCRIPTION,
   PROP_DIRECTORY,
   PROP_DOAP,
@@ -191,6 +193,28 @@ ide_project_info_get_last_modified_at (IdeProjectInfo *self)
 }
 
 const gchar *
+ide_project_info_get_build_system_name (IdeProjectInfo *self)
+{
+  g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL);
+
+  return self->build_system_name;
+}
+
+void
+ide_project_info_set_build_system_name (IdeProjectInfo *self,
+                                        const gchar    *build_system_name)
+{
+  g_return_if_fail (IDE_IS_PROJECT_INFO (self));
+
+  if (!ide_str_equal0 (self->build_system_name, build_system_name))
+    {
+      g_free (self->build_system_name);
+      self->build_system_name = g_strdup (build_system_name);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUILD_SYSTEM_NAME]);
+    }
+}
+
+const gchar *
 ide_project_info_get_description (IdeProjectInfo *self)
 {
   g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL);
@@ -299,6 +323,7 @@ ide_project_info_finalize (GObject *object)
   IdeProjectInfo *self = (IdeProjectInfo *)object;
 
   g_clear_pointer (&self->last_modified_at, g_date_time_unref);
+  g_clear_pointer (&self->build_system_name, g_free);
   g_clear_pointer (&self->description, g_free);
   g_clear_pointer (&self->languages, g_strfreev);
   g_clear_pointer (&self->name, g_free);
@@ -318,6 +343,10 @@ ide_project_info_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_BUILD_SYSTEM_NAME:
+      g_value_set_string (value, ide_project_info_get_build_system_name (self));
+      break;
+
     case PROP_DESCRIPTION:
       g_value_set_string (value, ide_project_info_get_description (self));
       break;
@@ -369,6 +398,10 @@ ide_project_info_set_property (GObject      *object,
 
   switch (prop_id)
     {
+    case PROP_BUILD_SYSTEM_NAME:
+      ide_project_info_set_build_system_name (self, g_value_get_string (value));
+      break;
+
     case PROP_DESCRIPTION:
       ide_project_info_set_description (self, g_value_get_string (value));
       break;
@@ -419,6 +452,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_NAME] =
+    g_param_spec_string ("build-system-name",
+                         "Build System name",
+                         "Build System name",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_DESCRIPTION] =
     g_param_spec_string ("description",
                          "Description",
diff --git a/libide/projects/ide-project-info.h b/libide/projects/ide-project-info.h
index 64031fd..698c23b 100644
--- a/libide/projects/ide-project-info.h
+++ b/libide/projects/ide-project-info.h
@@ -29,32 +29,35 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (IdeProjectInfo, ide_project_info, IDE, PROJECT_INFO, GObject)
 
-gint         ide_project_info_compare              (IdeProjectInfo  *info1,
-                                                    IdeProjectInfo  *info2);
-GFile        *ide_project_info_get_file             (IdeProjectInfo  *self);
-IdeDoap      *ide_project_info_get_doap             (IdeProjectInfo  *self);
-const gchar  *ide_project_info_get_description      (IdeProjectInfo  *self);
-GFile        *ide_project_info_get_directory        (IdeProjectInfo  *self);
-gboolean      ide_project_info_get_is_recent        (IdeProjectInfo  *self);
-gint          ide_project_info_get_priority         (IdeProjectInfo  *self);
-GDateTime    *ide_project_info_get_last_modified_at (IdeProjectInfo  *self);
+gint         ide_project_info_compare                (IdeProjectInfo  *info1,
+                                                      IdeProjectInfo  *info2);
+GFile        *ide_project_info_get_file              (IdeProjectInfo  *self);
+IdeDoap      *ide_project_info_get_doap              (IdeProjectInfo  *self);
+const gchar  *ide_project_info_get_build_system_name (IdeProjectInfo  *self);
+const gchar  *ide_project_info_get_description       (IdeProjectInfo  *self);
+GFile        *ide_project_info_get_directory         (IdeProjectInfo  *self);
+gboolean      ide_project_info_get_is_recent         (IdeProjectInfo  *self);
+gint          ide_project_info_get_priority          (IdeProjectInfo  *self);
+GDateTime    *ide_project_info_get_last_modified_at  (IdeProjectInfo  *self);
 const gchar * const *
-              ide_project_info_get_languages        (IdeProjectInfo  *self);
-const gchar  *ide_project_info_get_name             (IdeProjectInfo  *self);
-void          ide_project_info_set_file             (IdeProjectInfo  *self,
-                                                     GFile           *file);
-void          ide_project_info_set_description      (IdeProjectInfo  *self,
-                                                     const gchar     *description);
-void          ide_project_info_set_directory        (IdeProjectInfo  *self,
-                                                     GFile           *directory);
-void          ide_project_info_set_is_recent        (IdeProjectInfo  *self,
-                                                     gboolean         is_recent);
-void          ide_project_info_set_languages        (IdeProjectInfo  *self,
-                                                     gchar          **languages);
-void          ide_project_info_set_name             (IdeProjectInfo  *self,
-                                                     const gchar     *name);
-void          ide_project_info_set_priority         (IdeProjectInfo  *self,
-                                                     gint             priority);
+              ide_project_info_get_languages         (IdeProjectInfo  *self);
+const gchar  *ide_project_info_get_name              (IdeProjectInfo  *self);
+void          ide_project_info_set_file              (IdeProjectInfo  *self,
+                                                      GFile           *file);
+void          ide_project_info_set_build_system_name (IdeProjectInfo  *self,
+                                                      const gchar     *build_system_name);
+void          ide_project_info_set_description       (IdeProjectInfo  *self,
+                                                      const gchar     *description);
+void          ide_project_info_set_directory         (IdeProjectInfo  *self,
+                                                      GFile           *directory);
+void          ide_project_info_set_is_recent         (IdeProjectInfo  *self,
+                                                      gboolean         is_recent);
+void          ide_project_info_set_languages         (IdeProjectInfo  *self,
+                                                      gchar          **languages);
+void          ide_project_info_set_name              (IdeProjectInfo  *self,
+                                                      const gchar     *name);
+void          ide_project_info_set_priority          (IdeProjectInfo  *self,
+                                                      gint             priority);
 
 G_END_DECLS
 
diff --git a/libide/projects/ide-recent-projects.c b/libide/projects/ide-recent-projects.c
index 0e892e3..2385915 100644
--- a/libide/projects/ide-recent-projects.c
+++ b/libide/projects/ide-recent-projects.c
@@ -184,6 +184,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_name = NULL;
       const gchar *uri = uris[z];
       time_t modified;
       g_auto(GStrv) groups = NULL;
@@ -221,10 +222,13 @@ ide_recent_projects_load_recent (IdeRecentProjects *self)
         {
           if (g_str_has_prefix (groups [i], IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX))
             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);
         }
       g_ptr_array_add (languages, NULL);
 
       project_info = g_object_new (IDE_TYPE_PROJECT_INFO,
+                                   "build-system-name", build_system_name,
                                    "description", description,
                                    "directory", directory,
                                    "file", project_file,
diff --git a/libide/projects/ide-recent-projects.h b/libide/projects/ide-recent-projects.h
index e5a2def..b07aecd 100644
--- a/libide/projects/ide-recent-projects.h
+++ b/libide/projects/ide-recent-projects.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
 
 #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_BOOKMARK_FILENAME     "recent-projects.xbel"
 
 G_DECLARE_FINAL_TYPE (IdeRecentProjects, ide_recent_projects, IDE, RECENT_PROJECTS, GObject)


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