Skip to content

Commit 4c40a7d

Browse files
authored
Feature: Added slider to control item size (phase 1) (#14719)
1 parent a1e17f8 commit 4c40a7d

40 files changed

+796
-852
lines changed

src/Files.App/Actions/Display/LayoutAction.cs

Lines changed: 143 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override RichGlyph Glyph
2020
public override HotKey HotKey
2121
=> new(Keys.Number1, KeyModifiers.CtrlShift);
2222
}
23-
23+
2424
internal class LayoutListAction : ToggleLayoutAction
2525
{
2626
protected override LayoutTypes LayoutType
@@ -57,60 +57,24 @@ public override HotKey HotKey
5757
=> new(Keys.Number3, KeyModifiers.CtrlShift);
5858
}
5959

60-
internal class LayoutGridSmallAction : ToggleLayoutAction
60+
internal class LayoutGridAction : ToggleLayoutAction
6161
{
6262
protected override LayoutTypes LayoutType
63-
=> LayoutTypes.GridSmall;
63+
=> LayoutTypes.Grid;
6464

6565
public override string Label
66-
=> "SmallIcons".GetLocalizedResource();
66+
=> "Grid".GetLocalizedResource();
6767

6868
public override string Description
69-
=> "LayoutGridSmallDescription".GetLocalizedResource();
69+
=> "LayoutGridescription".GetLocalizedResource();
7070

7171
public override RichGlyph Glyph
72-
=> new(opacityStyle: "ColorIconGridSmallLayout");
72+
=> new(opacityStyle: "ColorIconGridLayout");
7373

7474
public override HotKey HotKey
7575
=> new(Keys.Number4, KeyModifiers.CtrlShift);
7676
}
7777

78-
internal class LayoutGridMediumAction : ToggleLayoutAction
79-
{
80-
protected override LayoutTypes LayoutType
81-
=> LayoutTypes.GridMedium;
82-
83-
public override string Label
84-
=> "MediumIcons".GetLocalizedResource();
85-
86-
public override string Description
87-
=> "LayoutGridMediumDescription".GetLocalizedResource();
88-
89-
public override RichGlyph Glyph
90-
=> new(opacityStyle: "ColorIconGridMediumLayout");
91-
92-
public override HotKey HotKey
93-
=> new(Keys.Number5, KeyModifiers.CtrlShift);
94-
}
95-
96-
internal class LayoutGridLargeAction : ToggleLayoutAction
97-
{
98-
protected override LayoutTypes LayoutType
99-
=> LayoutTypes.GridLarge;
100-
101-
public override string Label
102-
=> "LargeIcons".GetLocalizedResource();
103-
104-
public override string Description
105-
=> "LayoutGridLargeDescription".GetLocalizedResource();
106-
107-
public override RichGlyph Glyph
108-
=> new(opacityStyle: "ColorIconGridLargeLayout");
109-
110-
public override HotKey HotKey
111-
=> new(Keys.Number6, KeyModifiers.CtrlShift);
112-
}
113-
11478
internal class LayoutColumnsAction : ToggleLayoutAction
11579
{
11680
protected override LayoutTypes LayoutType
@@ -126,7 +90,7 @@ public override RichGlyph Glyph
12690
=> new(opacityStyle: "ColorIconColumnsLayout");
12791

12892
public override HotKey HotKey
129-
=> new(Keys.Number7, KeyModifiers.CtrlShift);
93+
=> new(Keys.Number5, KeyModifiers.CtrlShift);
13094
}
13195

13296
internal class LayoutAdaptiveAction : ToggleLayoutAction
@@ -204,9 +168,11 @@ protected virtual void OnContextChanged(string propertyName)
204168
}
205169
}
206170

