Skip to content

Commit

Permalink
Don't select appended list items, except for profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Apr 7, 2024
1 parent a9b0d9d commit 7b9c64a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
11 changes: 6 additions & 5 deletions NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ private void Drop(object? sender, DropEventArgs e)
if (!NoUserProfiles)
{
_profileManager.Mutate(
new ListMutation<ScanProfile>.Append(data.ScanProfileXml.FromXml<ScanProfile>()), _listView);
new ListMutation<ScanProfile>.AppendAndSelect(data.ScanProfileXml.FromXml<ScanProfile>()),
_listView);
}
}
}
Expand Down Expand Up @@ -264,8 +265,8 @@ private async void DoScan()
{
return;
}
_profileManager.Mutate(new ListMutation<ScanProfile>.Append(editSettingsForm.ScanProfile),
ListSelection.Empty<ScanProfile>());
_profileManager.Mutate(new ListMutation<ScanProfile>.AppendAndSelect(editSettingsForm.ScanProfile),
_listView);
_profileManager.DefaultProfile = editSettingsForm.ScanProfile;
}
if (SelectedProfile == null)
Expand Down Expand Up @@ -293,7 +294,7 @@ private void DoAdd()
fedit.ShowModal();
if (fedit.Result)
{
_profileManager.Mutate(new ListMutation<ScanProfile>.Append(fedit.ScanProfile), _listView);
_profileManager.Mutate(new ListMutation<ScanProfile>.AppendAndSelect(fedit.ScanProfile), _listView);
}
}

Expand Down Expand Up @@ -355,7 +356,7 @@ private void DoPaste()
{
var data = _profileTransfer.GetFromClipboard();
var profile = data.ScanProfileXml.FromXml<ScanProfile>();
_profileManager.Mutate(new ListMutation<ScanProfile>.Append(profile), _listView);
_profileManager.Mutate(new ListMutation<ScanProfile>.AppendAndSelect(profile), _listView);
}
}

Expand Down
23 changes: 23 additions & 0 deletions NAPS2.Lib/Util/ListMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,29 @@ public Append(params T[] items)
_items = items.ToList();
}

public override void Apply(List<T> list, ref ListSelection<T> selection)
{
list.AddRange(_items);
}
}

/// <summary>
/// Appends the given item(s) to the end of the list and selects them.
/// </summary>
public class AppendAndSelect : ListMutation<T>
{
private readonly List<T> _items;

public AppendAndSelect(IEnumerable<T> items)
{
_items = items.ToList();
}

public AppendAndSelect(params T[] items)
{
_items = items.ToList();
}

public override void Apply(List<T> list, ref ListSelection<T> selection)
{
list.AddRange(_items);
Expand Down

0 comments on commit 7b9c64a

Please sign in to comment.