[gnome-builder/wip/gtk4-port] plugins/spellcheck: disable when buffer is loading



commit ee1abc894785409b400e730825d281df2d6d94ad
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 7 17:48:49 2022 -0700

    plugins/spellcheck: disable when buffer is loading

 src/plugins/spellcheck/gbp-spell-buffer-addin.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/spellcheck/gbp-spell-buffer-addin.c b/src/plugins/spellcheck/gbp-spell-buffer-addin.c
index 56ba26dc9..e52f656da 100644
--- a/src/plugins/spellcheck/gbp-spell-buffer-addin.c
+++ b/src/plugins/spellcheck/gbp-spell-buffer-addin.c
@@ -52,6 +52,20 @@ check_error (GObject      *object,
     g_warning ("Failed to persist metadata: %s", error->message);
 }
 
+static gboolean
+state_to_enabled (GBinding     *binding,
+                  const GValue *from_value,
+                  GValue       *to_value,
+                  gpointer      user_data)
+{
+  if (g_value_get_enum (from_value) == IDE_BUFFER_STATE_READY)
+    g_value_set_boolean (to_value, TRUE);
+  else
+    g_value_set_boolean (to_value, FALSE);
+
+  return TRUE;
+}
+
 static void
 checker_notify_language_cb (GbpSpellBufferAddin *self,
                             GParamSpec          *pspec,
@@ -102,7 +116,9 @@ gbp_spell_buffer_addin_load (IdeBufferAddin *addin,
 
   self->enabled_action = g_property_action_new ("enabled", self->adapter, "enabled");
 
-  editor_text_buffer_spell_adapter_set_enabled (self->adapter, TRUE);
+  g_object_bind_property_full (buffer, "state", self->adapter, "enabled",
+                               G_BINDING_SYNC_CREATE,
+                               state_to_enabled, NULL, NULL, NULL);
 
   IDE_EXIT;
 }


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