Skip to content

Feature: Added slider to control item size (phase 1) #14719

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 2 commits into from
Feb 20, 2024
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
194 changes: 143 additions & 51 deletions src/Files.App/Actions/Display/LayoutAction.cs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to update docs

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override RichGlyph Glyph
public override HotKey HotKey
=> new(Keys.Number1, KeyModifiers.CtrlShift);
}

internal class LayoutListAction : ToggleLayoutAction
{
protected override LayoutTypes LayoutType
Expand Down Expand Up @@ -57,60 +57,24 @@ public override HotKey HotKey
=> new(Keys.Number3, KeyModifiers.CtrlShift);
}

internal class LayoutGridSmallAction : ToggleLayoutAction
internal class LayoutGridAction : ToggleLayoutAction
{
protected override LayoutTypes LayoutType
=> LayoutTypes.GridSmall;
=> LayoutTypes.Grid;

public override string Label
=> "SmallIcons".GetLocalizedResource();
=> "Grid".GetLocalizedResource();

public override string Description
=> "LayoutGridSmallDescription".GetLocalizedResource();
=> "LayoutGridescription".GetLocalizedResource();

public override RichGlyph Glyph
=> new(opacityStyle: "ColorIconGridSmallLayout");
=> new(opacityStyle: "ColorIconGridLayout");

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

internal class LayoutGridMediumAction : ToggleLayoutAction
{
protected override LayoutTypes LayoutType
=> LayoutTypes.GridMedium;

public override string Label
=> "MediumIcons".GetLocalizedResource();

public override string Description
=> "LayoutGridMediumDescription".GetLocalizedResource();

public override RichGlyph Glyph
=> new(opacityStyle: "ColorIconGridMediumLayout");

public override HotKey HotKey
=> new(Keys.Number5, KeyModifiers.CtrlShift);
}

internal class LayoutGridLargeAction : ToggleLayoutAction
{
protected override LayoutTypes LayoutType
=> LayoutTypes.GridLarge;

public override string Label
=> "LargeIcons".GetLocalizedResource();

public override string Description
=> "LayoutGridLargeDescription".GetLocalizedResource();

public override RichGlyph Glyph
=> new(opacityStyle: "ColorIconGridLargeLayout");

public override HotKey HotKey
=> new(Keys.Number6, KeyModifiers.CtrlShift);
}

internal class LayoutColumnsAction : ToggleLayoutAction
{
protected override LayoutTypes LayoutType
Expand All @@ -126,7 +90,7 @@ public override RichGlyph Glyph
=> new(opacityStyle: "ColorIconColumnsLayout");

public override HotKey HotKey
=> new(Keys.Number7, KeyModifiers.CtrlShift);
=> new(Keys.Number5, KeyModifiers.CtrlShift);
}

internal class LayoutAdaptiveAction : ToggleLayoutAction
Expand Down Expand Up @@ -204,9 +168,11 @@ protected virtual void OnContextChanged(string propertyName)
}
}

internal class LayoutDecreaseSizeAction : IAction
internal class LayoutDecreaseSizeAction : ObservableObject, IAction
{
private readonly IDisplayPageContext context;
private static readonly IUserSettingsService UserSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
private readonly IDisplayPageContext DisplayPageContext = Ioc.Default.GetRequiredService<IDisplayPageContext>();
private readonly IContentPageContext ContentPageContext = Ioc.Default.GetRequiredService<IContentPageContext>();

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

public bool IsExecutable =>
ContentPageContext.PageType is not ContentPageTypes.Home &&
((DisplayPageContext.LayoutType == LayoutTypes.Details && UserSettingsService.LayoutSettingsService.ItemSizeDetailsView > Constants.IconHeights.DetailsView.Minimum) ||
(DisplayPageContext.LayoutType == LayoutTypes.List && UserSettingsService.LayoutSettingsService.ItemSizeListView > Constants.IconHeights.ListView.Minimum) ||
(DisplayPageContext.LayoutType == LayoutTypes.Grid && UserSettingsService.LayoutSettingsService.ItemSizeGridView > Constants.IconHeights.GridView.Minimum) ||
(DisplayPageContext.LayoutType == LayoutTypes.Columns && UserSettingsService.LayoutSettingsService.ItemSizeColumnsView > Constants.IconHeights.ColumnsView.Minimum));

public LayoutDecreaseSizeAction()
{
context = Ioc.Default.GetRequiredService<IDisplayPageContext>();
ContentPageContext.PropertyChanged += ContentPageContext_PropertyChanged;
DisplayPageContext.PropertyChanged += DisplayPageContext_PropertyChanged;
UserSettingsService.LayoutSettingsService.PropertyChanged += UserSettingsService_PropertyChanged;
}

private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.PageType):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}

