From 4ec042665bd3eaf734c33277929101921e511a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Porto?= Date: Mon, 11 Nov 2024 20:53:11 -0300 Subject: [PATCH] Editor: don't clear or remove autolocal in watch pane --- Editor/AGS.Editor/GUI/WatchVariablesPanel.cs | 37 ++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs b/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs index d18faf732b..7aabaa36f5 100644 --- a/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs +++ b/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs @@ -1,5 +1,6 @@ using AGS.Types; using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -394,17 +395,34 @@ private void listView1_KeyDown(object sender, KeyEventArgs e) { if (listView1.SelectedItems.Count > 0) { - listView1.SelectedItems[0].BeginEdit(); + if (!IsAutoLocal(listView1.SelectedItems[0])) + listView1.SelectedItems[0].BeginEdit(); } } } + private static bool AllAutoLocal(IEnumerable items) + { + foreach (ListViewItem itm in items) + { + if(itm.Text.Length > 0 && !IsAutoLocal(itm)) + return false; + } + return true; + } + + private bool WatchPaneIsEmpty() + { + return (listView1.Items.Count == 0) || + (listView1.Items.Count == 1 && listView1.Items[listView1.Items.Count - 1].Text.Length == 0); + } + private void listView1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { - removeToolStripMenuItem.Enabled = listView1.SelectedItems.Count > 0; - clearToolStripMenuItem.Enabled = listView1.Items.Count > 0; + removeToolStripMenuItem.Enabled = !WatchPaneIsEmpty() && !AllAutoLocal(listView1.SelectedItems); + clearToolStripMenuItem.Enabled = !WatchPaneIsEmpty() && !AllAutoLocal(listView1.Items); contextMenuStrip1.Show(listView1, e.Location); } } @@ -433,14 +451,21 @@ private void addToolStripMenuItem_Click(object sender, EventArgs e) private void removeToolStripMenuItem_Click(object sender, EventArgs e) { - foreach (var item in listView1.SelectedItems) - listView1.Items.Remove(item as ListViewItem); + foreach (ListViewItem itm in listView1.SelectedItems) + { + if (!IsAutoLocal(itm)) + listView1.Items.Remove(itm); + } EnsureEmptyItem(); } private void clearToolStripMenuItem_Click(object sender, EventArgs e) { - listView1.Items.Clear(); + foreach (ListViewItem itm in listView1.Items) + { + if (!IsAutoLocal(itm)) + listView1.Items.Remove(itm); + } EnsureEmptyItem(); }