Skip to content

Commit 5af9f59

Browse files
Feature: Added an option to manage tags when right clicking on the sidebar (#16475)
1 parent 7282b47 commit 5af9f59

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

src/Files.App/Actions/Open/OpenSettingsAction.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using Files.App.Dialogs;
5+
46
namespace Files.App.Actions
57
{
68
internal sealed class OpenSettingsAction : BaseUIAction, IAction
@@ -21,6 +23,9 @@ public HotKey HotKey
2123
public Task ExecuteAsync(object? parameter = null)
2224
{
2325
var dialog = dialogService.GetDialog(viewModel);
26+
if (parameter is not null && parameter is SettingsNavigationParams navParams)
27+
((SettingsDialog)dialog).NavigateTo(navParams);
28+
2429
return dialog.TryShowAsync();
2530
}
2631
}

src/Files.App/Data/Contracts/INavigationControlItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public sealed class ContextMenuOptions
4242
{
4343
public bool IsLibrariesHeader { get; set; }
4444

45+
public bool IsTagsHeader { get; set; }
46+
4547
public bool ShowHideSection { get; set; }
4648

4749
public bool IsLocationItem { get; set; }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Data.Parameters
5+
{
6+
public sealed class SettingsNavigationParams
7+
{
8+
public SettingsPageKind PageKind { get; set; }
9+
}
10+
}

src/Files.App/Dialogs/SettingsDialog.xaml.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Files.App.Views.Settings;
5-
using Files.App.ViewModels.Dialogs;
65
using Microsoft.UI.Xaml;
76
using Microsoft.UI.Xaml.Controls;
8-
using System;
9-
using System.Threading.Tasks;
10-
using Files.App.Data.Enums;
117
using Microsoft.UI.Xaml.Media.Animation;
128

139
namespace Files.App.Dialogs
@@ -32,6 +28,19 @@ public SettingsDialog()
3228
return (DialogResult)await base.ShowAsync();
3329
}
3430

31+
public void NavigateTo(SettingsNavigationParams navParams)
32+
{
33+
var defaultTag = SettingsPageKind.AppearancePage.ToString();
34+
var oldSelection = MainSettingsNavigationView.MenuItems.FirstOrDefault(item => ((NavigationViewItem)item).IsSelected) as NavigationViewItem;
35+
var targetSection = MainSettingsNavigationView.MenuItems.FirstOrDefault(
36+
item => Enum.Parse<SettingsPageKind>(((NavigationViewItem)item).Tag.ToString() ?? defaultTag) == navParams.PageKind
37+
);
38+
if (oldSelection is not null)
39+
oldSelection.IsSelected = false;
40+
41+
MainSettingsNavigationView.SelectedItem = targetSection;
42+
}
43+
3544
private void Current_SizeChanged(object sender, WindowSizeChangedEventArgs e)
3645
{
3746
UpdateDialogLayout();

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,4 +4001,7 @@
40014001
<data name="DataStreamsAreHiddenDescription" xml:space="preserve">
40024002
<value>Would you like to display alternate data streams? You can modify this setting anytime from the files and folders settings page.</value>
40034003
</data>
4004+
<data name="ManageTags" xml:space="preserve">
4005+
<value>Manage tags</value>
4006+
</data>
40044007
</root>

src/Files.App/ViewModels/UserControls/SidebarViewModel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ private async Task<LocationItem> CreateSectionAsync(SectionType sectionType)
551551
{
552552
break;
553553
}
554-
section = BuildSection("FileTags".GetLocalizedResource(), sectionType, new ContextMenuOptions { ShowHideSection = true }, false);
554+
section = BuildSection("FileTags".GetLocalizedResource(), sectionType, new ContextMenuOptions { IsTagsHeader = true, ShowHideSection = true }, false);
555555
icon = new BitmapImage(new Uri(Constants.FluentIconsPaths.FileTagsIcon));
556556
section.IsHeader = true;
557557
section.IsExpanded = UserSettingsService.GeneralSettingsService.IsFileTagsSectionExpanded;
@@ -1070,6 +1070,14 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
10701070
Tag = "ItemOverflow",
10711071
IsEnabled = false,
10721072
IsHidden = !options.ShowShellItems,
1073+
},
1074+
new ContextMenuFlyoutItemViewModel()
1075+
{
1076+
Text = "ManageTags".GetLocalizedResource(),
1077+
Glyph = "\uE8EC",
1078+
Command = Commands.OpenSettings,
1079+
CommandParameter = new SettingsNavigationParams() { PageKind = SettingsPageKind.TagsPage },
1080+
ShowItem = options.IsTagsHeader
10731081
}
10741082
}.Where(x => x.ShowItem).ToList();
10751083
}

0 commit comments

Comments
 (0)