From 7b9c64a9898f9020b8ee0dc9ed3b6df5b2b7a651 Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Sun, 7 Apr 2024 11:59:28 -0700 Subject: [PATCH] Don't select appended list items, except for profiles --- NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs | 11 ++++++----- NAPS2.Lib/Util/ListMutation.cs | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs b/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs index 427b5dc8f3..f8a2cd2e2c 100644 --- a/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs @@ -223,7 +223,8 @@ private void Drop(object? sender, DropEventArgs e) if (!NoUserProfiles) { _profileManager.Mutate( - new ListMutation.Append(data.ScanProfileXml.FromXml()), _listView); + new ListMutation.AppendAndSelect(data.ScanProfileXml.FromXml()), + _listView); } } } @@ -264,8 +265,8 @@ private async void DoScan() { return; } - _profileManager.Mutate(new ListMutation.Append(editSettingsForm.ScanProfile), - ListSelection.Empty()); + _profileManager.Mutate(new ListMutation.AppendAndSelect(editSettingsForm.ScanProfile), + _listView); _profileManager.DefaultProfile = editSettingsForm.ScanProfile; } if (SelectedProfile == null) @@ -293,7 +294,7 @@ private void DoAdd() fedit.ShowModal(); if (fedit.Result) { - _profileManager.Mutate(new ListMutation.Append(fedit.ScanProfile), _listView); + _profileManager.Mutate(new ListMutation.AppendAndSelect(fedit.ScanProfile), _listView); } } @@ -355,7 +356,7 @@ private void DoPaste() { var data = _profileTransfer.GetFromClipboard(); var profile = data.ScanProfileXml.FromXml(); - _profileManager.Mutate(new ListMutation.Append(profile), _listView); + _profileManager.Mutate(new ListMutation.AppendAndSelect(profile), _listView); } } diff --git a/NAPS2.Lib/Util/ListMutation.cs b/NAPS2.Lib/Util/ListMutation.cs index b81ca23cae..0025945719 100644 --- a/NAPS2.Lib/Util/ListMutation.cs +++ b/NAPS2.Lib/Util/ListMutation.cs @@ -432,6 +432,29 @@ public Append(params T[] items) _items = items.ToList(); } + public override void Apply(List list, ref ListSelection selection) + { + list.AddRange(_items); + } + } + + /// + /// Appends the given item(s) to the end of the list and selects them. + /// + public class AppendAndSelect : ListMutation + { + private readonly List _items; + + public AppendAndSelect(IEnumerable items) + { + _items = items.ToList(); + } + + public AppendAndSelect(params T[] items) + { + _items = items.ToList(); + } + public override void Apply(List list, ref ListSelection selection) { list.AddRange(_items);