Skip to content

Commit

Permalink
Fixup bad item renaming and command tree scrollbar bugs (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Jun 20, 2023
1 parent f39f591 commit 7919625
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
20 changes: 18 additions & 2 deletions src/SerialLoops/Controls/ScriptCommandSectionTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<DeleteItemEventArgs> DeleteCommand;
public event EventHandler<CommandEventArgs> AddCommand;
Expand Down Expand Up @@ -175,6 +176,8 @@ public ScriptCommandSectionTreeGridView(IEnumerable<ScriptCommandSectionEntry> t
_treeView.Size = size;
SetContents(topNodes, expanded);

_treeView.MouseDown += OnMouseDown;
_treeView.MouseUp += OnMouseUp;
_treeView.MouseMove += OnMouseMove;
_treeView.DragOver += OnDragOver;
_treeView.DragDrop += OnDragDrop;
Expand All @@ -190,10 +193,23 @@ public ScriptCommandSectionTreeGridView(IEnumerable<ScriptCommandSectionEntry> 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();
Expand Down
4 changes: 2 additions & 2 deletions src/SerialLoops/MainForm.eto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}

Expand Down Expand Up @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion src/SerialLoops/Utility/Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7919625

Please sign in to comment.