From 0955ee0da2b41a908c8a918951495d2c8d08ece9 Mon Sep 17 00:00:00 2001 From: e Date: Wed, 19 Jun 2024 20:19:05 -0300 Subject: [PATCH] Editor: avoid blinking in Watch Variables already added --- Editor/AGS.Editor/GUI/WatchVariablesPanel.cs | 41 ++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs b/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs index 8029354aa84..daca8374b01 100644 --- a/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs +++ b/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs @@ -293,43 +293,44 @@ public void SetAutoLocalVariables(DebugCallStack callStack) .Select(v => v.VariableName).Distinct().ToList(); listView1.BeginUpdate(); + + // We will avoid blinking of all "autolocal" by removing the ones not in varnames + // so we can keep the ones that already were added in a previous cycle + // later we will add ONLY the ones that weren't already added + // We also need to keep sync in the items to update. foreach (ListViewItem itm in listView1.Items) { - if(itm.Tag as string == "autolocal") + if (itm.Tag as string == "autolocal" && !varnames.Contains(itm.Text)) { itm.Remove(); } } - lock (_updateItemLock) { - for (int i = _itemsToUpdate.Count - 1; i >= 0; i--) - { - ListViewItem itm = _itemsToUpdate[i]; - if (itm.Tag as string == "autolocal") - { - _itemsToUpdate.RemoveAt(i); - } - } + _itemsToUpdate.RemoveAll(itm => itm.Tag as string == "autolocal" && !varnames.Contains(itm.Text)); Color c = Color.Empty; foreach (var v in varnames) { - var itm = CreateItem(v); - itm.Tag = "autolocal"; - itm = listView1.Items.Insert(0, itm); - - if (c.IsEmpty) + if (!listView1.Items.Cast().Any(itm => itm.Text == v && itm.Tag as string == "autolocal")) { - int brightness = PerceivedBrightness(itm.ForeColor); - c = brightness > 128 ? Color.LightBlue : Color.DarkBlue; - } - itm.ForeColor = c; + var itm = CreateItem(v); + itm.Tag = "autolocal"; + listView1.Items.Insert(0, itm); + + if (c == Color.Empty) + { + int brightness = PerceivedBrightness(itm.ForeColor); + c = brightness > 128 ? Color.LightBlue : Color.DarkBlue; + } + itm.ForeColor = c; - _itemsToUpdate.Add(itm); + _itemsToUpdate.Add(itm); + } } } + listView1.EndUpdate(); _updateItemTimer.Start(); }