Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Files.Launcher/MessageHandlers/ContextMenuHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private Func<string, bool> FilterMenuItems(bool showOpenMenu)
{
var knownItems = new List<string>()
{
"opennew", "openas", "opencontaining", "opennewprocess",
"opennew", "opencontaining", "opennewprocess",
"runas", "runasuser", "pintohome", "PinToStartScreen",
"cut", "copy", "paste", "delete", "properties", "link",
"Windows.ModernShare", "Windows.Share", "setdesktopwallpaper",
Expand Down
17 changes: 17 additions & 0 deletions Files/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ private async Task LoadMenuItemsAsync()

private void AddShellItemsToMenu(List<ContextMenuFlyoutItemViewModel> shellMenuItems, Microsoft.UI.Xaml.Controls.CommandBarFlyout contextMenuFlyout, bool shiftPressed)
{
var openWithSubItems = ItemModelListToContextFlyoutHelper.GetMenuFlyoutItemsFromModel(ShellContextmenuHelper.GetOpenWithItems(shellMenuItems));
var mainShellMenuItems = shellMenuItems.RemoveFrom(!App.AppSettings.MoveOverflowMenuItemsToSubMenu ? int.MaxValue : shiftPressed ? 6 : 4);
var overflowShellMenuItems = shellMenuItems.Except(mainShellMenuItems).ToList();

Expand Down Expand Up @@ -649,6 +650,22 @@ private void AddShellItemsToMenu(List<ContextMenuFlyoutItemViewModel> shellMenuI
overflowItem.Visibility = Visibility.Visible;
}
}

// add items to openwith dropdown
var openWithOverflow = contextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton abb && (abb.Tag as string) == "OpenWithOverflow") as AppBarButton;
if (openWithSubItems is not null && openWithOverflow is not null)
{
var openWith = contextMenuFlyout.SecondaryCommands.FirstOrDefault(x => x is AppBarButton abb && (abb.Tag as string) == "OpenWith") as AppBarButton;
var flyout = new MenuFlyout();
foreach (var item in openWithSubItems)
{
flyout.Items.Add(item);
}

openWithOverflow.Flyout = flyout;
openWith.Visibility = Visibility.Collapsed;
openWithOverflow.Visibility = Visibility.Visible;
}
}

