Skip to content

Commit 0e5691a

Browse files
authored
Feature: Added option to hide the Send To menu (#12674)
1 parent cea675e commit 0e5691a

File tree

10 files changed

+66
-23
lines changed

10 files changed

+66
-23
lines changed

src/Files.App/Helpers/ContextFlyoutItemHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Files.App.Commands;
5+
using Files.App.ServicesImplementation.Settings;
56
using Files.Backend.Helpers;
67
using Files.Backend.Services;
78
using Microsoft.UI.Xaml.Media.Imaging;
@@ -551,7 +552,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
551552
Tag = "SendTo",
552553
CollapseLabel = true,
553554
ShowInSearchPage = true,
554-
ShowItem = itemsSelected
555+
ShowItem = itemsSelected && userSettingsService.GeneralSettingsService.ShowSendToMenu
555556
},
556557
new ContextMenuFlyoutItemViewModel()
557558
{
@@ -567,7 +568,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
567568
}
568569
},
569570
ShowInSearchPage = true,
570-
ShowItem = itemsSelected
571+
ShowItem = itemsSelected && userSettingsService.GeneralSettingsService.ShowSendToMenu
571572
},
572573
new ContextMenuFlyoutItemViewModel()
573574
{

src/Files.App/Helpers/ShellContextMenuHelper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,13 @@ public static async Task LoadShellMenuItems(
264264
if (openWithItem is not null)
265265
shellMenuItems.Remove(openWithItem);
266266

267-
var sendToItem = showSendToMenu ? shellMenuItems.Where(x => (x.Tag as Win32ContextMenuItem)?.CommandString == "sendto").ToList().FirstOrDefault() : null;
268-
if (sendToItem is not null)
267+
var sendToItem = shellMenuItems.Where(x => (x.Tag as Win32ContextMenuItem)?.CommandString == "sendto").ToList().FirstOrDefault();
268+
if (sendToItem is not null &&
269+
(showSendToMenu || !UserSettingsService.GeneralSettingsService.ShowSendToMenu))
269270
shellMenuItems.Remove(sendToItem);
270271

272+
sendToItem = showSendToMenu && UserSettingsService.GeneralSettingsService.ShowSendToMenu ? sendToItem : null;
273+
271274
if (!UserSettingsService.GeneralSettingsService.MoveShellExtensionsToSubMenu)
272275
{
273276
var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(shellMenuItems);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ public bool ShowEditTagsMenu
186186
set => Set(value);
187187
}
188188

189+
public bool ShowSendToMenu
190+
{
191+
get => Get(true);
192+
set => Set(value);
193+
}
194+
189195
public bool ShowOpenInNewTab
190196
{
191197
get => Get(true);
@@ -246,6 +252,7 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
246252
case nameof(ShowFileTagsSection):
247253
case nameof(MoveShellExtensionsToSubMenu):
248254
case nameof(ShowEditTagsMenu):
255+
case nameof(ShowSendToMenu):
249256
case nameof(ShowOpenInNewTab):
250257
case nameof(ShowOpenInNewWindow):
251258
case nameof(ShowOpenInNewPane):

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,9 @@
23912391
<data name="ShowEditTagsMenu" xml:space="preserve">
23922392
<value>Show edit tags flyout</value>
23932393
</data>
2394+
<data name="ShowSendToMenu" xml:space="preserve">
2395+
<value>Show Send To menu</value>
2396+
</data>
23942397
<data name="ShowOpenInNewTab" xml:space="preserve">
23952398
<value>Show option to open folders in a new tab</value>
23962399
</data>

src/Files.App/UserControls/Widgets/FileTagsWidget.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
136136
{
137137
Text = "SendTo".GetLocalizedResource(),
138138
Tag = "SendToPlaceholder",
139-
ShowItem = !isFolder
139+
ShowItem = !isFolder && userSettingsService.GeneralSettingsService.ShowSendToMenu
140140
},
141141
new ContextMenuFlyoutItemViewModel()
142142
{

src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public sealed partial class RecentFilesWidget : HomePageWidget, IWidgetItemModel
4949

5050
private CancellationTokenSource refreshRecentsCTS;
5151

52+
private readonly IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
53+
5254
public string WidgetName => nameof(RecentFilesWidget);
5355

5456
public string AutomationProperties => "RecentFilesWidgetAutomationProperties/Name".GetLocalizedResource();
@@ -157,6 +159,7 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
157159
{
158160
Text = "SendTo".GetLocalizedResource(),
159161
Tag = "SendToPlaceholder",
162+
ShowItem = userSettingsService.GeneralSettingsService.ShowSendToMenu
160163
},
161164
new ContextMenuFlyoutItemViewModel()
162165
{
@@ -202,7 +205,7 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
202205
Tag = "ItemOverflow",
203206
IsEnabled = false,
204207
}
205-
};
208+
}.Where(x => x.ShowItem).ToList();
206209
}
207210

208211
public async Task RefreshWidget()

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,19 @@ public bool ShowOpenInNewTab
483483
}
484484
}
485485

