From c6e95e8e82f72df7ca39d5920e722f55c3ccc74a Mon Sep 17 00:00:00 2001 From: Bob Long Date: Wed, 29 Nov 2023 17:16:36 +1100 Subject: [PATCH] ConfigRawParams: prevent favorites from changing the tree --- GCSViews/ConfigurationView/ConfigRawParams.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/GCSViews/ConfigurationView/ConfigRawParams.cs b/GCSViews/ConfigurationView/ConfigRawParams.cs index f1db939983..4005026afb 100644 --- a/GCSViews/ConfigurationView/ConfigRawParams.cs +++ b/GCSViews/ConfigurationView/ConfigRawParams.cs @@ -644,10 +644,24 @@ private void BuildTree() treeView1.Nodes.Clear(); var currentNode = treeView1.Nodes.Add("All"); string currentPrefix = ""; - DataGridViewRowCollection rows = Params.Rows; - for (int i = 0; i < rows.Count; i++) + + // Get command names from the gridview + List commands = new List(); + foreach (DataGridViewRow row in Params.Rows) + { + string command = row.Cells[Command.Index].Value.ToString(); + if (!commands.Contains(command)) + { + commands.Add(command); + } + } + + // Sort them again (because of the favorites, they may be out of order) + commands.Sort(); + + for (int i = 0; i < commands.Count; i++) { - string param = rows[i].Cells[Command.Index].Value.ToString(); + string param = commands[i]; // While param does not start with currentPrefix, step up a layer in the tree while (!param.StartsWith(currentPrefix)) @@ -657,13 +671,13 @@ private void BuildTree() } // If this is the last parameter, add it - if (i == rows.Count - 1) + if (i == commands.Count - 1) { currentNode.Nodes.Add(param); break; } - string next_param = rows[i + 1].Cells[Command.Index].Value.ToString(); + string next_param = commands[i + 1]; // While the next parameter has a common prefix with this, add branch nodes string nodeToAdd = param.Substring(currentPrefix.Length).Split('_')[0] + "_"; while (nodeToAdd.Length > 1 // While the currentPrefix is smaller than param