[gnome-builder] context: add ide_context_get_recent_manager()



commit c306640c08aab847169f419359d114be3c30df12
Author: Christian Hergert <christian hergert me>
Date:   Tue Apr 7 23:52:01 2015 -0700

    context: add ide_context_get_recent_manager()
    
    This makes it convenient for context objects to add recent items to be
    tracked by the system.

 libide/ide-context.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++
 libide/ide-context.h |    2 +
 2 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-context.c b/libide/ide-context.c
index e3e13d9..4ff350c 100644
--- a/libide/ide-context.c
+++ b/libide/ide-context.c
@@ -47,6 +47,7 @@ struct _IdeContext
   IdeBufferManager         *buffer_manager;
   IdeBuildSystem           *build_system;
   IdeDeviceManager         *device_manager;
+  GtkRecentManager         *recent_manager;
   IdeScriptManager         *script_manager;
   IdeSearchEngine          *search_engine;
   IdeSourceSnippetsManager *snippets_manager;
@@ -85,6 +86,22 @@ enum {
 static GParamSpec *gParamSpecs [LAST_PROP];
 
 /**
+ * ide_context_get_recent_manager:
+ *
+ * Gets the IdeContext:recent-manager property. The recent manager is a GtkRecentManager instance
+ * that should be used for the workbench.
+ *
+ * Returns: (transfer none): A #GtkRecentManager.
+ */
+GtkRecentManager *
+ide_context_get_recent_manager (IdeContext *self)
+{
+  g_return_val_if_fail (IDE_IS_CONTEXT (self), NULL);
+
+  return self->recent_manager;
+}
+
+/**
  * ide_context_get_back_forward_list:
  *
  * Retrieves the global back forward list for the #IdeContext.
@@ -502,6 +519,7 @@ ide_context_finalize (GObject *object)
   g_clear_object (&self->device_manager);
   g_clear_object (&self->project);
   g_clear_object (&self->project_file);
+  g_clear_object (&self->recent_manager);
   g_clear_object (&self->unsaved_files);
   g_clear_object (&self->vcs);
 
@@ -711,6 +729,8 @@ ide_context_init (IdeContext *self)
 
   IDE_ENTRY;
 
+  self->recent_manager = gtk_recent_manager_new ();
+
   self->root_build_dir = g_build_filename (g_get_user_cache_dir (),
                                            ide_get_program_name (),
                                            "builds",
@@ -1210,6 +1230,40 @@ ide_context_init_search_engine (gpointer             source_object,
 }
 
 static void
+ide_context_init_add_recent (gpointer             source_object,
+                             GCancellable        *cancellable,
+                             GAsyncReadyCallback  callback,
+                             gpointer             user_data)
+{
+  IdeContext *self = source_object;
+  GtkRecentData recent_data = { 0 };
+  const gchar *groups[] = { "X-GNOME-Builder-Project", NULL };
+  g_autoptr(GTask) task = NULL;
+  g_autofree gchar *uri = NULL;
+  g_autofree gchar *app_exec = NULL;
+
+  g_assert (IDE_IS_CONTEXT (self));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  task = g_task_new (self, cancellable, callback, user_data);
+
+  uri = g_file_get_uri (self->project_file);
+  app_exec = g_strdup_printf ("%s -p %%p", ide_get_program_name ());
+
+  recent_data.display_name = (gchar *)ide_project_get_name (self->project);
+  recent_data.description = NULL;
+  recent_data.mime_type = "application/x-builder-project";
+  recent_data.app_name = (gchar *)ide_get_program_name ();
+  recent_data.app_exec = app_exec;
+  recent_data.groups = (gchar **)groups;
+  recent_data.is_private = FALSE;
+
+  gtk_recent_manager_add_full (self->recent_manager, uri, &recent_data);
+
+  g_task_return_boolean (task, TRUE);
+}
+
+static void
 ide_context_init_async (GAsyncInitable      *initable,
                         int                  io_priority,
                         GCancellable        *cancellable,
@@ -1234,6 +1288,7 @@ ide_context_init_async (GAsyncInitable      *initable,
                         ide_context_init_search_engine,
                         ide_context_init_snippets,
                         ide_context_init_scripts,
+                        ide_context_init_add_recent,
                         NULL);
 
   /* TODO: Restore buffer state? */
diff --git a/libide/ide-context.h b/libide/ide-context.h
index a5513c6..0e5d3be 100644
--- a/libide/ide-context.h
+++ b/libide/ide-context.h
@@ -20,6 +20,7 @@
 #define IDE_CONTEXT_H
 
 #include <gio/gio.h>
+#include <gtk/gtk.h>
 
 #include "ide-types.h"
 
@@ -35,6 +36,7 @@ IdeBufferManager         *ide_context_get_buffer_manager    (IdeContext
 IdeBuildSystem           *ide_context_get_build_system      (IdeContext           *self);
 IdeDeviceManager         *ide_context_get_device_manager    (IdeContext           *self);
 IdeProject               *ide_context_get_project           (IdeContext           *self);
+GtkRecentManager         *ide_context_get_recent_manager    (IdeContext           *self);
 IdeScriptManager         *ide_context_get_script_manager    (IdeContext           *self);
 IdeSearchEngine          *ide_context_get_search_engine     (IdeContext           *self);
 IdeSourceSnippetsManager *ide_context_get_snippets_manager  (IdeContext           *self);


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