486+
public bool ShowSendToMenu
487+
{
488+
get => UserSettingsService.GeneralSettingsService.ShowSendToMenu;
489+
set
490+
{
491+
if (value != UserSettingsService.GeneralSettingsService.ShowSendToMenu)
492+
{
493+
UserSettingsService.GeneralSettingsService.ShowSendToMenu = value;
494+
OnPropertyChanged();
495+
}
496+
}
497+
}
498+
486499
public bool ShowOpenInNewWindow
487500
{
488501
get => UserSettingsService.GeneralSettingsService.ShowOpenInNewWindow;

src/Files.App/Views/LayoutModes/BaseLayout.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
using CommunityToolkit.WinUI.UI;
55
using Files.App.Filesystem.StorageItems;
66
using Files.App.Helpers.ContextFlyouts;
7-
using Files.App.UserControls;
87
using Files.App.UserControls.Menus;
9-
using Files.App.Views;
108
using Microsoft.UI.Xaml;
119
using Microsoft.UI.Xaml.Controls;
1210
using Microsoft.UI.Xaml.Controls.Primitives;
@@ -809,26 +807,29 @@ private async Task AddShellMenuItemsAsync(List<ContextMenuFlyoutItemViewModel> s
809807
}
810808

811809
// Add items to sendto dropdown
812-
var sendToOverflow = contextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton abb && (abb.Tag as string) == "SendToOverflow") as AppBarButton;
813-
814-
var sendTo = contextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton abb && (abb.Tag as string) == "SendTo") as AppBarButton;
815-
if (sendToMenuItem?.LoadSubMenuAction is not null && sendToOverflow is not null && sendTo is not null)
810+
if (UserSettingsService.GeneralSettingsService.ShowSendToMenu)
816811
{
817-
await sendToMenuItem.LoadSubMenuAction();
818-
var sendToSubItems = ItemModelListToContextFlyoutHelper.GetMenuFlyoutItemsFromModel(ShellContextmenuHelper.GetSendToItems(shellMenuItems));
812+
var sendToOverflow = contextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton abb && (abb.Tag as string) == "SendToOverflow") as AppBarButton;
819813

820-
if (sendToSubItems is not null)
814+
var sendTo = contextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton abb && (abb.Tag as string) == "SendTo") as AppBarButton;
815+
if (sendToMenuItem?.LoadSubMenuAction is not null && sendToOverflow is not null && sendTo is not null)
821816
{
822-
var flyout = (MenuFlyout)sendToOverflow.Flyout;
817+
await sendToMenuItem.LoadSubMenuAction();
818+
var sendToSubItems = ItemModelListToContextFlyoutHelper.GetMenuFlyoutItemsFromModel(ShellContextmenuHelper.GetSendToItems(shellMenuItems));
823819

824-
flyout.Items.Clear();
820+
if (sendToSubItems is not null)
821+
{
822+
var flyout = (MenuFlyout)sendToOverflow.Flyout;
825823

826-
foreach (var item in sendToSubItems)
827-
flyout.Items.Add(item);
824+
flyout.Items.Clear();
825+
826+
foreach (var item in sendToSubItems)
827+
flyout.Items.Add(item);
828828

829-
sendToOverflow.Flyout = flyout;
830-
sendTo.Visibility = Visibility.Collapsed;
831-
sendToOverflow.Visibility = Visibility.Visible;
829+
sendToOverflow.Flyout = flyout;
830+
sendTo.Visibility = Visibility.Collapsed;
831+
sendToOverflow.Visibility = Visibility.Visible;
832+
}
832833
}
833834
}
834835

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@
284284
IsOn="{x:Bind ViewModel.ShowEditTagsMenu, Mode=TwoWay}"
285285
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
286286
</local:SettingsBlockControl>
287+
288+
<!-- Send To -->
289+
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowSendToMenu}" HorizontalAlignment="Stretch">
290+
<ToggleSwitch
291+
AutomationProperties.Name="{helpers:ResourceString Name=ShowSendToMenu}"
292+
IsOn="{x:Bind ViewModel.ShowSendToMenu, Mode=TwoWay}"
293+
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
294+
</local:SettingsBlockControl>
287295
</StackPanel>
288296
</local:SettingsBlockControl.ExpandableContent>
289297
</local:SettingsBlockControl>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,16 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
159159
/// </summary>
160160
bool ShowOpenInNewWindow { get; set; }
161161

162-
163162
/// <summary>
164163
/// Gets or sets a value indicating whether or not to show the option to open folders in a new pane.
165164
/// </summary>
166165
bool ShowOpenInNewPane { get; set; }
167166

167+
/// <summary>
168+
/// Gets or sets a value indicating whether or not to show the Send To menu.
169+
/// </summary>
170+
bool ShowSendToMenu { get; set; }
171+
168172
/// <summary>
169173
/// Gets or sets a value indicating the default option to resolve conflicts.
170174
/// </summary>

0 commit comments

Comments
 (0)