207-
internal class LayoutDecreaseSizeAction : IAction
171+
internal class LayoutDecreaseSizeAction : ObservableObject, IAction
208172
{
209-
private readonly IDisplayPageContext context;
173+
private static readonly IUserSettingsService UserSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
174+
private readonly IDisplayPageContext DisplayPageContext = Ioc.Default.GetRequiredService<IDisplayPageContext>();
175+
private readonly IContentPageContext ContentPageContext = Ioc.Default.GetRequiredService<IContentPageContext>();
210176

211177
public string Label
212178
=> "DecreaseSize".GetLocalizedResource();
@@ -220,22 +186,86 @@ public HotKey HotKey
220186
public HotKey MediaHotKey
221187
=> new(Keys.OemMinus, KeyModifiers.Ctrl, false);
222188

189+
public bool IsExecutable =>
190+
ContentPageContext.PageType is not ContentPageTypes.Home &&
191+
((DisplayPageContext.LayoutType == LayoutTypes.Details && UserSettingsService.LayoutSettingsService.ItemSizeDetailsView > Constants.IconHeights.DetailsView.Minimum) ||
192+
(DisplayPageContext.LayoutType == LayoutTypes.List && UserSettingsService.LayoutSettingsService.ItemSizeListView > Constants.IconHeights.ListView.Minimum) ||
193+
(DisplayPageContext.LayoutType == LayoutTypes.Grid && UserSettingsService.LayoutSettingsService.ItemSizeGridView > Constants.IconHeights.GridView.Minimum) ||
194+
(DisplayPageContext.LayoutType == LayoutTypes.Columns && UserSettingsService.LayoutSettingsService.ItemSizeColumnsView > Constants.IconHeights.ColumnsView.Minimum));
195+
223196
public LayoutDecreaseSizeAction()
224197
{
225-
context = Ioc.Default.GetRequiredService<IDisplayPageContext>();
198+
ContentPageContext.PropertyChanged += ContentPageContext_PropertyChanged;
199+
DisplayPageContext.PropertyChanged += DisplayPageContext_PropertyChanged;
200+
UserSettingsService.LayoutSettingsService.PropertyChanged += UserSettingsService_PropertyChanged;
201+
}
202+
203+
private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
204+
{
205+
switch (e.PropertyName)
206+
{
207+
case nameof(IContentPageContext.PageType):
208+
OnPropertyChanged(nameof(IsExecutable));
209+
break;
210+
}
211+
}
212+
213+
private void DisplayPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
214+
{
215+
switch (e.PropertyName)
216+
{
217+
case nameof(IDisplayPageContext.LayoutType):
218+
OnPropertyChanged(nameof(IsExecutable));
219+
break;
220+
}
221+
}
222+
223+
private void UserSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
224+
{
225+
switch (e.PropertyName)
226+
{
227+
case nameof(ILayoutSettingsService.ItemSizeDetailsView):
228+
case nameof(ILayoutSettingsService.ItemSizeListView):
229+
case nameof(ILayoutSettingsService.ItemSizeGridView):
230+
case nameof(ILayoutSettingsService.ItemSizeColumnsView):
231+
OnPropertyChanged(nameof(IsExecutable));
232+
break;
233+
}
226234
}
227235

228236
public Task ExecuteAsync()
229237
{
230-
context.DecreaseLayoutSize();
238+
switch (DisplayPageContext.LayoutType)
239+
{
240+
case LayoutTypes.Details:
241+
if (UserSettingsService.LayoutSettingsService.ItemSizeDetailsView > Constants.IconHeights.DetailsView.Minimum)
242+
UserSettingsService.LayoutSettingsService.ItemSizeDetailsView -= Constants.IconHeights.DetailsView.Increment;
243+
break;
244+
case LayoutTypes.List:
245+
if (UserSettingsService.LayoutSettingsService.ItemSizeListView > Constants.IconHeights.ListView.Minimum)
246+
UserSettingsService.LayoutSettingsService.ItemSizeListView -= Constants.IconHeights.ListView.Increment;
247+
break;
248+
case LayoutTypes.Tiles:
249+
break;
250+
case LayoutTypes.Grid:
251+
if (UserSettingsService.LayoutSettingsService.ItemSizeGridView > Constants.IconHeights.GridView.Minimum)
252+
UserSettingsService.LayoutSettingsService.ItemSizeGridView -= Constants.IconHeights.GridView.Increment;
253+
break;
254+
case LayoutTypes.Columns:
255+
if (UserSettingsService.LayoutSettingsService.ItemSizeColumnsView > Constants.IconHeights.ColumnsView.Minimum)
256+
UserSettingsService.LayoutSettingsService.ItemSizeColumnsView -= Constants.IconHeights.ColumnsView.Increment;
257+
break;
258+
}
231259

232260
return Task.CompletedTask;
233261
}
234262
}
235263

