Skip to content

Commit 390960d

Browse files
committed
enable tagging in multi selection mode
1 parent f76d6ae commit 390960d

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

Rememory/ViewModels/ClipboardRootPageViewModel.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,14 +836,15 @@ private void AddOwnerToFilters(OwnerModel? owner)
836836
}
837837

838838
[RelayCommand]
839-
private void ToggleClipTag(Tuple<ClipModel, TagModel>? clipTagData)
839+
private void ToggleClipTag(Tuple<ClipModel, TagModel, bool>? clipTagData)
840840
{
841841
if (clipTagData is null) return;
842842

843843
var clip = clipTagData.Item1;
844844
var tag = clipTagData.Item2;
845+
var isChecked = clipTagData.Item3;
845846

846-
if (clip.Tags.Contains(tag))
847+
if (isChecked)
847848
{
848849
_tagService.RemoveClipFromTag(tag, clip);
849850
}
@@ -953,7 +954,8 @@ private void DeleteClips(IEnumerable<ClipModel>? clips)
953954
}
954955

955956
private bool CanAddOwnersToFilters(IEnumerable<ClipModel>? clips) => clips is not null
956-
&& clips.Any(clip => !string.IsNullOrEmpty(clip.Owner?.Path) && !clip.Owner.Path.EndsWith("svchost.exe")); // check svchost.exe for UWP app sources
957+
&& clips.Any(clip => !string.IsNullOrEmpty(clip.Owner?.Path)
958+
&& !clip.Owner.Path.EndsWith("svchost.exe")); // check svchost.exe for UWP app sources
957959

958960
[RelayCommand(CanExecute = nameof(CanAddOwnersToFilters))]
959961
private void AddOwnersToFilters(IEnumerable<ClipModel>? clips)
@@ -966,6 +968,28 @@ private void AddOwnersToFilters(IEnumerable<ClipModel>? clips)
966968
}
967969
}
968970

971+
[RelayCommand]
972+
private void ToggleClipsTag(Tuple<IEnumerable<ClipModel>, TagModel, bool>? clipsTagData)
973+
{
974+
if (clipsTagData is null) return;
975+
976+
var clips = clipsTagData.Item1;
977+
var tag = clipsTagData.Item2;
978+
var isChecked = clipsTagData.Item3;
979+
980+
foreach (var clip in clips)
981+
{
982+
if (isChecked)
983+
{
984+
_tagService.RemoveClipFromTag(tag, clip);
985+
}
986+
else
987+
{
988+
_tagService.AddClipToTag(tag, clip);
989+
}
990+
}
991+
}
992+
969993
private void PasteClipsAsCombinedText(IEnumerable<ClipModel> clips, [Optional] TextCaseType? caseType)
970994
{
971995
var filteredClips = clips.Where(clip => clip.Data.ContainsKey(ClipboardFormat.Text)).ToArray();

Rememory/Views/ClipboardRootPage.xaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,14 @@
672672
CommandParameter="{Binding}"
673673
Command="{x:Bind ViewModel.DeleteClipCommand}"
674674
Icon="{tk:FontIcon Glyph=&#xE74D;}" />
675-
<MenuFlyoutSeparator />
676-
<MenuFlyoutSubItem x:Uid="/Clipboard/Clip_ContextMenu_Tags"
675+
<MenuFlyoutSeparator x:Name="ClipMenuFlyoutBottomSeparator" />
676+
<MenuFlyoutSubItem x:Name="TagsClipMenuFlyoutItem"
677+
x:Uid="/Clipboard/Clip_ContextMenu_Tags"
677678
Icon="{tk:FontIcon Glyph=&#xE8EC;}"
678679
Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource BoolToVisibilityConverter}}"
679680
Loaded="MenuFlyoutTags_Loaded" />
680-
<MenuFlyoutItem x:Uid="/Clipboard/Clip_ContextMenu_FilterSource"
681+
<MenuFlyoutItem x:Name="FilterClipMenuFlyoutItem"
682+
x:Uid="/Clipboard/Clip_ContextMenu_FilterSource"
681683
CommandParameter="{Binding Owner}"
682684
Command="{x:Bind ViewModel.AddOwnerToFiltersCommand}"
683685
Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource BoolToVisibilityConverter}}"
@@ -737,7 +739,12 @@
737739
CommandParameter="{x:Bind OrderedSelectedClips, Mode=OneWay}"
738740
Command="{x:Bind ViewModel.DeleteClipsCommand}"
739741
Icon="{tk:FontIcon Glyph=&#xE74D;}" />
740-
<MenuFlyoutSeparator Visibility="{Binding Visibility, ElementName=FilterClipsMenuFlyoutItem}" />
742+
<MenuFlyoutSeparator x:Name="ClipsMenuFlyoutBottomSeparator" />
743+
<MenuFlyoutSubItem x:Name="TagsClipsMenuFlyoutItem"
744+
x:Uid="/Clipboard/Clip_ContextMenu_Tags"
745+
Icon="{tk:FontIcon Glyph=&#xE8EC;}"
746+
Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource BoolToVisibilityConverter}}"
747+
Loaded="MenuFlyoutTags_Loaded" />
741748
<MenuFlyoutItem x:Name="FilterClipsMenuFlyoutItem"
742749
x:Uid="/Clipboard/Clip_ContextMenu_FilterSource"
743750
CommandParameter="{x:Bind OrderedSelectedClips, Mode=OneWay}"

