[gnome-builder] code: add API for buffer addins to settle
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] code: add API for buffer addins to settle
- Date: Mon, 18 Feb 2019 19:38:04 +0000 (UTC)
commit a18df278b28b1a721fd7109b5f04ceefc3195806
Author: Christian Hergert <chergert redhat com>
Date: Mon Feb 18 10:26:23 2019 -0800
code: add API for buffer addins to settle
This gives the buffer addins a way to say they need more time to finish
an in-flight operation before the buffer is marked as "settled". Doing
so allows things like "save" to settle before proceeding with reading the
buffer contents.
This only implements the addin scaffolding. Additional work in IdeBuffer
is needed to consume this.
src/libide/code/ide-buffer-addin.c | 50 +++++++++++++++++++
src/libide/code/ide-buffer-addin.h | 100 +++++++++++++++++++++----------------
2 files changed, 108 insertions(+), 42 deletions(-)
---
diff --git a/src/libide/code/ide-buffer-addin.c b/src/libide/code/ide-buffer-addin.c
index 7eaf484b8..ce0f168a4 100644
--- a/src/libide/code/ide-buffer-addin.c
+++ b/src/libide/code/ide-buffer-addin.c
@@ -22,6 +22,7 @@
#include "config.h"
+#include <libide-threading.h>
#include <libpeas/peas.h>
#include "ide-buffer.h"
@@ -48,9 +49,33 @@
G_DEFINE_INTERFACE (IdeBufferAddin, ide_buffer_addin, G_TYPE_OBJECT)
+static void
+ide_buffer_addin_real_settle_async (IdeBufferAddin *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr(IdeTask) task = NULL;
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, ide_buffer_addin_real_settle_async);
+ ide_task_set_priority (task, G_PRIORITY_HIGH);
+ ide_task_return_boolean (task, TRUE);
+}
+
+static gboolean
+ide_buffer_addin_real_settle_finish (IdeBufferAddin *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ return ide_task_propagate_boolean (IDE_TASK (result), error);
+}
+
static void
ide_buffer_addin_default_init (IdeBufferAddinInterface *iface)
{
+ iface->settle_async = ide_buffer_addin_real_settle_async;
+ iface->settle_finish = ide_buffer_addin_real_settle_finish;
}
/**
@@ -409,3 +434,28 @@ _ide_buffer_addin_style_scheme_changed_cb (IdeExtensionSetAdapter *set,
ide_buffer_addin_style_scheme_changed (IDE_BUFFER_ADDIN (exten), IDE_BUFFER (user_data));
}
+
+void
+ide_buffer_addin_settle_async (IdeBufferAddin *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (IDE_IS_MAIN_THREAD ());
+ g_return_if_fail (IDE_IS_BUFFER_ADDIN (self));
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ IDE_BUFFER_ADDIN_GET_IFACE (self)->settle_async (self, cancellable, callback, user_data);
+}
+
+gboolean
+ide_buffer_addin_settle_finish (IdeBufferAddin *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (IDE_IS_MAIN_THREAD (), FALSE);
+ g_return_val_if_fail (IDE_IS_BUFFER_ADDIN (self), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+ return IDE_BUFFER_ADDIN_GET_IFACE (self)->settle_finish (self, result, error);
+}
diff --git a/src/libide/code/ide-buffer-addin.h b/src/libide/code/ide-buffer-addin.h
index 78481188e..df84afe42 100644
--- a/src/libide/code/ide-buffer-addin.h
+++ b/src/libide/code/ide-buffer-addin.h
@@ -39,58 +39,74 @@ struct _IdeBufferAddinInterface
{
GTypeInterface parent_iface;
- void (*load) (IdeBufferAddin *self,
- IdeBuffer *buffer);
- void (*unload) (IdeBufferAddin *self,
- IdeBuffer *buffer);
- void (*file_loaded) (IdeBufferAddin *self,
- IdeBuffer *buffer,
- GFile *file);
- void (*save_file) (IdeBufferAddin *self,
- IdeBuffer *buffer,
- GFile *file);
- void (*file_saved) (IdeBufferAddin *self,
- IdeBuffer *buffer,
- GFile *file);
- void (*language_set) (IdeBufferAddin *self,
- IdeBuffer *buffer,
- const gchar *language_id);
- void (*change_settled) (IdeBufferAddin *self,
- IdeBuffer *buffer);
- void (*style_scheme_changed) (IdeBufferAddin *self,
- IdeBuffer *buffer);
+ void (*load) (IdeBufferAddin *self,
+ IdeBuffer *buffer);
+ void (*unload) (IdeBufferAddin *self,
+ IdeBuffer *buffer);
+ void (*file_loaded) (IdeBufferAddin *self,
+ IdeBuffer *buffer,
+ GFile *file);
+ void (*save_file) (IdeBufferAddin *self,
+ IdeBuffer *buffer,
+ GFile *file);
+ void (*file_saved) (IdeBufferAddin *self,
+ IdeBuffer *buffer,
+ GFile *file);
+ void (*language_set) (IdeBufferAddin *self,
+ IdeBuffer *buffer,
+ const gchar *language_id);
+ void (*change_settled) (IdeBufferAddin *self,
+ IdeBuffer *buffer);
+ void (*style_scheme_changed) (IdeBufferAddin *self,
+ IdeBuffer *buffer);
+ void (*settle_async) (IdeBufferAddin *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (*settle_finish) (IdeBufferAddin *self,
+ GAsyncResult *result,
+ GError **error);
};
IDE_AVAILABLE_IN_3_32
-void ide_buffer_addin_load (IdeBufferAddin *self,
- IdeBuffer *buffer);
+void ide_buffer_addin_load (IdeBufferAddin *self,
+ IdeBuffer *buffer);
IDE_AVAILABLE_IN_3_32
-void ide_buffer_addin_unload (IdeBufferAddin *self,
- IdeBuffer *buffer);
+void ide_buffer_addin_unload (IdeBufferAddin *self,
+ IdeBuffer *buffer);
IDE_AVAILABLE_IN_3_32
-void ide_buffer_addin_file_loaded (IdeBufferAddin *self,
- IdeBuffer *buffer,
- GFile *file);
+void ide_buffer_addin_file_loaded (IdeBufferAddin *self,
+ IdeBuffer *buffer,
+ GFile *file);
IDE_AVAILABLE_IN_3_32
-void ide_buffer_addin_save_file (IdeBufferAddin *self,
- IdeBuffer *buffer,
- GFile *file);
+void ide_buffer_addin_save_file (IdeBufferAddin *self,
+ IdeBuffer *buffer,
+ GFile *file);
IDE_AVAILABLE_IN_3_32
-void ide_buffer_addin_file_saved (IdeBufferAddin *self,
- IdeBuffer *buffer,
- GFile *file);
+void ide_buffer_addin_file_saved (IdeBufferAddin *self,
+ IdeBuffer *buffer,
+ GFile *file);
IDE_AVAILABLE_IN_3_32
-void ide_buffer_addin_language_set (IdeBufferAddin *self,
- IdeBuffer *buffer,
- const gchar *language_id);
+void ide_buffer_addin_language_set (IdeBufferAddin *self,
+ IdeBuffer *buffer,
+ const gchar *language_id);
IDE_AVAILABLE_IN_3_32
-void ide_buffer_addin_change_settled (IdeBufferAddin *self,
- IdeBuffer *buffer);
+void ide_buffer_addin_change_settled (IdeBufferAddin *self,
+ IdeBuffer *buffer);
IDE_AVAILABLE_IN_3_32
-void ide_buffer_addin_style_scheme_changed (IdeBufferAddin *self,
- IdeBuffer *buffer);
+void ide_buffer_addin_style_scheme_changed (IdeBufferAddin *self,
+ IdeBuffer *buffer);
IDE_AVAILABLE_IN_3_32
-IdeBufferAddin *ide_buffer_addin_find_by_module_name (IdeBuffer *buffer,
- const gchar *module_name);
+void ide_buffer_addin_settle_async (IdeBufferAddin *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+IDE_AVAILABLE_IN_3_32
+gboolean ide_buffer_addin_settle_finish (IdeBufferAddin *self,
+ GAsyncResult *result,
+ GError **error);
+IDE_AVAILABLE_IN_3_32
+IdeBufferAddin *ide_buffer_addin_find_by_module_name (IdeBuffer *buffer,
+ const gchar *module_name);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]