Skip to content

Commit

Permalink
Revert "Code Quality: Improved the way of instancing OpacityIconModel" (
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Feb 1, 2024
1 parent 681b2d3 commit 6718879
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public ContextMenuFlyoutItemViewModel Build()
var glyph = command.Glyph;
if (!string.IsNullOrEmpty(glyph.OpacityStyle))
{
viewModel.OpacityIcon = new(glyph.OpacityStyle);
viewModel.OpacityIcon = new OpacityIconModel
{
OpacityIconStyle = glyph.OpacityStyle,
};
}
else
{
Expand Down
20 changes: 6 additions & 14 deletions src/Files.App/Data/Models/OpacityIconModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,19 @@

namespace Files.App.Data.Models
{
/// <summary>
/// Represents a model for <see cref="OpacityIcon"/>.
/// </summary>
public class OpacityIconModel
public struct OpacityIconModel
{
public string? OpacityIconStyle { get; set; }
public string OpacityIconStyle { get; set; }

public bool IsValid
=> !string.IsNullOrWhiteSpace(OpacityIconStyle);

public OpacityIconModel(string styleName)
{
OpacityIconStyle = styleName;
}

public OpacityIcon ToOpacityIcon()
public readonly OpacityIcon ToOpacityIcon()
{
return new()
{
Style = (Style)Application.Current.Resources[OpacityIconStyle],
};
}

public readonly bool IsValid
=> !string.IsNullOrEmpty(OpacityIconStyle);
}
}
25 changes: 20 additions & 5 deletions src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "SortBy".GetLocalizedResource(),
OpacityIcon = new("ColorIconSort"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconSort",
},
ShowItem = !itemsSelected,
ShowInRecycleBin = true,
ShowInSearchPage = true,
Expand Down Expand Up @@ -352,7 +355,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
},
new ContextMenuFlyoutItemViewModel()
{
OpacityIcon = new(commands.AddItem.Glyph.OpacityStyle),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = commands.AddItem.Glyph.OpacityStyle
},
Text = commands.AddItem.Label,
Items = GetNewItemItems(commandsViewModel, currentInstanceViewModel.CanCreateFileInPage),
ShowItem = !itemsSelected,
Expand All @@ -379,7 +385,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenWith".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenWith"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenWith"
},
Tag = "OpenWithOverflow",
IsHidden = true,
CollapseLabel = true,
Expand Down Expand Up @@ -503,7 +512,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
{
Text = "Compress".GetLocalizedResource(),
ShowInSearchPage = true,
OpacityIcon = new("ColorIconZip"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconZip",
},
Items = new List<ContextMenuFlyoutItemViewModel>
{
new ContextMenuFlyoutItemViewModelBuilder(commands.CompressIntoArchive).Build(),
Expand All @@ -516,7 +528,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
{
Text = "Extract".GetLocalizedResource(),
ShowInSearchPage = true,
OpacityIcon = new("ColorIconZip"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconZip",
},
Items = new List<ContextMenuFlyoutItemViewModel>
{
new ContextMenuFlyoutItemViewModelBuilder(commands.DecompressArchive).Build(),
Expand Down
5 changes: 4 additions & 1 deletion src/Files.App/Helpers/MenuFlyout/ShellContextMenuHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ x.Tag is Win32ContextMenuItem menuItem &&
{
await openWithItem.LoadSubMenuAction();

openWithItem.OpacityIcon = new("ColorIconOpenWith");
openWithItem.OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenWith",
};
var (_, openWithItems) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(new List<ContextMenuFlyoutItemViewModel>() { openWithItem });
var placeholder = itemContextMenuFlyout.SecondaryCommands.Where(x => Equals((x as AppBarButton)?.Tag, "OpenWithPlaceholder")).FirstOrDefault() as AppBarButton;
if (placeholder is not null)
Expand Down
25 changes: 20 additions & 5 deletions src/Files.App/UserControls/Widgets/DrivesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,21 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewTab".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenInNewTab"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenInNewTab",
},
Command = OpenInNewTabCommand,
CommandParameter = item,
ShowItem = userSettingsService.GeneralSettingsService.ShowOpenInNewTab
},
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewWindow".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenInNewWindow"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenInNewWindow",
},
Command = OpenInNewWindowCommand,
CommandParameter = item,
ShowItem = userSettingsService.GeneralSettingsService.ShowOpenInNewWindow
Expand All @@ -182,15 +188,21 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
Text = "PinToFavorites".GetLocalizedResource(),
OpacityIcon = new("ColorIconPinToFavorites"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconPinToFavorites",
},
Command = PinToFavoritesCommand,
CommandParameter = item,
ShowItem = !isPinned
},
new ContextMenuFlyoutItemViewModel()
{
Text = "UnpinFromFavorites".GetLocalizedResource(),
OpacityIcon = new("ColorIconUnpinFromFavorites"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconUnpinFromFavorites",
},
Command = UnpinFromFavoritesCommand,
CommandParameter = item,
ShowItem = isPinned
Expand All @@ -212,7 +224,10 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
Text = "Properties".GetLocalizedResource(),
OpacityIcon = new("ColorIconProperties"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconProperties",
},
Command = OpenPropertiesCommand,
CommandParameter = item
},
Expand Down
30 changes: 24 additions & 6 deletions src/Files.App/UserControls/Widgets/FileTagsWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenWith".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenWith"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenWith",
},
Tag = "OpenWithPlaceholder",
ShowItem = !isFolder
},
Expand All @@ -168,15 +171,21 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewTab".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenInNewTab"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenInNewTab",
},
Command = OpenInNewTabCommand,
CommandParameter = item,
ShowItem = isFolder
},
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewWindow".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenInNewWindow"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenInNewWindow",
},
Command = OpenInNewWindowCommand,
CommandParameter = item,
ShowItem = isFolder
Expand All @@ -199,23 +208,32 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
Text = "PinToFavorites".GetLocalizedResource(),
OpacityIcon = new("ColorIconPinToFavorites"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconPinToFavorites",
},
Command = PinToFavoritesCommand,
CommandParameter = item,
ShowItem = !isPinned && isFolder
},
new ContextMenuFlyoutItemViewModel()
{
Text = "UnpinFromFavorites".GetLocalizedResource(),
OpacityIcon = new("ColorIconUnpinFromFavorites"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconUnpinFromFavorites",
},
Command = UnpinFromFavoritesCommand,
CommandParameter = item,
ShowItem = isPinned && isFolder
},
new ContextMenuFlyoutItemViewModel()
{
Text = "Properties".GetLocalizedResource(),
OpacityIcon = new("ColorIconProperties"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconProperties",
},
Command = OpenPropertiesCommand,
CommandParameter = item,
ShowItem = isFolder
Expand Down
25 changes: 20 additions & 5 deletions src/Files.App/UserControls/Widgets/QuickAccessWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,21 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewTab".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenInNewTab"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenInNewTab",
},
Command = OpenInNewTabCommand,
CommandParameter = item,
ShowItem = userSettingsService.GeneralSettingsService.ShowOpenInNewTab
},
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewWindow".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenInNewWindow"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenInNewWindow",
},
Command = OpenInNewWindowCommand,
CommandParameter = item,
ShowItem = userSettingsService.GeneralSettingsService.ShowOpenInNewWindow
Expand All @@ -172,23 +178,32 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
Text = "PinToFavorites".GetLocalizedResource(),
OpacityIcon = new("ColorIconPinToFavorites"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconPinToFavorites",
},
Command = PinToFavoritesCommand,
CommandParameter = item,
ShowItem = !isPinned
},
new ContextMenuFlyoutItemViewModel()
{
Text = "UnpinFromFavorites".GetLocalizedResource(),
OpacityIcon = new("ColorIconUnpinFromFavorites"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconUnpinFromFavorites",
},
Command = UnpinFromFavoritesCommand,
CommandParameter = item,
ShowItem = isPinned
},
new ContextMenuFlyoutItemViewModel()
{
Text = "Properties".GetLocalizedResource(),
OpacityIcon = new("ColorIconProperties"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconProperties",
},
Command = OpenPropertiesCommand,
CommandParameter = item
},
Expand Down
10 changes: 8 additions & 2 deletions src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenWith".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenWith"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenWith",
},
Tag = "OpenWithPlaceholder",
},
new ContextMenuFlyoutItemViewModel()
Expand Down Expand Up @@ -190,7 +193,10 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
new ContextMenuFlyoutItemViewModel()
{
Text = "Properties".GetLocalizedResource(),
OpacityIcon = new("ColorIconProperties"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconProperties",
},
Command = OpenPropertiesCommand,
CommandParameter = item
},
Expand Down
25 changes: 20 additions & 5 deletions src/Files.App/ViewModels/UserControls/SidebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -977,14 +977,20 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewTab".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenInNewTab"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenInNewTab",
},
Command = OpenInNewTabCommand,
ShowItem = options.IsLocationItem && UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
},
new ContextMenuFlyoutItemViewModel()
{
Text = "OpenInNewWindow".GetLocalizedResource(),
OpacityIcon = new("ColorIconOpenInNewWindow"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconOpenInNewWindow",
},
Command = OpenInNewWindowCommand,
ShowItem = options.IsLocationItem && UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
},
Expand All @@ -997,14 +1003,20 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
new ContextMenuFlyoutItemViewModel()
{
Text = "PinToFavorites".GetLocalizedResource(),
OpacityIcon = new("ColorIconPinToFavorites"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconPinToFavorites",
},
Command = PinItemCommand,
ShowItem = isDriveItem && !isDriveItemPinned
},
new ContextMenuFlyoutItemViewModel()
{
Text = "UnpinFromFavorites".GetLocalizedResource(),
OpacityIcon = new("ColorIconUnpinFromFavorites"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconUnpinFromFavorites",
},
Command = UnpinItemCommand,
ShowItem = options.ShowUnpinItem || isDriveItemPinned
},
Expand Down Expand Up @@ -1038,7 +1050,10 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
new ContextMenuFlyoutItemViewModel()
{
Text = "Properties".GetLocalizedResource(),
OpacityIcon = new("ColorIconProperties"),
OpacityIcon = new OpacityIconModel()
{
OpacityIconStyle = "ColorIconProperties",
},
Command = OpenPropertiesCommand,
CommandParameter = menu,
ShowItem = options.ShowProperties
Expand Down

0 comments on commit 6718879

Please sign in to comment.