Skip to content
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

Feature: Added option to set default column sizes #10117

Merged
139 changes: 72 additions & 67 deletions src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs
Original file line number Diff line number Diff line change
@@ -1,81 +1,86 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.ViewModels;
using Files.Backend.Services.Settings;
using Files.Shared.Enums;
using Files.App.ViewModels;

namespace Files.App.Helpers.LayoutPreferences
{
public class LayoutPreferences
{
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
public class LayoutPreferences
{
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();

public SortOption DirectorySortOption;
public SortDirection DirectorySortDirection;
public bool SortDirectoriesAlongsideFiles;
public GroupOption DirectoryGroupOption;
public FolderLayoutModes LayoutMode;
public int GridViewSize;
public bool IsAdaptiveLayoutOverridden;

public ColumnsViewModel ColumnsViewModel;

[LiteDB.BsonIgnore]
public static LayoutPreferences DefaultLayoutPreferences => new LayoutPreferences();

public SortOption DirectorySortOption;
public SortDirection DirectorySortDirection;
public bool SortDirectoriesAlongsideFiles;
public GroupOption DirectoryGroupOption;
public FolderLayoutModes LayoutMode;
public int GridViewSize;
public bool IsAdaptiveLayoutOverridden;
public LayoutPreferences()
{
this.LayoutMode = UserSettingsService.PreferencesSettingsService.DefaultLayoutMode;
this.GridViewSize = UserSettingsService.LayoutSettingsService.DefaultGridViewSize;
this.DirectorySortOption = UserSettingsService.LayoutSettingsService.DefaultDirectorySortOption;
this.DirectoryGroupOption = UserSettingsService.LayoutSettingsService.DefaultDirectoryGroupOption;
this.DirectorySortDirection = UserSettingsService.LayoutSettingsService.DefaultDirectorySortDirection;
this.SortDirectoriesAlongsideFiles = UserSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles;
this.IsAdaptiveLayoutOverridden = false;

public ColumnsViewModel ColumnsViewModel;
this.ColumnsViewModel = new ColumnsViewModel();
this.ColumnsViewModel.DateCreatedColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowDateCreatedColumn;
this.ColumnsViewModel.DateModifiedColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowDateColumn;
this.ColumnsViewModel.ItemTypeColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowTypeColumn;
this.ColumnsViewModel.SizeColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowSizeColumn;
this.ColumnsViewModel.TagColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowFileTagColumn;

[LiteDB.BsonIgnore]
public static LayoutPreferences DefaultLayoutPreferences => new LayoutPreferences();
this.ColumnsViewModel.NameColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.NameColumnWidth;
this.ColumnsViewModel.DateModifiedColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.DateModifiedColumnWidth;
this.ColumnsViewModel.DateCreatedColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.DateCreatedColumnWidth;
this.ColumnsViewModel.ItemTypeColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.TypeColumnWidth;
this.ColumnsViewModel.SizeColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.SizeColumnWidth;
this.ColumnsViewModel.TagColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.TagColumnWidth;
}

public LayoutPreferences()
{
this.LayoutMode = UserSettingsService.PreferencesSettingsService.DefaultLayoutMode;
this.GridViewSize = UserSettingsService.LayoutSettingsService.DefaultGridViewSize;
this.DirectorySortOption = UserSettingsService.LayoutSettingsService.DefaultDirectorySortOption;
this.DirectoryGroupOption = UserSettingsService.LayoutSettingsService.DefaultDirectoryGroupOption;
this.DirectorySortDirection = UserSettingsService.LayoutSettingsService.DefaultDirectorySortDirection;
this.SortDirectoriesAlongsideFiles = UserSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles;
this.IsAdaptiveLayoutOverridden = false;
public override bool Equals(object? obj)
{
if (obj == null)
return false;

this.ColumnsViewModel = new ColumnsViewModel();
this.ColumnsViewModel.DateCreatedColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowDateCreatedColumn;
this.ColumnsViewModel.DateModifiedColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowDateColumn;
this.ColumnsViewModel.ItemTypeColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowTypeColumn;
this.ColumnsViewModel.SizeColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowSizeColumn;
this.ColumnsViewModel.TagColumn.UserCollapsed = !UserSettingsService.PreferencesSettingsService.ShowFileTagColumn;
}
if (obj == this)
return true;

public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (obj == this)
{
return true;
}
if (obj is LayoutPreferences prefs)
{
return (
prefs.LayoutMode == this.LayoutMode &&
prefs.GridViewSize == this.GridViewSize &&
prefs.DirectoryGroupOption == this.DirectoryGroupOption &&
prefs.DirectorySortOption == this.DirectorySortOption &&
prefs.DirectorySortDirection == this.DirectorySortDirection &&
prefs.SortDirectoriesAlongsideFiles == this.SortDirectoriesAlongsideFiles &&
prefs.IsAdaptiveLayoutOverridden == this.IsAdaptiveLayoutOverridden &&
prefs.ColumnsViewModel.Equals(this.ColumnsViewModel));
}
return base.Equals(obj);
}
if (obj is LayoutPreferences prefs)
{
return (
prefs.LayoutMode == this.LayoutMode &&
prefs.GridViewSize == this.GridViewSize &&
prefs.DirectoryGroupOption == this.DirectoryGroupOption &&
prefs.DirectorySortOption == this.DirectorySortOption &&
prefs.DirectorySortDirection == this.DirectorySortDirection &&
prefs.SortDirectoriesAlongsideFiles == this.SortDirectoriesAlongsideFiles &&
prefs.IsAdaptiveLayoutOverridden == this.IsAdaptiveLayoutOverridden &&
prefs.ColumnsViewModel.Equals(this.ColumnsViewModel));
}
return base.Equals(obj);
}

public override int GetHashCode()
{
var hashCode = LayoutMode.GetHashCode();
hashCode = (hashCode * 397) ^ GridViewSize.GetHashCode();
hashCode = (hashCode * 397) ^ DirectoryGroupOption.GetHashCode();
hashCode = (hashCode * 397) ^ DirectorySortOption.GetHashCode();
hashCode = (hashCode * 397) ^ DirectorySortDirection.GetHashCode();
hashCode = (hashCode * 397) ^ SortDirectoriesAlongsideFiles.GetHashCode();
hashCode = (hashCode * 397) ^ IsAdaptiveLayoutOverridden.GetHashCode();
hashCode = (hashCode * 397) ^ ColumnsViewModel.GetHashCode();
return hashCode;
}
}
public override int GetHashCode()
{
var hashCode = LayoutMode.GetHashCode();
hashCode = (hashCode * 397) ^ GridViewSize.GetHashCode();
hashCode = (hashCode * 397) ^ DirectoryGroupOption.GetHashCode();
hashCode = (hashCode * 397) ^ DirectorySortOption.GetHashCode();
hashCode = (hashCode * 397) ^ DirectorySortDirection.GetHashCode();
hashCode = (hashCode * 397) ^ SortDirectoriesAlongsideFiles.GetHashCode();
hashCode = (hashCode * 397) ^ IsAdaptiveLayoutOverridden.GetHashCode();
hashCode = (hashCode * 397) ^ ColumnsViewModel.GetHashCode();
return hashCode;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
using Files.App.Serialization;
using Files.Backend.Services.Settings;
using Files.Shared.Enums;
using Files.App.Serialization;

namespace Files.App.ServicesImplementation.Settings
{
internal sealed class LayoutSettingsService : BaseObservableJsonSettings, ILayoutSettingsService
{
public LayoutSettingsService(ISettingsSharingContext settingsSharingContext)
{
// Register root
RegisterSettingsContext(settingsSharingContext);
}
internal sealed class LayoutSettingsService : BaseObservableJsonSettings, ILayoutSettingsService
{
public LayoutSettingsService(ISettingsSharingContext settingsSharingContext)
{
// Register root
RegisterSettingsContext(settingsSharingContext);
}

public int DefaultGridViewSize
{
get => (int)Get((long)Constants.Browser.GridViewBrowser.GridViewSizeSmall);
set => Set((long)value);
}
public int DefaultGridViewSize
{
get => (int)Get((long)Constants.Browser.GridViewBrowser.GridViewSizeSmall);
set => Set((long)value);
}

public SortDirection DefaultDirectorySortDirection
{
get => (SortDirection)Get((long)SortDirection.Ascending);
set => Set((long)value);
}
public SortDirection DefaultDirectorySortDirection
{
get => (SortDirection)Get((long)SortDirection.Ascending);
set => Set((long)value);
}

public SortOption DefaultDirectorySortOption
{
get => (SortOption)Get((long)SortOption.Name);
set => Set((long)value);
}
public bool DefaultSortDirectoriesAlongsideFiles
{
get => Get(false);
set => Set(value);
}
public SortOption DefaultDirectorySortOption
{
get => (SortOption)Get((long)SortOption.Name);
set => Set((long)value);
}
public bool DefaultSortDirectoriesAlongsideFiles
{
get => Get(false);
set => Set(value);
}

public GroupOption DefaultDirectoryGroupOption
{
get => (GroupOption)Get((long)GroupOption.None);
set => Set((long)value);
}
}
public GroupOption DefaultDirectoryGroupOption
{
get => (GroupOption)Get((long)GroupOption.None);
set => Set((long)value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,66 @@ public FolderLayoutModes DefaultLayoutMode
set => Set((long)value);
}

public double TagColumnWidth
{
get => Get(200d);
set
{
if (value != 0)
Copy link
Member

Choose a reason for hiding this comment

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

Is the value ever less than 0?

Copy link
Contributor Author

@ferrariofilippo ferrariofilippo Oct 6, 2022

Choose a reason for hiding this comment

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

I'll remove it as this is no more needed (I wrote that to fix a bug that involved recycle bin columns, but I fixed that another way)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yaichenbaum I found the reason I put there that code. I opened #10239 to fix it

Set(value);
}
}

public double NameColumnWidth
{
get => Get(200d);
set
{
if (value != 0)
Set(value);
}
}

public double DateModifiedColumnWidth
{
get => Get(200d);
set
{
if (value != 0)
Set(value);
}
}

public double TypeColumnWidth
{
get => Get(200d);
set
{
if (value != 0)
Set(value);
}
}

public double DateCreatedColumnWidth
{
get => Get(200d);
set
{
if (value != 0)
Set(value);
}
}

public double SizeColumnWidth
{
get => Get(200d);
set
{
if (value != 0)
Set(value);
}
}

protected override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
{
switch (e.SettingName)
Expand Down
Loading