[gnome-builder] libide: save back-forward-list during context unload
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: save back-forward-list during context unload
- Date: Tue, 24 Mar 2015 00:17:38 +0000 (UTC)
commit 7f4253c2810d4829f2cce9c43d7b876fabffa391
Author: Christian Hergert <christian hergert me>
Date: Thu Mar 12 22:54:33 2015 -0700
libide: save back-forward-list during context unload
libide/ide-context.c | 79 +++++++++++++++++++++++++++++++++++++++----------
libide/ide-internal.h | 8 +++++
2 files changed, 71 insertions(+), 16 deletions(-)
---
diff --git a/libide/ide-context.c b/libide/ide-context.c
index 2aa9d0b..f7f9692 100644
--- a/libide/ide-context.c
+++ b/libide/ide-context.c
@@ -441,6 +441,27 @@ ide_context_get_service_typed (IdeContext *self,
return ide_context_create_service (self, service_type);
}
+static GFile *
+get_back_forward_list_file (IdeContext *self)
+{
+ const gchar *project_name;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *path = NULL;
+ GFile *file;
+
+ g_assert (IDE_IS_CONTEXT (self));
+
+ project_name = ide_project_get_name (self->project);
+ name = g_strdup_printf ("%s.back-forward-list", project_name);
+ path = g_build_filename (g_get_user_data_dir (),
+ "gnome-builder",
+ g_strdelimit (name, " \t\n", '_'),
+ NULL);
+ file = g_file_new_for_path (path);
+
+ return file;
+}
+
static void
ide_context_dispose (GObject *object)
{
@@ -1048,10 +1069,7 @@ ide_context_init_back_forward_list (gpointer source_object,
{
IdeContext *self = source_object;
g_autoptr(GTask) task = NULL;
- g_autofree gchar *name = NULL;
- g_autofree gchar *path = NULL;
g_autoptr(GFile) file = NULL;
- const gchar *project_name;
IDE_ENTRY;
@@ -1059,16 +1077,7 @@ ide_context_init_back_forward_list (gpointer source_object,
task = g_task_new (self, cancellable, callback, user_data);
- project_name = ide_project_get_name (self->project);
- name = g_strdup_printf ("%s.back-forward-list", project_name);
- path = g_build_filename (g_get_user_data_dir (),
- "gnome-builder",
- g_strdelimit (name, " \t\n", '_'),
- NULL);
- file = g_file_new_for_path (path);
-
- IDE_TRACE_MSG ("Loading %s", path);
-
+ file = get_back_forward_list_file (self);
_ide_back_forward_list_load_async (self->back_forward_list,
file,
cancellable,
@@ -1247,21 +1256,59 @@ async_initable_init (GAsyncInitableIface *iface)
}
static void
+ide_context_unload__back_forward_list_save_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IdeBackForwardList *back_forward_list = (IdeBackForwardList *)object;
+ g_autoptr(GTask) task = user_data;
+ GError *error = NULL;
+
+ IDE_ENTRY;
+
+ if (!_ide_back_forward_list_save_finish (back_forward_list, result, &error))
+ {
+ g_warning ("%s(): %s", G_STRFUNC, error->message);
+ g_clear_error (&error);
+ }
+
+ g_task_return_boolean (task, TRUE);
+
+ IDE_EXIT;
+}
+
+static void
ide_context_unload__unsaved_files_save_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
IdeUnsavedFiles *unsaved_files = (IdeUnsavedFiles *)object;
g_autoptr(GTask) task = user_data;
+ g_autoptr(GFile) file = NULL;
+ IdeContext *self;
GError *error = NULL;
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_UNSAVED_FILES (unsaved_files));
+ g_assert (G_IS_TASK (task));
+
+ self = g_task_get_source_object (task);
+
if (!ide_unsaved_files_save_finish (unsaved_files, result, &error))
{
- g_task_return_error (task, error);
- return;
+ g_warning ("%s(): %s", G_STRFUNC, error->message);
+ g_clear_error (&error);
}
- g_task_return_boolean (task, TRUE);
+ file = get_back_forward_list_file (self);
+ _ide_back_forward_list_save_async (self->back_forward_list,
+ file,
+ g_task_get_cancellable (task),
+ ide_context_unload__back_forward_list_save_cb,
+ g_object_ref (task));
+
+ IDE_EXIT;
}
/**
diff --git a/libide/ide-internal.h b/libide/ide-internal.h
index bb086a8..af14c8f 100644
--- a/libide/ide-internal.h
+++ b/libide/ide-internal.h
@@ -40,6 +40,14 @@ void _ide_back_forward_list_load_async (IdeBackForwardList *s
gboolean _ide_back_forward_list_load_finish (IdeBackForwardList *self,
GAsyncResult *result,
GError **error);
+void _ide_back_forward_list_save_async (IdeBackForwardList *self,
+ GFile *file,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean _ide_back_forward_list_save_finish (IdeBackForwardList *self,
+ GAsyncResult *result,
+ GError **error);
IdeBackForwardItem *_ide_back_forward_list_find (IdeBackForwardList *self,
IdeFile *file);
void _ide_diagnostic_add_range (IdeDiagnostic *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]