fix moving items in sln explorer
This commit is contained in:
@@ -326,18 +326,9 @@ public partial class SolutionExplorerPanel : MarginContainer
|
|||||||
newStartingIndex += folderCount;
|
newStartingIndex += folderCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
var treeParent = treeItem.GetParent()!;
|
|
||||||
await this.InvokeAsync(() =>
|
await this.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
// The API for moving TreeItems is painful - we can only move an Item before or after another item
|
treeItem.MoveToIndexInParent(oldStartingIndex, newStartingIndex);
|
||||||
treeParent.RemoveChild(treeItem);
|
|
||||||
var newItem = tree.CreateItem(treeParent, newStartingIndex);
|
|
||||||
newItem.SetText(0, treeItem.GetText(0));
|
|
||||||
newItem.SetIcon(0, treeItem.GetIcon(0));
|
|
||||||
newItem.SetMetadata(0, treeItem.GetMetadata(0));
|
|
||||||
if (isFile) newItem.SetCustomColor(0, treeItem.GetCustomColor(0));
|
|
||||||
treeItemContainer.Value = newItem;
|
|
||||||
treeItem.Free();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,17 @@ public static class NodeExtensions
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public void MoveToIndexInParent(int currentIndex, int newIndex)
|
||||||
|
{
|
||||||
|
var parent = treeItem.GetParent()!;
|
||||||
|
if (newIndex == currentIndex) throw new ArgumentException("New index is the same as current index", nameof(newIndex));
|
||||||
|
|
||||||
|
var target = parent.GetChild(newIndex);
|
||||||
|
if (newIndex < currentIndex)
|
||||||
|
treeItem.MoveBefore(target);
|
||||||
|
else
|
||||||
|
treeItem.MoveAfter(target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
extension(Node node)
|
extension(Node node)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user