Skip to content

Commit 97c66e7

Browse files
authored
Respect Move overflow items to a submenu setting on sidebar shell items (#6084)
1 parent 544aaae commit 97c66e7

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

Files/UserControls/SidebarControl.xaml.cs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Files.DataModels;
22
using Files.DataModels.NavigationControlItems;
3+
using Files.Extensions;
34
using Files.Filesystem;
45
using Files.Filesystem.StorageItems;
56
using Files.Helpers;
@@ -374,6 +375,12 @@ private void NavigationViewLocationItem_RightTapped(object sender, RightTappedRo
374375
RightClickedItem = item;
375376
var menuItems = GetLocationItemMenuItems();
376377
var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(menuItems);
378+
379+
if (!App.AppSettings.MoveOverflowMenuItemsToSubMenu)
380+
{
381+
secondaryElements.OfType<FrameworkElement>().ForEach(i => i.MinWidth = 250); // Set menu min width if the overflow menu setting is disabled
382+
}
383+
377384
secondaryElements.ForEach(i => itemContextMenuFlyout.SecondaryCommands.Add(i));
378385
itemContextMenuFlyout.ShowAt(sidebarItem, new Windows.UI.Xaml.Controls.Primitives.FlyoutShowOptions() { Position = e.GetPosition(sidebarItem) });
379386

@@ -420,6 +427,12 @@ private void NavigationViewDriveItem_RightTapped(object sender, RightTappedRoute
420427
RightClickedItem = item;
421428
var menuItems = GetLocationItemMenuItems();
422429
var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(menuItems);
430+
431+
if (!App.AppSettings.MoveOverflowMenuItemsToSubMenu)
432+
{
433+
secondaryElements.OfType<FrameworkElement>().ForEach(i => i.MinWidth = 250); // Set menu min width if the overflow menu setting is disabled
434+
}
435+
423436
secondaryElements.ForEach(i => itemContextMenuFlyout.SecondaryCommands.Add(i));
424437
itemContextMenuFlyout.ShowAt(sidebarItem, new Windows.UI.Xaml.Controls.Primitives.FlyoutShowOptions() { Position = e.GetPosition(sidebarItem) });
425438

@@ -963,12 +976,32 @@ private async void LoadShellMenuItems(Microsoft.UI.Xaml.Controls.CommandBarFlyou
963976
var shiftPressed = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
964977
var shellMenuItems = await ContextFlyoutItemHelper.GetItemContextShellCommandsAsync(connection: await AppServiceConnectionHelper.Instance, currentInstanceViewModel: null, workingDir: null,
965978
new List<ListedItem>() { new ListedItem(null) { ItemPath = RightClickedItem.Path } }, shiftPressed: shiftPressed, showOpenMenu: false);
966-
var overflowItems = ItemModelListToContextFlyoutHelper.GetMenuFlyoutItemsFromModel(shellMenuItems);
967-
var overflowItem = itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton appBarButton && (appBarButton.Tag as string) == "ItemOverflow") as AppBarButton;
968-
if (overflowItem is not null)
979+
if (!App.AppSettings.MoveOverflowMenuItemsToSubMenu)
980+
{
981+
var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(shellMenuItems);
982+
if (secondaryElements.Any())
983+
{
984+
var openedPopups = Windows.UI.Xaml.Media.VisualTreeHelper.GetOpenPopups(Window.Current);
985+
var secondaryMenu = openedPopups.FirstOrDefault(popup => popup.Name == "OverflowPopup");
986+
var itemsControl = secondaryMenu?.Child.FindDescendant<ItemsControl>();
987+
if (itemsControl is not null)
988+
{
989+
secondaryElements.OfType<FrameworkElement>().ForEach(x => x.MaxWidth = itemsControl.ActualWidth - 10); // Set items max width to current menu width (#5555)
990+
}
991+
992+
itemContextMenuFlyout.SecondaryCommands.Add(new AppBarSeparator());
993+
secondaryElements.ForEach(i => itemContextMenuFlyout.SecondaryCommands.Add(i));
994+
}
995+
}
996+
else
969997
{
970-
overflowItems.ForEach(i => (overflowItem.Flyout as MenuFlyout).Items.Add(i));
971-
overflowItem.Visibility = overflowItems.Any() ? Visibility.Visible : Visibility.Collapsed;
998+
var overflowItems = ItemModelListToContextFlyoutHelper.GetMenuFlyoutItemsFromModel(shellMenuItems);
999+
var overflowItem = itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton appBarButton && (appBarButton.Tag as string) == "ItemOverflow") as AppBarButton;
1000+
if (overflowItem is not null)
1001+
{
1002+
overflowItems.ForEach(i => (overflowItem.Flyout as MenuFlyout).Items.Add(i));
1003+
overflowItem.Visibility = overflowItems.Any() ? Visibility.Visible : Visibility.Collapsed;
1004+
}
9721005
}
9731006
}
9741007
}

0 commit comments

Comments
 (0)