[gnome-builder] config: avoid writeback due to attaching config



commit e63e46f52f7f5459816ffd8c2fe63227310cfc3a
Author: Christian Hergert <chergert redhat com>
Date:   Tue Apr 10 18:51:30 2018 -0700

    config: avoid writeback due to attaching config
    
    When we attach the config, we might set a new prefix based on what the
    runtime requires. We should not force a writeback in this case as it
    causes spurious .buildconfig files upon loading a project.

 src/libide/config/ide-configuration.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/config/ide-configuration.c b/src/libide/config/ide-configuration.c
index d72884a21..1f2039ba9 100644
--- a/src/libide/config/ide-configuration.c
+++ b/src/libide/config/ide-configuration.c
@@ -56,6 +56,8 @@ typedef struct
   gint            parallelism;
   guint           sequence;
 
+  guint           block_changed;
+
   guint           dirty : 1;
   guint           debug : 1;
   guint           has_attached : 1;
@@ -126,12 +128,35 @@ _value_new (GType type)
   return value;
 }
 
+static void
+ide_configuration_block_changed (IdeConfiguration *self)
+{
+  IdeConfigurationPrivate *priv = ide_configuration_get_instance_private (self);
+
+  g_assert (IDE_IS_CONFIGURATION (self));
+
+  priv->block_changed++;
+}
+
+static void
+ide_configuration_unblock_changed (IdeConfiguration *self)
+{
+  IdeConfigurationPrivate *priv = ide_configuration_get_instance_private (self);
+
+  g_assert (IDE_IS_CONFIGURATION (self));
+
+  priv->block_changed--;
+}
+
 static void
 ide_configuration_emit_changed (IdeConfiguration *self)
 {
+  IdeConfigurationPrivate *priv = ide_configuration_get_instance_private (self);
+
   g_assert (IDE_IS_CONFIGURATION (self));
 
-  g_signal_emit (self, signals [CHANGED], 0);
+  if (priv->block_changed == 0)
+    g_signal_emit (self, signals [CHANGED], 0);
 }
 
 static IdeRuntime *
@@ -881,6 +906,9 @@ ide_configuration_set_dirty (IdeConfiguration *self,
 
   g_return_if_fail (IDE_IS_CONFIGURATION (self));
 
+  if (priv->block_changed)
+    IDE_EXIT;
+
   dirty = !!dirty;
 
   if (dirty != priv->dirty)
@@ -1509,5 +1537,8 @@ _ide_configuration_attach (IdeConfiguration *self)
                            self,
                            G_CONNECT_SWAPPED);
 
+  /* Update the runtime and potentially set prefix, but do not emit changed */
+  ide_configuration_block_changed (self);
   ide_configuration_runtime_manager_items_changed (self, 0, 0, 0, runtime_manager);
+  ide_configuration_unblock_changed (self);
 }


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