From 23d318808126ef74237e2725cb2621977051303e Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:44:58 -0500 Subject: [PATCH 1/4] Fix: Fixed NullReferenceException in Item_Opening --- src/Files.App/UserControls/Menus/FileTagsContextMenu.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs b/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs index ce997845d308..97f97b70aa15 100644 --- a/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs +++ b/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs @@ -62,7 +62,7 @@ private void TagItem_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) } } - private void Item_Opening(object sender, object e) + private void Item_Opening(object? sender, object e) { Opening -= Item_Opening; From 56613146845041071ac108ead3f48017c51471fc Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sun, 11 Feb 2024 22:39:20 -0500 Subject: [PATCH 2/4] Update FileTagsContextMenu.cs --- .../UserControls/Menus/FileTagsContextMenu.cs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs b/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs index 97f97b70aa15..222b869f3538 100644 --- a/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs +++ b/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs @@ -1,20 +1,11 @@ // Copyright (c) 2023 Files Community // Licensed under the MIT License. See the LICENSE. -using CommunityToolkit.Mvvm.DependencyInjection; -using Files.App.Utils; -using Files.App.Helpers; -using Files.Core.Services.Settings; -using Files.Core.ViewModels.FileTags; -using Files.Shared.Extensions; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Markup; using Microsoft.UI.Xaml.Media; -using System; -using System.Collections.Generic; -using System.Linq; using static Files.App.Helpers.MenuFlyoutHelper; -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Markup; namespace Files.App.UserControls.Menus { @@ -46,7 +37,8 @@ public FileTagsContextMenu(IEnumerable selectedItems) SelectedItems = selectedItems; - Opening += Item_Opening; + if (SelectedItems is not null) + Opening += Item_Opening; } private void TagItem_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) From ac8c1f5b35fca81afdbd2758c5340408553575c6 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:54:02 -0500 Subject: [PATCH 3/4] Update FileTagsContextMenu.cs --- .../UserControls/Menus/FileTagsContextMenu.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs b/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs index 222b869f3538..e7338aee4cab 100644 --- a/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs +++ b/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs @@ -37,8 +37,7 @@ public FileTagsContextMenu(IEnumerable selectedItems) SelectedItems = selectedItems; - if (SelectedItems is not null) - Opening += Item_Opening; + Opening += Item_Opening; } private void TagItem_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) @@ -58,11 +57,14 @@ private void Item_Opening(object? sender, object e) { Opening -= Item_Opening; + if (SelectedItems is null) + return; + // go through each tag and find the common one for all files var commonFileTags = SelectedItems - .Select(x => x.FileTags ?? Enumerable.Empty()) - .Aggregate((x, y) => x.Intersect(y)) - .Select(x => Items.FirstOrDefault(y => x == ((TagViewModel)y.Tag)?.Uid)); + .Select(x => x.FileTags ?? Enumerable.Empty()) + .Aggregate((x, y) => x.Intersect(y)) + .Select(x => Items.FirstOrDefault(y => x == ((TagViewModel)y.Tag)?.Uid)); commonFileTags.OfType().ForEach(x => x.IsChecked = true); } From 96a5839fc13a7b834480837bdb8647af05358269 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:10:30 -0500 Subject: [PATCH 4/4] Update FileTagsContextMenu.cs --- src/Files.App/UserControls/Menus/FileTagsContextMenu.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs b/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs index e7338aee4cab..b5a43766dafb 100644 --- a/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs +++ b/src/Files.App/UserControls/Menus/FileTagsContextMenu.cs @@ -62,9 +62,9 @@ private void Item_Opening(object? sender, object e) // go through each tag and find the common one for all files var commonFileTags = SelectedItems - .Select(x => x.FileTags ?? Enumerable.Empty()) - .Aggregate((x, y) => x.Intersect(y)) - .Select(x => Items.FirstOrDefault(y => x == ((TagViewModel)y.Tag)?.Uid)); + .Select(x => x.FileTags ?? Enumerable.Empty()) + .Aggregate((x, y) => x.Intersect(y)) + .Select(x => Items.FirstOrDefault(y => x == ((TagViewModel)y.Tag)?.Uid)); commonFileTags.OfType().ForEach(x => x.IsChecked = true); }