Skip to content

Commit 6718879

Browse files
authored
Revert "Code Quality: Improved the way of instancing OpacityIconModel" (files-community#14617)
1 parent 681b2d3 commit 6718879

9 files changed

+126
-44
lines changed

src/Files.App/Data/Models/ContextMenuFlyoutItemViewModelBuilder.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public ContextMenuFlyoutItemViewModel Build()
6969
var glyph = command.Glyph;
7070
if (!string.IsNullOrEmpty(glyph.OpacityStyle))
7171
{
72-
viewModel.OpacityIcon = new(glyph.OpacityStyle);
72+
viewModel.OpacityIcon = new OpacityIconModel
73+
{
74+
OpacityIconStyle = glyph.OpacityStyle,
75+
};
7376
}
7477
else
7578
{

src/Files.App/Data/Models/OpacityIconModel.cs

+6-14
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,19 @@
55

66
namespace Files.App.Data.Models
77
{
8-
/// <summary>
9-
/// Represents a model for <see cref="OpacityIcon"/>.
10-
/// </summary>
11-
public class OpacityIconModel
8+
public struct OpacityIconModel
129
{
13-
public string? OpacityIconStyle { get; set; }
10+
public string OpacityIconStyle { get; set; }
1411

15-
public bool IsValid
16-
=> !string.IsNullOrWhiteSpace(OpacityIconStyle);
17-
18-
public OpacityIconModel(string styleName)
19-
{
20-
OpacityIconStyle = styleName;
21-
}
22-
23-
public OpacityIcon ToOpacityIcon()
12+
public readonly OpacityIcon ToOpacityIcon()
2413
{
2514
return new()
2615
{
2716
Style = (Style)Application.Current.Resources[OpacityIconStyle],
2817
};
2918
}
19+
20+
public readonly bool IsValid
21+
=> !string.IsNullOrEmpty(OpacityIconStyle);
3022
}
3123
}

src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs

+20-5
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
143143
new ContextMenuFlyoutItemViewModel()
144144
{
145145
Text = "SortBy".GetLocalizedResource(),
146-
OpacityIcon = new("ColorIconSort"),
146+
OpacityIcon = new OpacityIconModel()
147+
{
148+
OpacityIconStyle = "ColorIconSort",
149+
},
147150
ShowItem = !itemsSelected,
148151
ShowInRecycleBin = true,
149152
ShowInSearchPage = true,
@@ -352,7 +355,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
352355
},
353356
new ContextMenuFlyoutItemViewModel()
354357
{
355-
OpacityIcon = new(commands.AddItem.Glyph.OpacityStyle),
358+
OpacityIcon = new OpacityIconModel()
359+
{
360+
OpacityIconStyle = commands.AddItem.Glyph.OpacityStyle
361+
},
356362
Text = commands.AddItem.Label,
357363
Items = GetNewItemItems(commandsViewModel, currentInstanceViewModel.CanCreateFileInPage),
358364
ShowItem = !itemsSelected,
@@ -379,7 +385,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
379385
new ContextMenuFlyoutItemViewModel()
380386
{
381387
Text = "OpenWith".GetLocalizedResource(),
382-
OpacityIcon = new("ColorIconOpenWith"),
388+
OpacityIcon = new OpacityIconModel()
389+
{
390+
OpacityIconStyle = "ColorIconOpenWith"
391+
},
383392
Tag = "OpenWithOverflow",
384393
IsHidden = true,
385394
CollapseLabel = true,
@@ -503,7 +512,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
503512
{
504513
Text = "Compress".GetLocalizedResource(),
505514
ShowInSearchPage = true,
506-
OpacityIcon = new("ColorIconZip"),
515+
OpacityIcon = new OpacityIconModel()
516+
{
517+
OpacityIconStyle = "ColorIconZip",
518+
},
507519
Items = new List<ContextMenuFlyoutItemViewModel>
508520
{
509521
new ContextMenuFlyoutItemViewModelBuilder(commands.CompressIntoArchive).Build(),
@@ -516,7 +528,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
516528
{
517529
Text = "Extract".GetLocalizedResource(),
518530
ShowInSearchPage = true,
519-
OpacityIcon = new("ColorIconZip"),
531+
OpacityIcon = new OpacityIconModel()
532+
{
533+
OpacityIconStyle = "ColorIconZip",
534+
},
520535
Items = new List<ContextMenuFlyoutItemViewModel>
521536
{
522537
new ContextMenuFlyoutItemViewModelBuilder(commands.DecompressArchive).Build(),

src/Files.App/Helpers/MenuFlyout/ShellContextMenuHelper.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,10 @@ x.Tag is Win32ContextMenuItem menuItem &&
330330
{
331331
await openWithItem.LoadSubMenuAction();
332332

333-
openWithItem.OpacityIcon = new("ColorIconOpenWith");
333+
openWithItem.OpacityIcon = new OpacityIconModel()
334+
{
335+
OpacityIconStyle = "ColorIconOpenWith",
336+
};
334337
var (_, openWithItems) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(new List<ContextMenuFlyoutItemViewModel>() { openWithItem });
335338
var placeholder = itemContextMenuFlyout.SecondaryCommands.Where(x => Equals((x as AppBarButton)?.Tag, "OpenWithPlaceholder")).FirstOrDefault() as AppBarButton;
336339
if (placeholder is not null)

src/Files.App/UserControls/Widgets/DrivesWidget.xaml.cs

+20-5
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,21 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
159159
new ContextMenuFlyoutItemViewModel()
160160
{
161161
Text = "OpenInNewTab".GetLocalizedResource(),
162-
OpacityIcon = new("ColorIconOpenInNewTab"),
162+
OpacityIcon = new OpacityIconModel()
163+
{
164+
OpacityIconStyle = "ColorIconOpenInNewTab",
165+
},
163166
Command = OpenInNewTabCommand,
164167
CommandParameter = item,
165168
ShowItem = userSettingsService.GeneralSettingsService.ShowOpenInNewTab
166169
},
167170
new ContextMenuFlyoutItemViewModel()
168171
{
169172
Text = "OpenInNewWindow".GetLocalizedResource(),
170-
OpacityIcon = new("ColorIconOpenInNewWindow"),
173+
OpacityIcon = new OpacityIconModel()
174+
{
175+
OpacityIconStyle = "ColorIconOpenInNewWindow",
176+
},
171177
Command = OpenInNewWindowCommand,
172178
CommandParameter = item,
173179
ShowItem = userSettingsService.GeneralSettingsService.ShowOpenInNewWindow
@@ -182,15 +188,21 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
182188
new ContextMenuFlyoutItemViewModel()
183189
{
184190
Text = "PinToFavorites".GetLocalizedResource(),
185-
OpacityIcon = new("ColorIconPinToFavorites"),
191+
OpacityIcon = new OpacityIconModel()
192+
{
193+
OpacityIconStyle = "ColorIconPinToFavorites",
194+
},
186195
Command = PinToFavoritesCommand,
187196
CommandParameter = item,
188197
ShowItem = !isPinned
189198
},
190199
new ContextMenuFlyoutItemViewModel()
191200
{
192201
Text = "UnpinFromFavorites".GetLocalizedResource(),
193-
OpacityIcon = new("ColorIconUnpinFromFavorites"),
202+
OpacityIcon = new OpacityIconModel()
203+
{
204+
OpacityIconStyle = "ColorIconUnpinFromFavorites",
205+
},
194206
Command = UnpinFromFavoritesCommand,
195207
CommandParameter = item,
196208
ShowItem = isPinned
@@ -212,7 +224,10 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
212224
new ContextMenuFlyoutItemViewModel()
213225
{
214226
Text = "Properties".GetLocalizedResource(),
215-
OpacityIcon = new("ColorIconProperties"),
227+
OpacityIcon = new OpacityIconModel()
228+
{
229+
OpacityIconStyle = "ColorIconProperties",
230+
},
216231
Command = OpenPropertiesCommand,
217232
CommandParameter = item
218233
},

src/Files.App/UserControls/Widgets/FileTagsWidget.xaml.cs

+24-6
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
155155
new ContextMenuFlyoutItemViewModel()
156156
{
157157
Text = "OpenWith".GetLocalizedResource(),
158-
OpacityIcon = new("ColorIconOpenWith"),
158+
OpacityIcon = new OpacityIconModel()
159+
{
160+
OpacityIconStyle = "ColorIconOpenWith",
161+
},
159162
Tag = "OpenWithPlaceholder",
160163
ShowItem = !isFolder
161164
},
@@ -168,15 +171,21 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
168171
new ContextMenuFlyoutItemViewModel()
169172
{
170173
Text = "OpenInNewTab".GetLocalizedResource(),
171-
OpacityIcon = new("ColorIconOpenInNewTab"),
174+
OpacityIcon = new OpacityIconModel()
175+
{
176+
OpacityIconStyle = "ColorIconOpenInNewTab",
177+
},
172178
Command = OpenInNewTabCommand,
173179
CommandParameter = item,
174180
ShowItem = isFolder
175181
},
176182
new ContextMenuFlyoutItemViewModel()
177183
{
178184
Text = "OpenInNewWindow".GetLocalizedResource(),
179-
OpacityIcon = new("ColorIconOpenInNewWindow"),
185+
OpacityIcon = new OpacityIconModel()
186+
{
187+
OpacityIconStyle = "ColorIconOpenInNewWindow",
188+
},
180189
Command = OpenInNewWindowCommand,
181190
CommandParameter = item,
182191
ShowItem = isFolder
@@ -199,23 +208,32 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
199208
new ContextMenuFlyoutItemViewModel()
200209
{
201210
Text = "PinToFavorites".GetLocalizedResource(),
202-
OpacityIcon = new("ColorIconPinToFavorites"),
211+
OpacityIcon = new OpacityIconModel()
212+
{
213+
OpacityIconStyle = "ColorIconPinToFavorites",
214+
},
203215
Command = PinToFavoritesCommand,
204216
CommandParameter = item,
205217
ShowItem = !isPinned && isFolder
206218
},
207219
new ContextMenuFlyoutItemViewModel()
208220
{
209221
Text = "UnpinFromFavorites".GetLocalizedResource(),
210-
OpacityIcon = new("ColorIconUnpinFromFavorites"),
222+
OpacityIcon = new OpacityIconModel()
223+
{
224+
OpacityIconStyle = "ColorIconUnpinFromFavorites",
225+
},
211226
Command = UnpinFromFavoritesCommand,
212227
CommandParameter = item,
213228
ShowItem = isPinned && isFolder
214229
},
215230
new ContextMenuFlyoutItemViewModel()
216231
{
217232
Text = "Properties".GetLocalizedResource(),
218-
OpacityIcon = new("ColorIconProperties"),
233+
OpacityIcon = new OpacityIconModel()
234+
{
235+
OpacityIconStyle = "ColorIconProperties",
236+
},
219237
Command = OpenPropertiesCommand,
220238
CommandParameter = item,
221239
ShowItem = isFolder

src/Files.App/UserControls/Widgets/QuickAccessWidget.xaml.cs

+20-5
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,21 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
149149
new ContextMenuFlyoutItemViewModel()
150150
{
151151
Text = "OpenInNewTab".GetLocalizedResource(),
152-
OpacityIcon = new("ColorIconOpenInNewTab"),
152+
OpacityIcon = new OpacityIconModel()
153+
{
154+
OpacityIconStyle = "ColorIconOpenInNewTab",
155+
},
153156
Command = OpenInNewTabCommand,
154157
CommandParameter = item,
155158
ShowItem = userSettingsService.GeneralSettingsService.ShowOpenInNewTab
156159
},
157160
new ContextMenuFlyoutItemViewModel()
158161
{
159162
Text = "OpenInNewWindow".GetLocalizedResource(),
160-
OpacityIcon = new("ColorIconOpenInNewWindow"),
163+
OpacityIcon = new OpacityIconModel()
164+
{
165+
OpacityIconStyle = "ColorIconOpenInNewWindow",
166+
},
161167
Command = OpenInNewWindowCommand,
162168
CommandParameter = item,
163169
ShowItem = userSettingsService.GeneralSettingsService.ShowOpenInNewWindow
@@ -172,23 +178,32 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
172178
new ContextMenuFlyoutItemViewModel()
173179
{
174180
Text = "PinToFavorites".GetLocalizedResource(),
175-
OpacityIcon = new("ColorIconPinToFavorites"),
181+
OpacityIcon = new OpacityIconModel()
182+
{
183+
OpacityIconStyle = "ColorIconPinToFavorites",
184+
},
176185
Command = PinToFavoritesCommand,
177186
CommandParameter = item,
178187
ShowItem = !isPinned
179188
},
180189
new ContextMenuFlyoutItemViewModel()
181190
{
182191
Text = "UnpinFromFavorites".GetLocalizedResource(),
183-
OpacityIcon = new("ColorIconUnpinFromFavorites"),
192+
OpacityIcon = new OpacityIconModel()
193+
{
194+
OpacityIconStyle = "ColorIconUnpinFromFavorites",
195+
},
184196
Command = UnpinFromFavoritesCommand,
185197
CommandParameter = item,
186198
ShowItem = isPinned
187199
},
188200
new ContextMenuFlyoutItemViewModel()
189201
{
190202
Text = "Properties".GetLocalizedResource(),
191-
OpacityIcon = new("ColorIconProperties"),
203+
OpacityIcon = new OpacityIconModel()
204+
{
205+
OpacityIconStyle = "ColorIconProperties",
206+
},
192207
Command = OpenPropertiesCommand,
193208
CommandParameter = item
194209
},

src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
158158
new ContextMenuFlyoutItemViewModel()
159159
{
160160
Text = "OpenWith".GetLocalizedResource(),
161-
OpacityIcon = new("ColorIconOpenWith"),
161+
OpacityIcon = new OpacityIconModel()
162+
{
163+
OpacityIconStyle = "ColorIconOpenWith",
164+
},
162165
Tag = "OpenWithPlaceholder",
163166
},
164167
new ContextMenuFlyoutItemViewModel()
@@ -190,7 +193,10 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
190193
new ContextMenuFlyoutItemViewModel()
191194
{
192195
Text = "Properties".GetLocalizedResource(),
193-
OpacityIcon = new("ColorIconProperties"),
196+
OpacityIcon = new OpacityIconModel()
197+
{
198+
OpacityIconStyle = "ColorIconProperties",
199+
},
194200
Command = OpenPropertiesCommand,
195201
CommandParameter = item
196202
},

src/Files.App/ViewModels/UserControls/SidebarViewModel.cs

+20-5
Original file line numberDiff line numberDiff line change
@@ -977,14 +977,20 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
977977
new ContextMenuFlyoutItemViewModel()
978978
{
979979
Text = "OpenInNewTab".GetLocalizedResource(),
980-
OpacityIcon = new("ColorIconOpenInNewTab"),
980+
OpacityIcon = new OpacityIconModel()
981+
{
982+
OpacityIconStyle = "ColorIconOpenInNewTab",
983+
},
981984
Command = OpenInNewTabCommand,
982985
ShowItem = options.IsLocationItem && UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
983986
},
984987
new ContextMenuFlyoutItemViewModel()
985988
{
986989
Text = "OpenInNewWindow".GetLocalizedResource(),
987-
OpacityIcon = new("ColorIconOpenInNewWindow"),
990+
OpacityIcon = new OpacityIconModel()
991+
{
992+
OpacityIconStyle = "ColorIconOpenInNewWindow",
993+
},
988994
Command = OpenInNewWindowCommand,
989995
ShowItem = options.IsLocationItem && UserSettingsService.GeneralSettingsService.ShowOpenInNewTab
990996
},
@@ -997,14 +1003,20 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
9971003
new ContextMenuFlyoutItemViewModel()
9981004
{
9991005
Text = "PinToFavorites".GetLocalizedResource(),
1000-
OpacityIcon = new("ColorIconPinToFavorites"),
1006+
OpacityIcon = new OpacityIconModel()
1007+
{
1008+
OpacityIconStyle = "ColorIconPinToFavorites",
1009+
},
10011010
Command = PinItemCommand,
10021011
ShowItem = isDriveItem && !isDriveItemPinned
10031012
},
10041013
new ContextMenuFlyoutItemViewModel()
10051014
{
10061015
Text = "UnpinFromFavorites".GetLocalizedResource(),
1007-
OpacityIcon = new("ColorIconUnpinFromFavorites"),
1016+
OpacityIcon = new OpacityIconModel()
1017+
{
1018+
OpacityIconStyle = "ColorIconUnpinFromFavorites",
1019+
},
10081020
Command = UnpinItemCommand,
10091021
ShowItem = options.ShowUnpinItem || isDriveItemPinned
10101022
},
@@ -1038,7 +1050,10 @@ private List<ContextMenuFlyoutItemViewModel> GetLocationItemMenuItems(INavigatio
10381050
new ContextMenuFlyoutItemViewModel()
10391051
{
10401052
Text = "Properties".GetLocalizedResource(),
1041-
OpacityIcon = new("ColorIconProperties"),
1053+
OpacityIcon = new OpacityIconModel()
1054+
{
1055+
OpacityIconStyle = "ColorIconProperties",
1056+
},
10421057
Command = OpenPropertiesCommand,
10431058
CommandParameter = menu,
10441059
ShowItem = options.ShowProperties

0 commit comments

Comments
 (0)