Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ internal class DeleteEntryCommand : IUiCommand
{
public void Execute(MetaDataEditorViewModel controller)
{
var itemToRemove = controller.SelectedAttribute;
if (itemToRemove == null || controller.ParsedFile == null)
return;
if (controller.ParsedFile == null) return;

// Get all selected items from the UI tags
var itemsToRemove = controller.Tags
.Where(x => x.IsSelected)
.Select(x => x._input)
.ToList();

if (!itemsToRemove.Any()) return;

// Batch remove all selected tags
foreach (var item in itemsToRemove)
{
controller.ParsedFile.Attributes.Remove(item);
}

controller.ParsedFile.Attributes.Remove(itemToRemove);
controller.UpdateView();

// Select the first item by default after deletion
controller.SelectedTag = controller.Tags.FirstOrDefault();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,96 @@ internal class MoveEntryCommand : IUiCommand
{
public void ExecuteUp(MetaDataEditorViewModel controller)
{
var itemToMove = controller.SelectedAttribute;
if (itemToMove == null || controller.ParsedFile == null)
return;

var currentIndex = controller.ParsedFile.Attributes.IndexOf(itemToMove);
if (currentIndex == 0)
return;

controller.ParsedFile.Attributes.Remove(itemToMove);
controller.ParsedFile.Attributes.Insert(currentIndex - 1, itemToMove);
controller.UpdateView();
controller.SelectedTag = controller.Tags
.Where(x => x._input == itemToMove)
.FirstOrDefault();
if (controller.ParsedFile == null) return;

var itemsToMove = controller.Tags
.Where(x => x.IsSelected)
.Select(x => x._input)
.ToList();

if (!itemsToMove.Any()) return;

var attributes = controller.ParsedFile.Attributes;

// Sort ascending to move top items first, preventing them from jumping over each other
var sortedItems = itemsToMove.OrderBy(x => attributes.IndexOf(x)).ToList();
bool moved = false;

foreach (var item in sortedItems)
{
var currentIndex = attributes.IndexOf(item);
if (currentIndex > 0)
{
// If the item above is also in the selection, keep them as a block
var itemAbove = attributes[currentIndex - 1];
if (!itemsToMove.Contains(itemAbove))
{
attributes.RemoveAt(currentIndex);
attributes.Insert(currentIndex - 1, item);
moved = true;
}
}
}

if (moved)
{
controller.UpdateView();

// Restore selection state for the moved items
foreach (var tag in controller.Tags.Where(t => itemsToMove.Contains(t._input)))
{
tag.IsSelected = true;
}

controller.SelectedTag = controller.Tags.FirstOrDefault(x => x.IsSelected);
}
}

public void ExecuteDown(MetaDataEditorViewModel controller)
{
var itemToMove = controller.SelectedAttribute;
if (itemToMove == null || controller.ParsedFile == null)
return;
if (controller.ParsedFile == null) return;

var itemsToMove = controller.Tags
.Where(x => x.IsSelected)
.Select(x => x._input)
.ToList();

if (!itemsToMove.Any()) return;

var attributes = controller.ParsedFile.Attributes;

// Sort descending to move bottom items first
var sortedItems = itemsToMove.OrderByDescending(x => attributes.IndexOf(x)).ToList();
bool moved = false;

foreach (var item in sortedItems)
{
var currentIndex = attributes.IndexOf(item);
if (currentIndex < attributes.Count - 1)
{
// If the item below is also in the selection, keep them as a block
var itemBelow = attributes[currentIndex + 1];
if (!itemsToMove.Contains(itemBelow))
{
attributes.RemoveAt(currentIndex);
attributes.Insert(currentIndex + 1, item);
moved = true;
}
}
}

var currentIndex = controller.ParsedFile.Attributes.IndexOf(itemToMove);
if (currentIndex == controller.ParsedFile.Attributes.Count -1)
return;
if (moved)
{
controller.UpdateView();

controller.ParsedFile.Attributes.Remove(itemToMove);
controller.ParsedFile.Attributes.Insert(currentIndex + 1, itemToMove);
controller.UpdateView();
controller.SelectedTag = controller.Tags
.Where(x => x._input == itemToMove)
.FirstOrDefault();
// Restore selection state for the moved items
foreach (var tag in controller.Tags.Where(t => itemsToMove.Contains(t._input)))
{
tag.IsSelected = true;
}

controller.SelectedTag = controller.Tags.FirstOrDefault(x => x.IsSelected);
}
}
}
}
Loading