Skip to content
Open
20 changes: 20 additions & 0 deletions src/Files.App/Actions/Display/LayoutAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public override HotKey HotKey
[GeneratedRichCommand]
internal sealed partial class LayoutColumnsAction : ToggleLayoutAction
{
private readonly IContentPageContext ContentPageContext = Ioc.Default.GetRequiredService<IContentPageContext>();

protected override LayoutTypes LayoutType
=> LayoutTypes.Columns;

Expand All @@ -96,6 +98,24 @@ public override RichGlyph Glyph

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

public override bool IsExecutable
=> ContentPageContext.PageType is not ContentPageTypes.RecycleBin;

public LayoutColumnsAction()
{
ContentPageContext.PropertyChanged += ContentPageContext_PropertyChanged;
}

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

[GeneratedRichCommand]
Expand Down
44 changes: 44 additions & 0 deletions src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,28 @@ public static void SetLayoutPreferencesForPath(string path, LayoutPreferencesIte

private static LayoutPreferencesItem? GetLayoutPreferencesForPath(string path)
{
if (path.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal))
Copy link
Member

Choose a reason for hiding this comment

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

Can this code be reused on line 128 to reduce duplication?

{
var trimmedPath = path.TrimPath() ?? string.Empty;

var recycleBinPreference = SafetyExtensions.IgnoreExceptions(() =>
{
var folderFRN = Win32Helper.GetFolderFRN(trimmedPath);

return GetLayoutPreferencesFromDatabase(trimmedPath, folderFRN)
?? GetLayoutPreferencesFromAds(trimmedPath, folderFRN);
}, App.Logger);

if (recycleBinPreference is not null && recycleBinPreference.LayoutMode != FolderLayoutModes.ColumnView)
return recycleBinPreference;

var defaultPref = new LayoutPreferencesItem();
if (defaultPref.LayoutMode == FolderLayoutModes.ColumnView)
defaultPref.LayoutMode = FolderLayoutModes.DetailsView;

return defaultPref;
}

if (!UserSettingsService.LayoutSettingsService.SyncFolderPreferencesAcrossDirectories)
{
path = path.TrimPath() ?? string.Empty;
Expand All @@ -503,6 +525,28 @@ public static void SetLayoutPreferencesForPath(string path, LayoutPreferencesIte
?? GetDefaultLayoutPreferences(path);
}

if (path.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal))
{
var trimmedPath = path.TrimPath() ?? string.Empty;

var recycleBinPreference = SafetyExtensions.IgnoreExceptions(() =>
{
var folderFRN = Win32Helper.GetFolderFRN(trimmedPath);

return GetLayoutPreferencesFromDatabase(trimmedPath, folderFRN)
?? GetLayoutPreferencesFromAds(trimmedPath, folderFRN);
}, App.Logger);

if (recycleBinPreference is not null && recycleBinPreference.LayoutMode != FolderLayoutModes.ColumnView)
return recycleBinPreference;

var defaultPref = new LayoutPreferencesItem();
if (defaultPref.LayoutMode == FolderLayoutModes.ColumnView)
defaultPref.LayoutMode = FolderLayoutModes.DetailsView;

return defaultPref;
}

return new LayoutPreferencesItem();
}

Expand Down
Loading