private void DisplayPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IDisplayPageContext.LayoutType):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}

private void UserSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(ILayoutSettingsService.ItemSizeDetailsView):
case nameof(ILayoutSettingsService.ItemSizeListView):
case nameof(ILayoutSettingsService.ItemSizeGridView):
case nameof(ILayoutSettingsService.ItemSizeColumnsView):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}

public Task ExecuteAsync()
{
context.DecreaseLayoutSize();
switch (DisplayPageContext.LayoutType)
{
case LayoutTypes.Details:
if (UserSettingsService.LayoutSettingsService.ItemSizeDetailsView > Constants.IconHeights.DetailsView.Minimum)
UserSettingsService.LayoutSettingsService.ItemSizeDetailsView -= Constants.IconHeights.DetailsView.Increment;
break;
case LayoutTypes.List:
if (UserSettingsService.LayoutSettingsService.ItemSizeListView > Constants.IconHeights.ListView.Minimum)
UserSettingsService.LayoutSettingsService.ItemSizeListView -= Constants.IconHeights.ListView.Increment;
break;
case LayoutTypes.Tiles:
break;
case LayoutTypes.Grid:
if (UserSettingsService.LayoutSettingsService.ItemSizeGridView > Constants.IconHeights.GridView.Minimum)
UserSettingsService.LayoutSettingsService.ItemSizeGridView -= Constants.IconHeights.GridView.Increment;
break;
case LayoutTypes.Columns:
if (UserSettingsService.LayoutSettingsService.ItemSizeColumnsView > Constants.IconHeights.ColumnsView.Minimum)
UserSettingsService.LayoutSettingsService.ItemSizeColumnsView -= Constants.IconHeights.ColumnsView.Increment;
break;
}

return Task.CompletedTask;
}
}

internal class LayoutIncreaseSizeAction : IAction
internal class LayoutIncreaseSizeAction : ObservableObject, IAction
{
private readonly IDisplayPageContext context;
private static readonly IUserSettingsService UserSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
private readonly IDisplayPageContext DisplayPageContext = Ioc.Default.GetRequiredService<IDisplayPageContext>();
private readonly IContentPageContext ContentPageContext = Ioc.Default.GetRequiredService<IContentPageContext>();

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

public bool IsExecutable =>
ContentPageContext.PageType is not ContentPageTypes.Home &&
((DisplayPageContext.LayoutType == LayoutTypes.Details && UserSettingsService.LayoutSettingsService.ItemSizeDetailsView < Constants.IconHeights.DetailsView.Maximum) ||
(DisplayPageContext.LayoutType == LayoutTypes.List && UserSettingsService.LayoutSettingsService.ItemSizeListView < Constants.IconHeights.ListView.Maximum) ||
(DisplayPageContext.LayoutType == LayoutTypes.Grid && UserSettingsService.LayoutSettingsService.ItemSizeGridView < Constants.IconHeights.GridView.Maximum) ||
(DisplayPageContext.LayoutType == LayoutTypes.Columns && UserSettingsService.LayoutSettingsService.ItemSizeColumnsView < Constants.IconHeights.ColumnsView.Maximum));

public LayoutIncreaseSizeAction()
{
context = Ioc.Default.GetRequiredService<IDisplayPageContext>();
ContentPageContext.PropertyChanged += ContentPageContext_PropertyChanged;
DisplayPageContext.PropertyChanged += DisplayPageContext_PropertyChanged;
UserSettingsService.LayoutSettingsService.PropertyChanged += UserSettingsService_PropertyChanged;
}

private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.PageType):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}

private void DisplayPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IDisplayPageContext.LayoutType):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}

private void UserSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(ILayoutSettingsService.ItemSizeDetailsView):
case nameof(ILayoutSettingsService.ItemSizeListView):
case nameof(ILayoutSettingsService.ItemSizeGridView):
case nameof(ILayoutSettingsService.ItemSizeColumnsView):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}

public Task ExecuteAsync()
{
context.IncreaseLayoutSize();
switch (DisplayPageContext.LayoutType)
{
case LayoutTypes.Details:
if (UserSettingsService.LayoutSettingsService.ItemSizeDetailsView < Constants.IconHeights.DetailsView.Maximum)
UserSettingsService.LayoutSettingsService.ItemSizeDetailsView += Constants.IconHeights.DetailsView.Increment;
break;
case LayoutTypes.List:
if (UserSettingsService.LayoutSettingsService.ItemSizeListView < Constants.IconHeights.ListView.Maximum)
UserSettingsService.LayoutSettingsService.ItemSizeListView += Constants.IconHeights.ListView.Increment;
break;
case LayoutTypes.Tiles:
break;
case LayoutTypes.Grid:
if (UserSettingsService.LayoutSettingsService.ItemSizeGridView < Constants.IconHeights.GridView.Maximum)
UserSettingsService.LayoutSettingsService.ItemSizeGridView += Constants.IconHeights.GridView.Increment;
break;
case LayoutTypes.Columns:
if (UserSettingsService.LayoutSettingsService.ItemSizeColumnsView < Constants.IconHeights.ColumnsView.Maximum)
UserSettingsService.LayoutSettingsService.ItemSizeColumnsView += Constants.IconHeights.ColumnsView.Increment;
break;
}

return Task.CompletedTask;
}
Expand Down
7 changes: 1 addition & 6 deletions src/Files.App/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
<Application.Resources>
<ResourceDictionary>