Rememory/Views/ClipboardRootPage.xaml.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,37 @@ private void MenuFlyoutTags_Loaded(object sender, RoutedEventArgs e)
306306

307307
foreach (var tag in tags)
308308
{
309-
menuItem.Items.Add(new ToggleMenuFlyoutItem()
309+
var tagItem = new ToggleMenuFlyoutItem()
310310
{
311311
Text = tag.Name,
312-
IsChecked = clip.Tags.Contains(tag),
313-
Command = ViewModel.ToggleClipTagCommand,
314-
CommandParameter = new Tuple<ClipModel, TagModel>(clip, tag),
315312
Icon = new FontIcon() { Glyph = "\uEA3B", Foreground = tag.ColorBrush }
316-
});
313+
};
314+
315+
if (ClipsListView.SelectionMode == ListViewSelectionMode.None
316+
|| ClipsListView.SelectionMode == ListViewSelectionMode.Multiple && !OrderedSelectedClips.Contains(clip))
317+
{
318+
tagItem.IsChecked = clip.Tags.Contains(tag);
319+
tagItem.Command = ViewModel.ToggleClipTagCommand;
320+
tagItem.CommandParameter = new Tuple<ClipModel, TagModel, bool>(clip, tag, tagItem.IsChecked);
321+
}
322+
else if (ClipsListView.SelectionMode == ListViewSelectionMode.Multiple)
323+
{
324+
tagItem.IsChecked = OrderedSelectedClips.All(clip => clip.Tags.Contains(tag));
325+
tagItem.Command = ViewModel.ToggleClipsTagCommand;
326+
tagItem.CommandParameter = new Tuple<IEnumerable<ClipModel>, TagModel, bool>(OrderedSelectedClips, tag, tagItem.IsChecked);
327+
}
328+
329+
menuItem.Items.Add(tagItem);
330+
}
331+
332+
// Toggle bottom separator item visibility
333+
if (ClipsListView.SelectionMode == ListViewSelectionMode.None)
334+
{
335+
ClipMenuFlyoutBottomSeparator.Visibility = menuItem.IsEnabled || FilterClipMenuFlyoutItem.IsEnabled ? Visibility.Visible : Visibility.Collapsed;
336+
}
337+
else
338+
{
339+
ClipsMenuFlyoutBottomSeparator.Visibility = menuItem.IsEnabled || FilterClipsMenuFlyoutItem.IsEnabled ? Visibility.Visible : Visibility.Collapsed;
317340
}
318341
}
319342

0 commit comments

Comments
 (0)