Skip to content

Commit 9f26eb2

Browse files
authored
Feature: Added support for hiding more items from the context menu (#14408)
1 parent bd8f3b7 commit 9f26eb2

File tree

6 files changed

+125
-10
lines changed

6 files changed

+125
-10
lines changed

src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs

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

4-
using Files.App.ViewModels.Layouts;
5-
using Files.Shared.Helpers;
64
using Files.App.Helpers.ContextFlyouts;
75
using Files.App.ViewModels.Layouts;
6+
using Files.Shared.Helpers;
87
using Microsoft.UI.Xaml.Controls;
98
using Microsoft.UI.Xaml.Media.Imaging;
109
using System.IO;
@@ -452,15 +451,19 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
452451
}.Build(),
453452
new ContextMenuFlyoutItemViewModelBuilder(commands.CopyPath)
454453
{
455-
IsVisible = itemsSelected && !currentInstanceViewModel.IsPageTypeRecycleBin,
454+
IsVisible = userSettingsService.GeneralSettingsService.ShowCopyPath
455+
&& itemsSelected
456+
&&!currentInstanceViewModel.IsPageTypeRecycleBin,
456457
}.Build(),
457458
new ContextMenuFlyoutItemViewModelBuilder(commands.CreateFolderWithSelection)
458459
{
459-
IsVisible = itemsSelected
460+
IsVisible = userSettingsService.GeneralSettingsService.ShowCreateFolderWithSelection && itemsSelected
460461
}.Build(),
461462
new ContextMenuFlyoutItemViewModelBuilder(commands.CreateShortcut)
462463
{
463-
IsVisible = itemsSelected && (!selectedItems.FirstOrDefault()?.IsShortcut ?? false)
464+
IsVisible = userSettingsService.GeneralSettingsService.ShowCreateShortcut
465+
&& itemsSelected
466+
&& (!selectedItems.FirstOrDefault()?.IsShortcut ?? false)
464467
&& !currentInstanceViewModel.IsPageTypeRecycleBin,
465468
}.Build(),
466469
new ContextMenuFlyoutItemViewModelBuilder(commands.Rename)

src/Files.App/Services/Settings/GeneralSettingsService.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,24 @@ public bool ShowOpenInNewPane
217217
set => Set(value);
218218
}
219219

220+
public bool ShowCopyPath
221+
{
222+
get => Get(true);
223+
set => Set(value);
224+
}
225+
226+
public bool ShowCreateFolderWithSelection
227+
{
228+
get => Get(true);
229+
set => Set(value);
230+
}
231+
232+
public bool ShowCreateShortcut
233+
{
234+
get => Get(true);
235+
set => Set(value);
236+
}
237+
220238
public bool LeaveAppRunning
221239
{
222240
#if STORE || STABLE || PREVIEW
@@ -273,6 +291,10 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
273291
case nameof(ShowOpenInNewTab):
274292
case nameof(ShowOpenInNewWindow):
275293
case nameof(ShowOpenInNewPane):
294+
case nameof(ShowCopyPath):
295+
case nameof(ShowCreateFolderWithSelection):
296+
case nameof(ShowCreateShortcut):
297+
case nameof(ShowCompressionOptions):
276298
case nameof(LeaveAppRunning):
277299
case nameof(ConflictsResolveOption):
278300
case nameof(ShowHashesDictionary):

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,15 @@
10141014
<data name="ShowOpenInNewPane" xml:space="preserve">
10151015
<value>Show option to open folders in a new pane</value>
10161016
</data>
1017+
<data name="ShowCopyPath" xml:space="preserve">
1018+
<value>Show option to copy path</value>
1019+
</data>
1020+
<data name="ShowCreateFolderWithSelection" xml:space="preserve">
1021+
<value>Show option to create folder with selection</value>
1022+
</data>
1023+
<data name="ShowCreateShortcut" xml:space="preserve">
1024+
<value>Show option to create shortcut</value>
1025+
</data>
10171026
<data name="NavigationToolbarNewPane.Label" xml:space="preserve">
10181027
<value>New pane</value>
10191028
</data>
@@ -2233,7 +2242,7 @@
22332242
<value>Show compression options</value>
22342243
</data>
22352244
<data name="ShowSendToMenu" xml:space="preserve">
2236-
<value>Show Send To menu</value>
2245+
<value>Show send to menu</value>
22372246
</data>
22382247
<data name="ShowOpenInNewTab" xml:space="preserve">
22392248
<value>Show option to open folders in a new tab</value>

src/Files.App/ViewModels/Settings/GeneralViewModel.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,48 @@ public bool ShowOpenInNewPane
253253
}
254254
}
255255

