Skip to content

Commit

Permalink
Feature: Added support for hiding more items from the context menu (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Jan 9, 2024
1 parent bd8f3b7 commit 9f26eb2
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 10 deletions.
13 changes: 8 additions & 5 deletions src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.ViewModels.Layouts;
using Files.Shared.Helpers;
using Files.App.Helpers.ContextFlyouts;
using Files.App.ViewModels.Layouts;
using Files.Shared.Helpers;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Imaging;
using System.IO;
Expand Down Expand Up @@ -452,15 +451,19 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.CopyPath)
{
IsVisible = itemsSelected && !currentInstanceViewModel.IsPageTypeRecycleBin,
IsVisible = userSettingsService.GeneralSettingsService.ShowCopyPath
&& itemsSelected
&&!currentInstanceViewModel.IsPageTypeRecycleBin,
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.CreateFolderWithSelection)
{
IsVisible = itemsSelected
IsVisible = userSettingsService.GeneralSettingsService.ShowCreateFolderWithSelection && itemsSelected
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.CreateShortcut)
{
IsVisible = itemsSelected && (!selectedItems.FirstOrDefault()?.IsShortcut ?? false)
IsVisible = userSettingsService.GeneralSettingsService.ShowCreateShortcut
&& itemsSelected
&& (!selectedItems.FirstOrDefault()?.IsShortcut ?? false)
&& !currentInstanceViewModel.IsPageTypeRecycleBin,
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.Rename)
Expand Down
22 changes: 22 additions & 0 deletions src/Files.App/Services/Settings/GeneralSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ public bool ShowOpenInNewPane
set => Set(value);
}

public bool ShowCopyPath
{
get => Get(true);
set => Set(value);
}

public bool ShowCreateFolderWithSelection
{
get => Get(true);
set => Set(value);
}

public bool ShowCreateShortcut
{
get => Get(true);
set => Set(value);
}

public bool LeaveAppRunning
{
#if STORE || STABLE || PREVIEW
Expand Down Expand Up @@ -273,6 +291,10 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
case nameof(ShowOpenInNewTab):
case nameof(ShowOpenInNewWindow):
case nameof(ShowOpenInNewPane):
case nameof(ShowCopyPath):
case nameof(ShowCreateFolderWithSelection):
case nameof(ShowCreateShortcut):
case nameof(ShowCompressionOptions):
case nameof(LeaveAppRunning):
case nameof(ConflictsResolveOption):
case nameof(ShowHashesDictionary):
Expand Down
11 changes: 10 additions & 1 deletion src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,15 @@
<data name="ShowOpenInNewPane" xml:space="preserve">
<value>Show option to open folders in a new pane</value>
</data>
<data name="ShowCopyPath" xml:space="preserve">
<value>Show option to copy path</value>
</data>
<data name="ShowCreateFolderWithSelection" xml:space="preserve">
<value>Show option to create folder with selection</value>
</data>
<data name="ShowCreateShortcut" xml:space="preserve">
<value>Show option to create shortcut</value>
</data>
<data name="NavigationToolbarNewPane.Label" xml:space="preserve">
<value>New pane</value>
</data>
Expand Down Expand Up @@ -2233,7 +2242,7 @@
<value>Show compression options</value>
</data>
<data name="ShowSendToMenu" xml:space="preserve">
<value>Show Send To menu</value>
<value>Show send to menu</value>
</data>
<data name="ShowOpenInNewTab" xml:space="preserve">
<value>Show option to open folders in a new tab</value>
Expand Down
42 changes: 42 additions & 0 deletions src/Files.App/ViewModels/Settings/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,48 @@ public bool ShowOpenInNewPane
}
}

public bool ShowCreateFolderWithSelection
{
get => UserSettingsService.GeneralSettingsService.ShowCreateFolderWithSelection;
set
{
if (value != UserSettingsService.GeneralSettingsService.ShowCreateFolderWithSelection)
{
UserSettingsService.GeneralSettingsService.ShowCreateFolderWithSelection = value;

OnPropertyChanged();
}
}
}

public bool ShowCopyPath
{
get => UserSettingsService.GeneralSettingsService.ShowCopyPath;
set
{
if (value != UserSettingsService.GeneralSettingsService.ShowCopyPath)
{
UserSettingsService.GeneralSettingsService.ShowCopyPath = value;

OnPropertyChanged();
}
}
}

public bool ShowCreateShortcut
{
get => UserSettingsService.GeneralSettingsService.ShowCreateShortcut;
set
{
if (value != UserSettingsService.GeneralSettingsService.ShowCreateShortcut)
{
UserSettingsService.GeneralSettingsService.ShowCreateShortcut = value;

OnPropertyChanged();
}
}
}

public bool AlwaysOpenDualPaneInNewTab
{
get => UserSettingsService.GeneralSettingsService.AlwaysOpenDualPaneInNewTab;
Expand Down
32 changes: 28 additions & 4 deletions src/Files.App/Views/Settings/GeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,27 @@
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>

<!-- Edit tags -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowEditTagsMenu}" HorizontalAlignment="Stretch">
<!-- Copy path -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowCopyPath}" HorizontalAlignment="Stretch">
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Name=ShowEditTagsMenu}"
IsOn="{x:Bind ViewModel.ShowEditTagsMenu, Mode=TwoWay}"
AutomationProperties.Name="{helpers:ResourceString Name=ShowCopyPath}"
IsOn="{x:Bind ViewModel.ShowCopyPath, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>

<!-- Create folder with selection -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowCreateFolderWithSelection}" HorizontalAlignment="Stretch">
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Name=ShowCreateFolderWithSelection}"
IsOn="{x:Bind ViewModel.ShowCreateFolderWithSelection, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>

<!-- Create shortcut -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowCreateShortcut}" HorizontalAlignment="Stretch">
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Name=ShowCreateShortcut}"
IsOn="{x:Bind ViewModel.ShowCreateShortcut, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>

Expand All @@ -309,6 +325,14 @@
IsOn="{x:Bind ViewModel.ShowSendToMenu, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>

<!-- Edit tags -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowEditTagsMenu}" HorizontalAlignment="Stretch">
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Name=ShowEditTagsMenu}"
IsOn="{x:Bind ViewModel.ShowEditTagsMenu, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>
</StackPanel>
</local:SettingsBlockControl.ExpandableContent>
</local:SettingsBlockControl>
Expand Down
15 changes: 15 additions & 0 deletions src/Files.Core/Services/Settings/IGeneralSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
/// </summary>
bool ShowOpenInNewPane { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to show the option to copy an items path.
/// </summary>
bool ShowCopyPath { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to show the option to create a shortcut.
/// </summary>
bool ShowCreateShortcut { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to show the option to create folder with selection.
/// </summary>
bool ShowCreateFolderWithSelection { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to show the compression options e.g. create archive, extract files.
/// </summary>
Expand Down

0 comments on commit 9f26eb2

Please sign in to comment.