236-
internal class LayoutIncreaseSizeAction : IAction
264+
internal class LayoutIncreaseSizeAction : ObservableObject, IAction
237265
{
238-
private readonly IDisplayPageContext context;
266+
private static readonly IUserSettingsService UserSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
267+
private readonly IDisplayPageContext DisplayPageContext = Ioc.Default.GetRequiredService<IDisplayPageContext>();
268+
private readonly IContentPageContext ContentPageContext = Ioc.Default.GetRequiredService<IContentPageContext>();
239269

240270
public string Label
241271
=> "IncreaseSize".GetLocalizedResource();
@@ -249,14 +279,76 @@ public HotKey HotKey
249279
public HotKey MediaHotKey
250280
=> new(Keys.OemPlus, KeyModifiers.Ctrl, false);
251281

282+
public bool IsExecutable =>
283+
ContentPageContext.PageType is not ContentPageTypes.Home &&
284+
((DisplayPageContext.LayoutType == LayoutTypes.Details && UserSettingsService.LayoutSettingsService.ItemSizeDetailsView < Constants.IconHeights.DetailsView.Maximum) ||
285+
(DisplayPageContext.LayoutType == LayoutTypes.List && UserSettingsService.LayoutSettingsService.ItemSizeListView < Constants.IconHeights.ListView.Maximum) ||
286+
(DisplayPageContext.LayoutType == LayoutTypes.Grid && UserSettingsService.LayoutSettingsService.ItemSizeGridView < Constants.IconHeights.GridView.Maximum) ||
287+
(DisplayPageContext.LayoutType == LayoutTypes.Columns && UserSettingsService.LayoutSettingsService.ItemSizeColumnsView < Constants.IconHeights.ColumnsView.Maximum));
288+
252289
public LayoutIncreaseSizeAction()
253290
{
254-
context = Ioc.Default.GetRequiredService<IDisplayPageContext>();
291+
ContentPageContext.PropertyChanged += ContentPageContext_PropertyChanged;
292+
DisplayPageContext.PropertyChanged += DisplayPageContext_PropertyChanged;
293+
UserSettingsService.LayoutSettingsService.PropertyChanged += UserSettingsService_PropertyChanged;
294+
}
295+
296+
private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
297+
{
298+
switch (e.PropertyName)
299+
{
300+
case nameof(IContentPageContext.PageType):
301+
OnPropertyChanged(nameof(IsExecutable));
302+
break;
303+
}
304+
}
305+
306+
private void DisplayPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
307+
{
308+
switch (e.PropertyName)
309+
{
310+
case nameof(IDisplayPageContext.LayoutType):
311+
OnPropertyChanged(nameof(IsExecutable));
312+
break;
313+
}
314+
}
315+
316+
private void UserSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
317+
{
318+
switch (e.PropertyName)
319+
{
320+
case nameof(ILayoutSettingsService.ItemSizeDetailsView):
321+
case nameof(ILayoutSettingsService.ItemSizeListView):
322+
case nameof(ILayoutSettingsService.ItemSizeGridView):
323+
case nameof(ILayoutSettingsService.ItemSizeColumnsView):
324+
OnPropertyChanged(nameof(IsExecutable));
325+
break;
326+
}
255327
}
256328

257329
public Task ExecuteAsync()
258330
{
259-
context.IncreaseLayoutSize();
331+
switch (DisplayPageContext.LayoutType)
332+
{
333+
case LayoutTypes.Details:
334+
if (UserSettingsService.LayoutSettingsService.ItemSizeDetailsView < Constants.IconHeights.DetailsView.Maximum)
335+
UserSettingsService.LayoutSettingsService.ItemSizeDetailsView += Constants.IconHeights.DetailsView.Increment;
336+
break;
337+
case LayoutTypes.List:
338+
if (UserSettingsService.LayoutSettingsService.ItemSizeListView < Constants.IconHeights.ListView.Maximum)
339+
UserSettingsService.LayoutSettingsService.ItemSizeListView += Constants.IconHeights.ListView.Increment;
340+
break;
341+
case LayoutTypes.Tiles:
342+
break;
343+
case LayoutTypes.Grid:
344+
if (UserSettingsService.LayoutSettingsService.ItemSizeGridView < Constants.IconHeights.GridView.Maximum)
345+
UserSettingsService.LayoutSettingsService.ItemSizeGridView += Constants.IconHeights.GridView.Increment;
346+
break;
347+
case LayoutTypes.Columns:
348+
if (UserSettingsService.LayoutSettingsService.ItemSizeColumnsView < Constants.IconHeights.ColumnsView.Maximum)
349+
UserSettingsService.LayoutSettingsService.ItemSizeColumnsView += Constants.IconHeights.ColumnsView.Increment;
350+
break;
351+
}
260352

261353
return Task.CompletedTask;
262354
}

src/Files.App/App.xaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
<Application.Resources>
88
<ResourceDictionary>
99

10-
<!-- Default list view item height -->
11-
<x:Double x:Key="ListItemHeight">36</x:Double>
12-
13-
<!-- Default list view item margin -->
14-
<x:Double x:Key="ListItemMargin">0</x:Double>
15-
1610
<!-- Fix caption buttons background -->
1711
<SolidColorBrush x:Key="WindowCaptionBackground" Color="Transparent" />
1812
<SolidColorBrush x:Key="WindowCaptionBackgroundDisabled" Color="Transparent" />
@@ -29,6 +23,7 @@
2923
<!-- Workaround for https://github.com/files-community/Files/issues/13078 -->
3024
<Style TargetType="FlyoutPresenter">
3125
<Setter Target="HighContrastAdjustment" Value="None" />
26+
<Setter Property="CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
3227
</Style>
3328

3429
<Style TargetType="MenuFlyoutPresenter">

src/Files.App/Constants.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,41 @@ public static class TilesView
143143

144144
public static class ListView
145145
{
146+
public const int Increment = 4;
147+
148+
public const int Minimum = 24;
149+
150+
public const int Small = 28;
151+
146152
public const int Regular = 32;
153+
154+
public const int Maximum = 36;
147155
}
148156

149157
public static class DetailsView
150158
{
151-
public const int Regular = 32;
159+
public const int Increment = 4;
160+
161+
public const int Minimum = 28;
162+
163+
public const int Small = 32;
164+
165+
public const int Regular = 36;
166+
167+
public const int Maximum = 40;
152168
}
153169

154170
public static class ColumnsView
155171
{
156-
public const int Regular = 32;
172+
public const int Increment = 4;
173+
174+
public const int Minimum = 28;
175+
176+
public const int Small = 32;
177+
178+
public const int Regular = 36;
179+
180+
public const int Maximum = 40;
157181
}
158182
}
159183

