[gnome-builder] context: add helpers to track unloading state
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] context: add helpers to track unloading state
- Date: Thu, 1 Feb 2018 04:12:03 +0000 (UTC)
commit 7438dde81856986bd691405efb8e61650587c077
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 31 20:10:12 2018 -0800
context: add helpers to track unloading state
We want to avoid doing work when the context is shutting down,
so give ourselves a function to check.
src/libide/ide-context.c | 24 ++++++++++++++++++++++++
src/libide/ide-context.h | 3 +++
src/libide/ide-object.c | 13 +++++++++++++
src/libide/ide-object.h | 2 ++
4 files changed, 42 insertions(+)
---
diff --git a/src/libide/ide-context.c b/src/libide/ide-context.c
index 3b4e2eb77..b22687f61 100644
--- a/src/libide/ide-context.c
+++ b/src/libide/ide-context.c
@@ -140,6 +140,7 @@ struct _IdeContext
guint restored : 1;
guint restoring : 1;
+ guint unloading : 1;
};
static void async_initable_init (GAsyncInitableIface *);
@@ -2092,6 +2093,8 @@ ide_context_unload_async (IdeContext *self,
g_return_if_fail (IDE_IS_CONTEXT (self));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+ self->unloading = TRUE;
+
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, ide_context_unload_async);
@@ -2857,3 +2860,24 @@ ide_context_get_project_settings (IdeContext *self)
return g_settings_new_with_path ("org.gnome.builder.project", path);
}
+
+/**
+ * ide_context_is_unloading:
+ * @self: a #IdeContext
+ *
+ * Checks if ide_context_unload_async() has been called.
+ *
+ * You might use this to avoid starting any new work once the context has
+ * started the shutdown sequence.
+ *
+ * Returns: %TRUE if ide_context_unload_async() has been called.
+ *
+ * Since: 3.28
+ */
+gboolean
+ide_context_is_unloading (IdeContext *self)
+{
+ g_return_val_if_fail (IDE_IS_CONTEXT (self), FALSE);
+
+ return self->unloading;
+}
diff --git a/src/libide/ide-context.h b/src/libide/ide-context.h
index 7d47d5574..bbacc48a0 100644
--- a/src/libide/ide-context.h
+++ b/src/libide/ide-context.h
@@ -144,6 +144,9 @@ gchar *ide_context_cache_filename (IdeContext
IDE_AVAILABLE_IN_3_28
IdeVcsMonitor *ide_context_get_monitor (IdeContext *self);
+IDE_AVAILABLE_IN_3_28
+gboolean ide_context_is_unloading (IdeContext *self);
+
GListModel *_ide_context_get_pausables (IdeContext *self) G_GNUC_INTERNAL;
gboolean _ide_context_is_restoring (IdeContext *self) G_GNUC_INTERNAL;
diff --git a/src/libide/ide-object.c b/src/libide/ide-object.c
index 6385546d1..b665e098e 100644
--- a/src/libide/ide-object.c
+++ b/src/libide/ide-object.c
@@ -816,3 +816,16 @@ ide_object_warning (gpointer instance,
else
g_warning ("%s", str);
}
+
+gboolean
+ide_object_is_unloading (IdeObject *object)
+{
+ IdeContext *context;
+
+ g_return_val_if_fail (IDE_IS_OBJECT (object), TRUE);
+
+ if (!(context = ide_object_get_context (object)))
+ return TRUE;
+
+ return ide_context_is_unloading (context);
+}
diff --git a/src/libide/ide-object.h b/src/libide/ide-object.h
index 33c5ec0c0..4fbb58332 100644
--- a/src/libide/ide-object.h
+++ b/src/libide/ide-object.h
@@ -81,5 +81,7 @@ IDE_AVAILABLE_IN_3_28
void ide_object_warning (gpointer instance,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
+IDE_AVAILABLE_IN_3_28
+gboolean ide_object_is_unloading (IdeObject *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]