Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Disable show more options menu item until shell items are loaded #11243

Merged
merged 14 commits into from
Feb 13, 2023
14 changes: 8 additions & 6 deletions src/Files.App/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,14 @@ private async Task LoadMenuItemsAsync()
shellContextMenuItemCancellationToken = new CancellationTokenSource();
SelectedItemsPropertiesViewModel.CheckAllFileExtensions(SelectedItems!.Select(selectedItem => selectedItem?.FileExtension).ToList()!);
var shiftPressed = Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down);
var items = ContextFlyoutItemHelper.GetItemContextCommandsWithoutShellItems(currentInstanceViewModel: InstanceViewModel!, selectedItems: SelectedItems!, selectedItemsPropertiesViewModel: SelectedItemsPropertiesViewModel, commandsViewModel: CommandsViewModel!, shiftPressed: shiftPressed);
var items = ContextFlyoutItemHelper.GetItemContextCommandsWithoutShellItems(currentInstanceViewModel: InstanceViewModel!, selectedItems: SelectedItems!, selectedItemsPropertiesViewModel: SelectedItemsPropertiesViewModel, commandsViewModel: CommandsViewModel!, shiftPressed: shiftPressed);
hecksmosis marked this conversation as resolved.
Show resolved Hide resolved
ItemContextMenuFlyout.PrimaryCommands.Clear();
ItemContextMenuFlyout.SecondaryCommands.Clear();
var (primaryElements, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(items);
AddCloseHandler(ItemContextMenuFlyout, primaryElements, secondaryElements);
primaryElements.ForEach(i => ItemContextMenuFlyout.PrimaryCommands.Add(i));
primaryElements.ForEach(ItemContextMenuFlyout.PrimaryCommands.Add);
hecksmosis marked this conversation as resolved.
Show resolved Hide resolved
secondaryElements.OfType<FrameworkElement>().ForEach(i => i.MinWidth = Constants.UI.ContextMenuItemsMaxWidth); // Set menu min width
secondaryElements.ForEach(i => ItemContextMenuFlyout.SecondaryCommands.Add(i));
secondaryElements.ForEach(ItemContextMenuFlyout.SecondaryCommands.Add);

if (InstanceViewModel!.CanTagFilesInPage)
AddNewFileTagsToMenu(ItemContextMenuFlyout);
Expand Down Expand Up @@ -692,10 +692,12 @@ private void AddShellItemsToMenu(List<ContextMenuFlyoutItemViewModel> shellMenuI
index++;
}

if (overflowItemFlyout.Items.Count > 0)
if (overflowItemFlyout.Items.Count > 0 && UserSettingsService.AppearanceSettingsService.MoveShellExtensionsToSubMenu)
{
overflowItem.IsEnabled = true;
} else if (!UserSettingsService.AppearanceSettingsService.MoveShellExtensionsToSubMenu)
{
(contextMenuFlyout.SecondaryCommands.First(x => x is FrameworkElement fe && fe.Tag as string == "OverflowSeparator") as AppBarSeparator)!.Visibility = Visibility.Visible;
overflowItem.Visibility = Visibility.Visible;
overflowItem.Visibility = Visibility.Collapsed;
hecksmosis marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Files.App/Helpers/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,6 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
ItemType = ItemType.Separator,
Tag = "OverflowSeparator",
ShowInSearchPage = true,
IsHidden = true,
},
new ContextMenuFlyoutItemViewModel()
{
Expand All @@ -1116,7 +1115,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
ID = "ItemOverflow",
Tag = "ItemOverflow",
ShowInSearchPage = true,
IsHidden = true,
IsEnabled = false
},
};
}
Expand Down
62 changes: 61 additions & 1 deletion src/Files.App/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
Items = new List<ContextMenuFlyoutItemViewModel>(),
ID = "ItemOverflow",
Tag = "ItemOverflow",
IsHidden = true,
IsEnabled = false,
}
}.Where(x => x.ShowItem).ToList();
}
Expand Down Expand Up @@ -936,6 +936,66 @@ private void ResizeElementBorder_ManipulationStarted(object sender, Manipulation
dragging = true;
}

private async void LoadShellMenuItems(CommandBarFlyout itemContextMenuFlyout, ContextMenuOptions options)
{
try
{
if (options.ShowEmptyRecycleBin)
{
var emptyRecycleBinItem = itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton appBarButton && (appBarButton.Tag as string) == "EmptyRecycleBin") as AppBarButton;
if (emptyRecycleBinItem is not null)
{
var binHasItems = RecycleBinHelpers.RecycleBinHasItems();
hecksmosis marked this conversation as resolved.
Show resolved Hide resolved
emptyRecycleBinItem.IsEnabled = binHasItems;
}
}

if (!options.IsLocationItem)
return;

var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
var shellMenuItems = await ContextFlyoutItemHelper.GetItemContextShellCommandsAsync(workingDir: null,
new List<ListedItem>() { new ListedItem(null) { ItemPath = rightClickedItem.Path } }, shiftPressed: shiftPressed, showOpenMenu: false, default);
if (!userSettingsService.AppearanceSettingsService.MoveShellExtensionsToSubMenu)
{
if (itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton appBarButton && (appBarButton.Tag as string) == "ItemOverflow") is not AppBarButton overflowItem)
return;
overflowItem.Visibility = Visibility.Collapsed;

var (_, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(shellMenuItems);
if (!secondaryElements.Any())
return;

var openedPopups = Microsoft.UI.Xaml.Media.VisualTreeHelper.GetOpenPopups(App.Window);
var secondaryMenu = openedPopups.FirstOrDefault(popup => popup.Name == "OverflowPopup");

var itemsControl = secondaryMenu?.Child.FindDescendant<ItemsControl>();
if (itemsControl is not null)
{
var maxWidth = itemsControl.ActualWidth - Constants.UI.ContextMenuLabelMargin;
secondaryElements.OfType<FrameworkElement>()
.ForEach(x => x.MaxWidth = maxWidth); // Set items max width to current menu width (#5555)
}

itemContextMenuFlyout.SecondaryCommands.Add(new AppBarSeparator());
secondaryElements.ForEach(itemContextMenuFlyout.SecondaryCommands.Add);
}
else
{
var overflowItems = ItemModelListToContextFlyoutHelper.GetMenuFlyoutItemsFromModel(shellMenuItems);
if (itemContextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton appBarButton && (appBarButton.Tag as string) == "ItemOverflow") is not AppBarButton overflowItem)
return;

var flyoutItems = (overflowItem.Flyout as MenuFlyout)?.Items;
if (flyoutItems is not null)
overflowItems.ForEach(flyoutItems.Add);
overflowItem.IsEnabled = overflowItems.Any();
overflowItem.Visibility = overflowItems.Any() ? Visibility.Visible : Visibility.Collapsed;
}
}
catch { }
}

public static GridLength GetSidebarCompactSize()
{
return App.Current.Resources.TryGetValue("NavigationViewCompactPaneLength", out object paneLength) && paneLength is double paneLengthDouble
Expand Down