<!-- Default list view item height -->
<x:Double x:Key="ListItemHeight">36</x:Double>

<!-- Default list view item margin -->
<x:Double x:Key="ListItemMargin">0</x:Double>

<!-- Fix caption buttons background -->
<SolidColorBrush x:Key="WindowCaptionBackground" Color="Transparent" />
<SolidColorBrush x:Key="WindowCaptionBackgroundDisabled" Color="Transparent" />
Expand All @@ -29,6 +23,7 @@
<!-- Workaround for https://github.com/files-community/Files/issues/13078 -->
<Style TargetType="FlyoutPresenter">
<Setter Target="HighContrastAdjustment" Value="None" />
<Setter Property="CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
</Style>

<Style TargetType="MenuFlyoutPresenter">
Expand Down
28 changes: 26 additions & 2 deletions src/Files.App/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,41 @@ public static class TilesView

public static class ListView
{
public const int Increment = 4;

public const int Minimum = 24;

public const int Small = 28;

public const int Regular = 32;

public const int Maximum = 36;
}

public static class DetailsView
{
public const int Regular = 32;
public const int Increment = 4;

public const int Minimum = 28;

public const int Small = 32;

public const int Regular = 36;

public const int Maximum = 40;
}

public static class ColumnsView
{
public const int Regular = 32;
public const int Increment = 4;

public const int Minimum = 28;

public const int Small = 32;

public const int Regular = 36;

public const int Maximum = 40;
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/Files.App/Data/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ public enum CommandCodes
LayoutDetails,
LayoutList,
LayoutTiles,
LayoutGridSmall,
LayoutGridMedium,
LayoutGridLarge,
LayoutGrid,
LayoutColumns,
LayoutAdaptive,

Expand Down
8 changes: 2 additions & 6 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand LayoutDetails => commands[CommandCodes.LayoutDetails];
public IRichCommand LayoutList => commands[CommandCodes.LayoutList];
public IRichCommand LayoutTiles => commands[CommandCodes.LayoutTiles];
public IRichCommand LayoutGridSmall => commands[CommandCodes.LayoutGridSmall];
public IRichCommand LayoutGridMedium => commands[CommandCodes.LayoutGridMedium];
public IRichCommand LayoutGridLarge => commands[CommandCodes.LayoutGridLarge];
public IRichCommand LayoutGrid => commands[CommandCodes.LayoutGrid];
public IRichCommand LayoutColumns => commands[CommandCodes.LayoutColumns];
public IRichCommand LayoutAdaptive => commands[CommandCodes.LayoutAdaptive];
public IRichCommand SortByName => commands[CommandCodes.SortByName];
Expand Down Expand Up @@ -284,9 +282,7 @@ public CommandManager()
[CommandCodes.LayoutDetails] = new LayoutDetailsAction(),
[CommandCodes.LayoutList] = new LayoutListAction(),
[CommandCodes.LayoutTiles] = new LayoutTilesAction(),
[CommandCodes.LayoutGridSmall] = new LayoutGridSmallAction(),
[CommandCodes.LayoutGridMedium] = new LayoutGridMediumAction(),
[CommandCodes.LayoutGridLarge] = new LayoutGridLargeAction(),
[CommandCodes.LayoutGrid] = new LayoutGridAction(),
[CommandCodes.LayoutColumns] = new LayoutColumnsAction(),
[CommandCodes.LayoutAdaptive] = new LayoutAdaptiveAction(),
[CommandCodes.SortByName] = new SortByNameAction(),
Expand Down
4 changes: 1 addition & 3 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand LayoutDetails { get; }
IRichCommand LayoutList { get; }
IRichCommand LayoutTiles { get; }
IRichCommand LayoutGridSmall { get; }
IRichCommand LayoutGridMedium { get; }
IRichCommand LayoutGridLarge { get; }
IRichCommand LayoutGrid { get; }
IRichCommand LayoutColumns { get; }
IRichCommand LayoutAdaptive { get; }

Expand Down
Loading