protected virtual void Page_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
Expand Down
15 changes: 14 additions & 1 deletion Files/Helpers/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static async Task<List<ContextMenuFlyoutItemViewModel>> GetBaseContextShe
public static List<ContextMenuFlyoutItemViewModel> Filter(List<ContextMenuFlyoutItemViewModel> items, List<ListedItem> selectedItems, bool shiftPressed, CurrentInstanceViewModel currentInstanceViewModel, bool removeOverflowMenu = true)
{
items = items.Where(x => Check(item: x, currentInstanceViewModel: currentInstanceViewModel, selectedItems: selectedItems, shiftPressed: shiftPressed)).ToList();
items.ForEach(x => x.Items = x.Items.Where(y => Check(item: y, currentInstanceViewModel: currentInstanceViewModel, selectedItems: selectedItems, shiftPressed: shiftPressed)).ToList());
items.ForEach(x => x.Items = x.Items?.Where(y => Check(item: y, currentInstanceViewModel: currentInstanceViewModel, selectedItems: selectedItems, shiftPressed: shiftPressed)).ToList());

var overflow = items.Where(x => x.ID == "ItemOverflow").FirstOrDefault();
if (overflow != null)
Expand Down Expand Up @@ -478,6 +478,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseLayoutMenuItems(Curren
{
Text = "ContextMenuMoreItemsLabel".GetLocalized(),
Glyph = "\xE712",
Items = new List<ContextMenuFlyoutItemViewModel>(),
ID = "ItemOverflow",
Tag = "ItemOverflow",
IsHidden = true,
Expand Down Expand Up @@ -509,10 +510,21 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
Text = "BaseLayoutItemContextFlyoutOpenItemWith/Text".GetLocalized(),
Glyph = "\uE17D",
Command = commandsViewModel.OpenItemWithApplicationPickerCommand,
Tag = "OpenWith",
CollapseLabel = true,
ShowItem = selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.File && !i.IsShortcutItem),
},
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutItemContextFlyoutOpenItemWith/Text".GetLocalized(),
Glyph = "\uE17D",
Tag = "OpenWithOverflow",
IsHidden = true,
CollapseLabel = true,
Items = new List<ContextMenuFlyoutItemViewModel>(),
ShowItem = selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.File && !i.IsShortcutItem),
},
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutItemContextFlyoutOpenFileLocation/Text".GetLocalized(),
Glyph = "\uE8DA",
Expand Down Expand Up @@ -804,6 +816,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
{
Text = "ContextMenuMoreItemsLabel".GetLocalized(),
Glyph = "\xE712",
Items = new List<ContextMenuFlyoutItemViewModel>(),
ID = "ItemOverflow",
Tag = "ItemOverflow",
IsHidden = true,
Expand Down
11 changes: 8 additions & 3 deletions Files/Helpers/ItemModelListToContextFlyoutHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public static class ItemModelListToContextFlyoutHelper
{
public static List<MenuFlyoutItemBase> GetMenuFlyoutItemsFromModel(List<ContextMenuFlyoutItemViewModel> items)
{
if(items is null)
{
return null;
}

var flyout = new List<MenuFlyoutItemBase>();
items.ForEach(i =>
{
Expand Down Expand Up @@ -70,7 +75,7 @@ private static MenuFlyoutItemBase GetMenuFlyoutItem(ContextMenuFlyoutItemViewMod
Text = item.Text,
Tag = item.Tag,
};
item.Items.ForEach(i =>
item.Items?.ForEach(i =>
{
flyoutSubItem.Items.Add(GetMenuItem(i));
});
Expand Down Expand Up @@ -153,7 +158,7 @@ private static MenuFlyoutItemBase GetItem(ContextMenuFlyoutItemViewModel i)
return flyoutItem;
}

private static ICommandBarElement GetCommandBarItem(ContextMenuFlyoutItemViewModel item)
public static ICommandBarElement GetCommandBarItem(ContextMenuFlyoutItemViewModel item)
{
return item.ItemType switch
{
Expand Down Expand Up @@ -185,7 +190,7 @@ private static ICommandBarElement GetCommandBarButton(ContextMenuFlyoutItemViewM
}

MenuFlyout ctxFlyout = null;
if (item.Items.Count > 0 || item.ID == "ItemOverflow")
if ((item.Items is not null && item.Items.Count > 0) || item.ID == "ItemOverflow")
{
ctxFlyout = new MenuFlyout();
GetMenuFlyoutItemsFromModel(item.Items).ForEach(i => ctxFlyout.Items.Add(i));
Expand Down
8 changes: 8 additions & 0 deletions Files/Helpers/ShellContextMenuHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public static void LoadMenuFlyoutItem(IList<ContextMenuFlyoutItemViewModel> menu
{
Text = menuFlyoutItem.Label.Replace("&", ""),
Tag = (menuFlyoutItem, menuHandle),
Items = new List<ContextMenuFlyoutItemViewModel>(),
};
LoadMenuFlyoutItem(menuLayoutSubItem.Items, menuFlyoutItem.SubItems, menuHandle, showIcons);
menuItemsListLocal.Insert(0, menuLayoutSubItem);
Expand Down Expand Up @@ -162,5 +163,12 @@ await connection.SendMessageAsync(new ValueSet()
return (null, null);
}
}

public static List<ContextMenuFlyoutItemViewModel> GetOpenWithItems(List<ContextMenuFlyoutItemViewModel> flyout)
{
var item = flyout.FirstOrDefault(x => x.Tag is ValueTuple<Win32ContextMenuItem, string> vt && vt.Item1.CommandString == "openas");
flyout.Remove(item);
return item?.Items;
}
}
}
2 changes: 1 addition & 1 deletion Files/ViewModels/ContextMenuFlyoutItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ContextMenuFlyoutItemViewModel
public object Tag { get; set; }
public ItemType ItemType { get; set; }
public bool IsSubItem { get; set; }
public List<ContextMenuFlyoutItemViewModel> Items { get; set; } = new List<ContextMenuFlyoutItemViewModel>();
public List<ContextMenuFlyoutItemViewModel> Items { get; set; }
public BitmapImage BitmapIcon { get; set; }

/// <summary>
Expand Down