src/Files.App/Data/Commands/CommandCodes.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ public enum CommandCodes
113113
LayoutDetails,
114114
LayoutList,
115115
LayoutTiles,
116-
LayoutGridSmall,
117-
LayoutGridMedium,
118-
LayoutGridLarge,
116+
LayoutGrid,
119117
LayoutColumns,
120118
LayoutAdaptive,
121119

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ public IRichCommand this[HotKey hotKey]
113113
public IRichCommand LayoutDetails => commands[CommandCodes.LayoutDetails];
114114
public IRichCommand LayoutList => commands[CommandCodes.LayoutList];
115115
public IRichCommand LayoutTiles => commands[CommandCodes.LayoutTiles];
116-
public IRichCommand LayoutGridSmall => commands[CommandCodes.LayoutGridSmall];
117-
public IRichCommand LayoutGridMedium => commands[CommandCodes.LayoutGridMedium];
118-
public IRichCommand LayoutGridLarge => commands[CommandCodes.LayoutGridLarge];
116+
public IRichCommand LayoutGrid => commands[CommandCodes.LayoutGrid];
119117
public IRichCommand LayoutColumns => commands[CommandCodes.LayoutColumns];
120118
public IRichCommand LayoutAdaptive => commands[CommandCodes.LayoutAdaptive];
121119
public IRichCommand SortByName => commands[CommandCodes.SortByName];
@@ -284,9 +282,7 @@ public CommandManager()
284282
[CommandCodes.LayoutDetails] = new LayoutDetailsAction(),
285283
[CommandCodes.LayoutList] = new LayoutListAction(),
286284
[CommandCodes.LayoutTiles] = new LayoutTilesAction(),
287-
[CommandCodes.LayoutGridSmall] = new LayoutGridSmallAction(),
288-
[CommandCodes.LayoutGridMedium] = new LayoutGridMediumAction(),
289-
[CommandCodes.LayoutGridLarge] = new LayoutGridLargeAction(),
285+
[CommandCodes.LayoutGrid] = new LayoutGridAction(),
290286
[CommandCodes.LayoutColumns] = new LayoutColumnsAction(),
291287
[CommandCodes.LayoutAdaptive] = new LayoutAdaptiveAction(),
292288
[CommandCodes.SortByName] = new SortByNameAction(),

src/Files.App/Data/Commands/Manager/ICommandManager.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
9999
IRichCommand LayoutDetails { get; }
100100
IRichCommand LayoutList { get; }
101101
IRichCommand LayoutTiles { get; }
102-
IRichCommand LayoutGridSmall { get; }
103-
IRichCommand LayoutGridMedium { get; }
104-
IRichCommand LayoutGridLarge { get; }
102+
IRichCommand LayoutGrid { get; }
105103
IRichCommand LayoutColumns { get; }
106104
IRichCommand LayoutAdaptive { get; }
107105

0 commit comments

Comments
 (0)