[gnome-builder] ide-code: Add "disable addins" buffer flag



commit da575ed94f96c6dfe2f4192ff3f0d2f7a4e56fa6
Author: vanadiae <vanadiae35 gmail com>
Date:   Sat Aug 7 00:38:06 2021 +0200

    ide-code: Add "disable addins" buffer flag
    
    This allows disabling features that really are just useful when the
    buffer is displayed in a source view. That way we can avoid having
    e.g. codespell burning the CPU/disk when doing a Search and Replace on
    a project…

 src/libide/code/ide-buffer-manager.c | 14 +++++++++---
 src/libide/code/ide-buffer-manager.h |  2 ++
 src/libide/code/ide-buffer-private.h |  1 +
 src/libide/code/ide-buffer.c         | 43 +++++++++++++++++++++++++++++-------
 4 files changed, 49 insertions(+), 11 deletions(-)
---
diff --git a/src/libide/code/ide-buffer-manager.c b/src/libide/code/ide-buffer-manager.c
index 22d5f1903..225ef8429 100644
--- a/src/libide/code/ide-buffer-manager.c
+++ b/src/libide/code/ide-buffer-manager.c
@@ -117,6 +117,7 @@ save_all_free (SaveAll *state)
 static IdeBuffer *
 ide_buffer_manager_create_buffer (IdeBufferManager *self,
                                   GFile            *file,
+                                  gboolean          disable_addins,
                                   gboolean          is_temporary)
 {
   g_autoptr(IdeBuffer) buffer = NULL;
@@ -127,7 +128,7 @@ ide_buffer_manager_create_buffer (IdeBufferManager *self,
   g_assert (IDE_IS_MAIN_THREAD ());
   g_assert (IDE_IS_BUFFER_MANAGER (self));
 
-  buffer = _ide_buffer_new (self, file, is_temporary);
+  buffer = _ide_buffer_new (self, file, disable_addins, is_temporary);
   box = ide_object_box_new (G_OBJECT (buffer));
 
   ide_object_append (IDE_OBJECT (self), IDE_OBJECT (box));
@@ -661,7 +662,9 @@ ide_buffer_manager_load_file_async (IdeBufferManager     *self,
   else
     {
       /* Create the buffer and track it so we can find it later */
-      buffer = ide_buffer_manager_create_buffer (self, file, temp_file != NULL);
+      buffer = ide_buffer_manager_create_buffer (self, file,
+                                                 flags & IDE_BUFFER_OPEN_FLAGS_DISABLE_ADDINS,
+                                                 temp_file != NULL);
       is_new = TRUE;
     }
 
@@ -1181,7 +1184,12 @@ ide_buffer_manager_apply_edits_async (IdeBufferManager    *self,
        */
       ide_buffer_manager_load_file_async (self,
                                           file,
-                                          IDE_BUFFER_OPEN_FLAGS_NO_VIEW,
+                                          IDE_BUFFER_OPEN_FLAGS_NO_VIEW |
+                                          /* We are only temporary loading the buffer to replace text
+                                           * there, so let's avoid any heavy useless work that the
+                                           * buffer addins might do.
+                                           */
+                                          IDE_BUFFER_OPEN_FLAGS_DISABLE_ADDINS,
                                           NULL,
                                           cancellable,
                                           ide_buffer_manager_apply_edits_buffer_loaded_cb,
diff --git a/src/libide/code/ide-buffer-manager.h b/src/libide/code/ide-buffer-manager.h
index d635e9afa..8c7fd28c8 100644
--- a/src/libide/code/ide-buffer-manager.h
+++ b/src/libide/code/ide-buffer-manager.h
@@ -35,6 +35,7 @@ G_BEGIN_DECLS
  * @IDE_BUFFER_OPEN_FLAGS_NONE: No special processing will be performed
  * @IDE_BUFFER_OPEN_FLAGS_BACKGROUND: Open the document in the background (behind current view)
  * @IDE_BUFFER_OPEN_FLAGS_NO_VIEW: Open the document but do not create a new view for it
+ * @IDE_BUFFER_OPEN_FLAGS_DISABLE_ADDINS: Disables any buffer addin for this buffer.
  *
  * The #IdeBufferOpenFlags enumeration is used to specify how a document should
  * be opened by the workbench. Plugins may want to have a bit of control over
@@ -48,6 +49,7 @@ typedef enum
   IDE_BUFFER_OPEN_FLAGS_BACKGROUND   = 1 << 0,
   IDE_BUFFER_OPEN_FLAGS_NO_VIEW      = 1 << 1,
   IDE_BUFFER_OPEN_FLAGS_FORCE_RELOAD = 1 << 2,
+  IDE_BUFFER_OPEN_FLAGS_DISABLE_ADDINS = 1 << 3,
 } IdeBufferOpenFlags;
 
 /**
diff --git a/src/libide/code/ide-buffer-private.h b/src/libide/code/ide-buffer-private.h
index 1f2f26984..5d95d7fbb 100644
--- a/src/libide/code/ide-buffer-private.h
+++ b/src/libide/code/ide-buffer-private.h
@@ -38,6 +38,7 @@ gboolean                _ide_buffer_can_restore_cursor       (IdeBuffer
 IdeExtensionSetAdapter *_ide_buffer_get_addins               (IdeBuffer            *self);
 IdeBuffer              *_ide_buffer_new                      (IdeBufferManager     *self,
                                                               GFile                *file,
+                                                              gboolean              disable_addins,
                                                               gboolean              is_temporary);
 void                    _ide_buffer_attach                   (IdeBuffer            *self,
                                                               IdeObject            *parent);
diff --git a/src/libide/code/ide-buffer.c b/src/libide/code/ide-buffer.c
index 3788d364c..ca24f3208 100644
--- a/src/libide/code/ide-buffer.c
+++ b/src/libide/code/ide-buffer.c
@@ -98,6 +98,7 @@ struct _IdeBuffer
   IdeBufferState          state : 3;
   guint                   can_restore_cursor : 1;
   guint                   is_temporary : 1;
+  guint                   disable_addins : 1;
   guint                   changed_on_volume : 1;
   guint                   read_only : 1;
   guint                   highlight_diagnostics : 1;
@@ -131,6 +132,7 @@ enum {
   PROP_BUFFER_MANAGER,
   PROP_CHANGE_MONITOR,
   PROP_CHANGED_ON_VOLUME,
+  PROP_DISABLE_ADDINS,
   PROP_DIAGNOSTICS,
   PROP_FAILED,
   PROP_FILE,
@@ -276,6 +278,7 @@ lookup_symbol_data_free (LookUpSymbolData *data)
 IdeBuffer *
 _ide_buffer_new (IdeBufferManager *buffer_manager,
                  GFile            *file,
+                 gboolean          disable_addins,
                  gboolean          is_temporary)
 {
   g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL);
@@ -285,6 +288,7 @@ _ide_buffer_new (IdeBufferManager *buffer_manager,
   return g_object_new (IDE_TYPE_BUFFER,
                        "buffer-manager", buffer_manager,
                        "file", file,
+                       "disable-addins", disable_addins,
                        "is-temporary", is_temporary,
                        NULL);
 }
@@ -308,7 +312,7 @@ _ide_buffer_set_file (IdeBuffer *self,
       self->readlink_file = _ide_g_file_readlink (file);
       ide_buffer_reload_file_settings (self);
 
-      if (self->addins != NULL)
+      if (self->addins != NULL && !self->disable_addins)
         {
           IdeBufferFileLoad closure = { self, file };
           ide_extension_set_adapter_foreach (self->addins,
@@ -364,7 +368,7 @@ ide_buffer_notify_language (IdeBuffer  *self,
 
   lang_id = ide_buffer_get_language_id (self);
 
-  if (self->addins != NULL)
+  if (self->addins != NULL && !self->disable_addins)
     {
       IdeBufferLanguageSet state = { self, lang_id };
 
@@ -456,6 +460,10 @@ ide_buffer_get_property (GObject    *object,
       g_value_set_boolean (value, ide_buffer_get_changed_on_volume (self));
       break;
 
+    case PROP_DISABLE_ADDINS:
+      g_value_set_boolean (value, self->disable_addins);
+      break;
+
     case PROP_DIAGNOSTICS:
       g_value_set_object (value, ide_buffer_get_diagnostics (self));
       break;
@@ -531,6 +539,10 @@ ide_buffer_set_property (GObject      *object,
       ide_buffer_set_change_monitor (self, g_value_get_object (value));
       break;
 
+    case PROP_DISABLE_ADDINS:
+      self->disable_addins = g_value_get_boolean (value);
+      break;
+
     case PROP_DIAGNOSTICS:
       ide_buffer_set_diagnostics (self, g_value_get_object (value));
       break;
@@ -624,6 +636,21 @@ ide_buffer_class_init (IdeBufferClass *klass)
                           FALSE,
                           (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+  /**
+   * IdeBuffer:disable-addins:
+   *
+   * The "disable-addins" property determines whether addins will be aware of this buffer. When
+   * set to TRUE no ide_buffer_addin_*() functions will be called on this buffer.
+   *
+   * Since: 3.32
+   */
+  properties [PROP_DISABLE_ADDINS] =
+    g_param_spec_boolean ("disable-addins",
+                          "Disable addins",
+                          "Whether to disable addins for this buffer",
+                          FALSE,
+                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY));
+
   /**
    * IdeBuffer:diagnostics:
    *
@@ -1400,7 +1427,7 @@ _ide_buffer_load_file_finish (IdeBuffer     *self,
   g_signal_emit (self, signals [LOADED], 0);
 
   /* Notify buffer addins that a file has been loaded */
-  if (self->addins != NULL)
+  if (self->addins != NULL && !self->disable_addins)
     {
       IdeBufferFileLoad closure = { self, state->file };
       ide_extension_set_adapter_foreach (self->addins,
@@ -1454,7 +1481,7 @@ ide_buffer_save_file_cb (GObject      *object,
   _ide_buffer_set_changed_on_volume (self, FALSE);
 
   /* Notify addins that a save has completed */
-  if (self->addins != NULL)
+  if (self->addins != NULL && !self->disable_addins)
     {
       IdeBufferFileSave closure = { self, state->file };
       ide_extension_set_adapter_foreach (self->addins,
@@ -1496,7 +1523,7 @@ ide_buffer_save_file_settle_cb (GObject      *object,
   g_assert (IDE_IS_NOTIFICATION (state->notif));
   g_assert (GTK_SOURCE_IS_FILE (state->source_file));
 
-  if (self->addins != NULL)
+  if (self->addins != NULL && !self->disable_addins)
     {
       IdeBufferFileSave closure = { self, state->file };
       ide_extension_set_adapter_foreach (self->addins,
@@ -2304,7 +2331,7 @@ ide_buffer_settled_cb (gpointer user_data)
   self->settling_source = 0;
   g_signal_emit (self, signals [CHANGE_SETTLED], 0);
 
-  if (self->addins != NULL)
+  if (self->addins != NULL && !self->disable_addins)
     ide_extension_set_adapter_foreach (self->addins,
                                        _ide_buffer_addin_change_settled_cb,
                                        self);
@@ -3164,7 +3191,7 @@ ide_buffer_notify_style_scheme (IdeBuffer  *self,
 
 #undef GET_TAG
 
-  if (self->addins != NULL)
+  if (self->addins != NULL && !self->disable_addins)
     ide_extension_set_adapter_foreach (self->addins,
                                        _ide_buffer_addin_style_scheme_changed_cb,
                                        self);
@@ -3886,7 +3913,7 @@ settle_async (IdeBuffer           *self,
   ide_task_set_source_tag (task, settle_async);
   ide_task_set_task_data (task, n_active, g_free);
 
-  if (self->addins != NULL)
+  if (self->addins != NULL && !self->disable_addins)
     ide_extension_set_adapter_foreach (self->addins,
                                        settle_foreach_cb,
                                        task);


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