Skip to content

Feature: Context menu icons #11480

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

Merged
merged 16 commits into from
Feb 26, 2023
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
94 changes: 46 additions & 48 deletions src/Files.App/Helpers/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

namespace Files.App.Helpers
{
/// <summary>
/// Used to create lists of ContextMenuFlyoutItemViewModels that can be used by ItemModelListToContextFlyoutHelper to create context
/// menus and toolbars for the user.
/// <see cref="ContextMenuFlyoutItemViewModel"/>
/// <see cref="Files.App.Helpers.ContextFlyouts.ItemModelListToContextFlyoutHelper"/>
/// </summary>
public static class ContextFlyoutItemHelper
{
private static readonly IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
Expand Down Expand Up @@ -539,11 +545,9 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutContextFlyoutNew/Label".GetLocalizedResource(),
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseBackdropGlyph = "\uF051",
BaseLayerGlyph = "\uF037",
OverlayLayerGlyph = "\uF038"
OpacityIconStyle = "ColorIconNew",
},
KeyboardAccelerator = new KeyboardAccelerator
{
Expand Down Expand Up @@ -571,26 +575,31 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "RestoreAllItems".GetLocalizedResource(),
Glyph = "\xE777",
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconRestoreItem",
},
Command = commandsViewModel.RestoreRecycleBinCommand,
ShowItem = !itemsSelected && currentInstanceViewModel.IsPageTypeRecycleBin,
ShowInRecycleBin = true,
},
new ContextMenuFlyoutItemViewModel()
{
Text = "Restore".GetLocalizedResource(),
Glyph = "\xE777",
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconRestoreItem",
},
Command = commandsViewModel.RestoreItemCommand,
ShowInRecycleBin = true,
ShowItem = itemsSelected && selectedItems.All(x => x.IsRecycleBinItem)
},
new ContextMenuFlyoutItemViewModel()
{
Text = "Open".GetLocalizedResource(),
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseLayerGlyph = "\uF047",
OverlayLayerGlyph = "\uF048",
OpacityIconStyle = "ColorIconOpenFile"
},
Command = commandsViewModel.OpenItemCommand,
ShowInSearchPage = true,
Expand All @@ -601,10 +610,9 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutItemContextFlyoutOpenItemWith/Text".GetLocalizedResource(),
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseLayerGlyph = "\uF049",
OverlayLayerGlyph = "\uF04A",
OpacityIconStyle = "ColorIconOpenWith"
},
Command = commandsViewModel.OpenItemWithApplicationPickerCommand,
Tag = "OpenWith",
Expand All @@ -615,10 +623,9 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutItemContextFlyoutOpenItemWith/Text".GetLocalizedResource(),
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseLayerGlyph = "\uF049",
OverlayLayerGlyph = "\uF04A",
OpacityIconStyle = "ColorIconOpenWith"
},
Tag = "OpenWithOverflow",
IsHidden = true,
Expand All @@ -644,8 +651,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewTab".GetLocalizedResource(),
Glyph = "\uF113",
GlyphFontFamilyName = "CustomGlyph",
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenInNewTab"
},
Command = commandsViewModel.OpenDirectoryInNewTabCommand,
ShowItem = itemsSelected && selectedItems.Count < 5 && areAllItemsFolders && userSettingsService.PreferencesSettingsService.ShowOpenInNewTab,
ShowInSearchPage = true,
Expand All @@ -655,7 +664,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewWindow".GetLocalizedResource(),
Glyph = "\uE737",
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenInNewWindow"
},
Command = commandsViewModel.OpenInNewWindowItemCommand,
ShowItem = itemsSelected && selectedItems.Count < 5 && areAllItemsFolders && userSettingsService.PreferencesSettingsService.ShowOpenInNewWindow,
ShowInSearchPage = true,
Expand All @@ -665,11 +677,9 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewPane".GetLocalizedResource(),
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseBackdropGlyph = "\uF056",
BaseLayerGlyph = "\uF03B",
OverlayLayerGlyph = "\uF03C",
OpacityIconStyle = "ColorIconRightPane"
},
Command = commandsViewModel.OpenDirectoryInNewPaneCommand,
ShowItem = itemsSelected && userSettingsService.PreferencesSettingsService.ShowOpenInNewPane && areAllItemsFolders,
Expand Down Expand Up @@ -765,10 +775,9 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "BaseLayoutItemContextFlyoutCut/Text".GetLocalizedResource(),
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseLayerGlyph = "\uF03D",
OverlayLayerGlyph = "\uF03E",
OpacityIconStyle = "ColorIconCut",
},
Command = commandsViewModel.CutItemCommand,
IsPrimary = true,
Expand All @@ -786,11 +795,9 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "Copy".GetLocalizedResource(),
//Glyph = "\uF8C8",
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseLayerGlyph = "\uF021",
OverlayLayerGlyph = "\uF022",
OpacityIconStyle = "ColorIconCopy",
},
Command = commandsViewModel.CopyItemCommand,
ShowInRecycleBin = true,
Expand Down Expand Up @@ -824,13 +831,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "Paste".GetLocalizedResource(),
//Glyph = "\uF16D",
IsPrimary = true,
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseBackdropGlyph = "\uF052",
BaseLayerGlyph = "\uF023",
OverlayLayerGlyph = "\uF024",
OpacityIconStyle = "ColorIconPaste",
},
Command = commandsViewModel.PasteItemsFromClipboardCommand,
ShowItem = areAllItemsFolders || !itemsSelected,
Expand Down Expand Up @@ -874,11 +878,9 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
{
Text = "Rename".GetLocalizedResource(),
IsPrimary = true,
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseBackdropGlyph = "\uF054",
BaseLayerGlyph = "\uF027",
OverlayLayerGlyph = "\uF028",
OpacityIconStyle = "ColorIconRename",
},
Command = commandsViewModel.RenameItemCommand,
SingleItemOnly = true,
Expand All @@ -896,10 +898,9 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
{
Text = "BaseLayoutItemContextFlyoutShare/Text".GetLocalizedResource(),
IsPrimary = true,
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseLayerGlyph = "\uF025",
OverlayLayerGlyph = "\uF026",
OpacityIconStyle = "ColorIconShare",
},
Command = commandsViewModel.ShareItemCommand,
ShowItem = itemsSelected && DataTransferManager.IsSupported() && !selectedItems.Any(i => i.IsHiddenItem || (i.IsShortcut && !i.IsLinkItem) || (i.PrimaryItemAttribute == StorageItemTypes.Folder && !i.IsArchive)),
Expand All @@ -908,11 +909,9 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
{
Text = "Delete".GetLocalizedResource(),
IsPrimary = true,
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseBackdropGlyph = "\uF053",
BaseLayerGlyph = "\uF035",
OverlayLayerGlyph = "\uF036"
OpacityIconStyle = "ColorIconDelete",
},
Command = commandsViewModel.DeleteItemCommand,
ShowInRecycleBin = true,
Expand All @@ -930,10 +929,9 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
{
Text = "Properties".GetLocalizedResource(),
IsPrimary = true,
ColoredIcon = new ColoredIconModel()
OpacityIcon = new OpacityIconModel()
{
BaseLayerGlyph = "\uF031",
OverlayLayerGlyph = "\uF032"
OpacityIconStyle = "ColorIconProperties",
},
Command = commandsViewModel.ShowPropertiesCommand,
ShowInRecycleBin = true,
Expand Down
7 changes: 7 additions & 0 deletions src/Files.App/Helpers/ItemModelListToContextFlyoutHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

namespace Files.App.Helpers.ContextFlyouts
{
/// <summary>
/// This helper class is used to convert ContextMenuFlyoutItemViewModels into a control that can be displayed to the user.
/// This is for use in scenarios where XAML templates and data binding will not suffice.
/// <see cref="Files.App.ViewModels.ContextMenuFlyoutItemViewModel"/>
/// </summary>
public static class ItemModelListToContextFlyoutHelper
{
public static List<MenuFlyoutItemBase>? GetMenuFlyoutItemsFromModel(List<ContextMenuFlyoutItemViewModel>? items)
Expand Down Expand Up @@ -194,6 +199,8 @@ private static ICommandBarElement GetCommandBarButton(ContextMenuFlyoutItemViewM
};
else if (item.ColoredIcon.IsValid)
content = item.ColoredIcon.ToColoredIcon();
else if (item.OpacityIcon.IsValid)
content = item.OpacityIcon.ToOpacityIcon();
else if (item.ShowLoadingIndicator)
content = new ProgressRing()
{
Expand Down
Loading