256+
public bool ShowCreateFolderWithSelection
257+
{
258+
get => UserSettingsService.GeneralSettingsService.ShowCreateFolderWithSelection;
259+
set
260+
{
261+
if (value != UserSettingsService.GeneralSettingsService.ShowCreateFolderWithSelection)
262+
{
263+
UserSettingsService.GeneralSettingsService.ShowCreateFolderWithSelection = value;
264+
265+
OnPropertyChanged();
266+
}
267+
}
268+
}
269+
270+
public bool ShowCopyPath
271+
{
272+
get => UserSettingsService.GeneralSettingsService.ShowCopyPath;
273+
set
274+
{
275+
if (value != UserSettingsService.GeneralSettingsService.ShowCopyPath)
276+
{
277+
UserSettingsService.GeneralSettingsService.ShowCopyPath = value;
278+
279+
OnPropertyChanged();
280+
}
281+
}
282+
}
283+
284+
public bool ShowCreateShortcut
285+
{
286+
get => UserSettingsService.GeneralSettingsService.ShowCreateShortcut;
287+
set
288+
{
289+
if (value != UserSettingsService.GeneralSettingsService.ShowCreateShortcut)
290+
{
291+
UserSettingsService.GeneralSettingsService.ShowCreateShortcut = value;
292+
293+
OnPropertyChanged();
294+
}
295+
}
296+
}
297+
256298
public bool AlwaysOpenDualPaneInNewTab
257299
{
258300
get => UserSettingsService.GeneralSettingsService.AlwaysOpenDualPaneInNewTab;

src/Files.App/Views/Settings/GeneralPage.xaml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,27 @@
286286
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
287287
</local:SettingsBlockControl>
288288

289-
<!-- Edit tags -->
290-
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowEditTagsMenu}" HorizontalAlignment="Stretch">
289+
<!-- Copy path -->
290+
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowCopyPath}" HorizontalAlignment="Stretch">
291291
<ToggleSwitch
292-
AutomationProperties.Name="{helpers:ResourceString Name=ShowEditTagsMenu}"
293-
IsOn="{x:Bind ViewModel.ShowEditTagsMenu, Mode=TwoWay}"
292+
AutomationProperties.Name="{helpers:ResourceString Name=ShowCopyPath}"
293+
IsOn="{x:Bind ViewModel.ShowCopyPath, Mode=TwoWay}"
294+
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
295+
</local:SettingsBlockControl>
296+
297+
<!-- Create folder with selection -->
298+
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowCreateFolderWithSelection}" HorizontalAlignment="Stretch">
299+
<ToggleSwitch
300+
AutomationProperties.Name="{helpers:ResourceString Name=ShowCreateFolderWithSelection}"
301+
IsOn="{x:Bind ViewModel.ShowCreateFolderWithSelection, Mode=TwoWay}"
302+
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
303+
</local:SettingsBlockControl>
304+
305+
<!-- Create shortcut -->
306+
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowCreateShortcut}" HorizontalAlignment="Stretch">
307+
<ToggleSwitch
308+
AutomationProperties.Name="{helpers:ResourceString Name=ShowCreateShortcut}"
309+
IsOn="{x:Bind ViewModel.ShowCreateShortcut, Mode=TwoWay}"
294310
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
295311
</local:SettingsBlockControl>
296312

@@ -309,6 +325,14 @@
309325
IsOn="{x:Bind ViewModel.ShowSendToMenu, Mode=TwoWay}"
310326
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
311327
</local:SettingsBlockControl>
328+
329+
<!-- Edit tags -->
330+
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowEditTagsMenu}" HorizontalAlignment="Stretch">
331+
<ToggleSwitch
332+
AutomationProperties.Name="{helpers:ResourceString Name=ShowEditTagsMenu}"
333+
IsOn="{x:Bind ViewModel.ShowEditTagsMenu, Mode=TwoWay}"
334+
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
335+
</local:SettingsBlockControl>
312336
</StackPanel>
313337
</local:SettingsBlockControl.ExpandableContent>
314338
</local:SettingsBlockControl>

src/Files.Core/Services/Settings/IGeneralSettingsService.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
169169
/// </summary>
170170
bool ShowOpenInNewPane { get; set; }
171171

172+
/// <summary>
173+
/// Gets or sets a value indicating whether or not to show the option to copy an items path.
174+
/// </summary>
175+
bool ShowCopyPath { get; set; }
176+
177+
/// <summary>
178+
/// Gets or sets a value indicating whether or not to show the option to create a shortcut.
179+
/// </summary>
180+
bool ShowCreateShortcut { get; set; }
181+
182+
/// <summary>
183+
/// Gets or sets a value indicating whether or not to show the option to create folder with selection.
184+
/// </summary>
185+
bool ShowCreateFolderWithSelection { get; set; }
186+
172187
/// <summary>
173188
/// Gets or sets a value indicating whether or not to show the compression options e.g. create archive, extract files.
174189
/// </summary>

0 commit comments

Comments
 (0)