From 7919625ab427a96c41e6964c0613457e27f379b4 Mon Sep 17 00:00:00 2001 From: Jonko <69772986+jonko0493@users.noreply.github.com> Date: Tue, 20 Jun 2023 03:17:55 -0700 Subject: [PATCH] Fixup bad item renaming and command tree scrollbar bugs (#230) --- .../Controls/ScriptCommandSectionTree.cs | 20 +++++++++++++++++-- src/SerialLoops/MainForm.eto.cs | 4 ++-- src/SerialLoops/Utility/Shared.cs | 11 +++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/SerialLoops/Controls/ScriptCommandSectionTree.cs b/src/SerialLoops/Controls/ScriptCommandSectionTree.cs index ac9d6026..f9e22f66 100644 --- a/src/SerialLoops/Controls/ScriptCommandSectionTree.cs +++ b/src/SerialLoops/Controls/ScriptCommandSectionTree.cs @@ -2,12 +2,12 @@ using Eto.Drawing; using Eto.Forms; using HaruhiChokuretsuLib.Archive.Event; +using HaruhiChokuretsuLib.Util; +using SerialLoops.Editors; using SerialLoops.Lib.Script; using System; using System.Collections.Generic; using System.Linq; -using HaruhiChokuretsuLib.Util; -using SerialLoops.Editors; namespace SerialLoops.Controls { @@ -105,6 +105,7 @@ public class ScriptCommandSectionTreeGridView : SectionList { private TreeGridView _treeView; private ScriptCommandSectionTreeItem _cursorItem; + private bool _clickedOnCommand = false; public event EventHandler RepositionCommand; public event EventHandler DeleteCommand; public event EventHandler AddCommand; @@ -175,6 +176,8 @@ public ScriptCommandSectionTreeGridView(IEnumerable t _treeView.Size = size; SetContents(topNodes, expanded); + _treeView.MouseDown += OnMouseDown; + _treeView.MouseUp += OnMouseUp; _treeView.MouseMove += OnMouseMove; _treeView.DragOver += OnDragOver; _treeView.DragDrop += OnDragDrop; @@ -190,10 +193,23 @@ public ScriptCommandSectionTreeGridView(IEnumerable t }; } + private void OnMouseDown(object sender, MouseEventArgs e) + { + if (e.Buttons != MouseButtons.Primary) return; + if (_treeView.GetCellAt(e.Location).Item is not ScriptCommandSectionTreeItem { Parent: ScriptCommandSectionTreeItem parent } item) return; + _clickedOnCommand = true; + } + + private void OnMouseUp(object sender, MouseEventArgs e) + { + _clickedOnCommand = false; + } + private void OnMouseMove(object sender, MouseEventArgs e) { if (e.Buttons != MouseButtons.Primary) return; if (_treeView.GetCellAt(e.Location).Item is not ScriptCommandSectionTreeItem {Parent: ScriptCommandSectionTreeItem parent} item) return; + if (!_clickedOnCommand) return; _cursorItem = item; var data = new DataObject(); diff --git a/src/SerialLoops/MainForm.eto.cs b/src/SerialLoops/MainForm.eto.cs index 7f47d380..ef951fd1 100644 --- a/src/SerialLoops/MainForm.eto.cs +++ b/src/SerialLoops/MainForm.eto.cs @@ -620,7 +620,7 @@ private void SaveProject_Executed(object sender, EventArgs e) CharacterItem characterItem = (CharacterItem)item; if (characterItem.NameplateProperties.Name != item.DisplayName[4..]) { - Shared.RenameItem(OpenProject, ItemExplorer, EditorTabs, Log, + Shared.RenameItem(characterItem, OpenProject, ItemExplorer, EditorTabs, Log, $"CHR_{characterItem.NameplateProperties.Name}"); } @@ -648,7 +648,7 @@ private void SaveProject_Executed(object sender, EventArgs e) PlaceItem placeItem = (PlaceItem)item; if (placeItem.PlaceName != item.DisplayName[4..]) { - Shared.RenameItem(OpenProject, ItemExplorer, EditorTabs, Log, $"PLC_{placeItem.PlaceName}"); + Shared.RenameItem(placeItem, OpenProject, ItemExplorer, EditorTabs, Log, $"PLC_{placeItem.PlaceName}"); } MemoryStream placeStream = new(); diff --git a/src/SerialLoops/Utility/Shared.cs b/src/SerialLoops/Utility/Shared.cs index f2892b47..00871bd2 100644 --- a/src/SerialLoops/Utility/Shared.cs +++ b/src/SerialLoops/Utility/Shared.cs @@ -42,11 +42,20 @@ public static void RenameItem(Project project, ItemExplorerPanel explorer, Edito public static void RenameItem(Project project, ItemExplorerPanel explorer, EditorTabsPanel tabs, ILogger log, string newName) { ItemDescription item = project.FindItem(explorer.Viewer.SelectedItem?.Text); + RenameItem(item, project, explorer, tabs, log, newName); + } + public static void RenameItem(ItemDescription item, Project project, ItemExplorerPanel explorer, EditorTabsPanel tabs, ILogger log, string newName) + { if (item is not null) { + string oldName = item.DisplayName; DocumentPage openTab = tabs.Tabs.Pages.FirstOrDefault(p => p.Text == item.DisplayNameWithStatus); item.Rename(newName); - explorer.Viewer.SelectedItem.Text = item.DisplayName; + if (explorer.Viewer.SelectedItem.Text.Equals(oldName)) + { + // Unfortunately, there doesn't seem to be a good way to ensure the item gets rename if we've selected a different item + explorer.Viewer.SelectedItem.Text = item.DisplayName; + } if (openTab is not null) { openTab.Text = item.DisplayNameWithStatus;