-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
yaira2
merged 13 commits into
files-community:main
from
ferrariofilippo:Feature_Set_Column_Widths_Default_#9867
Oct 6, 2022
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2a5b869
Feature: Add menu option to set current directories column sizes as t…
ferrariofilippo dfa1b4e
Bug Fixed
ferrariofilippo d93802f
Merge branch 'main' into Feature_Set_Column_Widths_Default_#9867
ferrariofilippo 74b386d
Var names
ferrariofilippo 6964e7a
Merge branch 'Feature_Set_Column_Widths_Default_#9867' of https://git…
ferrariofilippo c03be31
Merge branch 'main' into Feature_Set_Column_Widths_Default_#9867
yaira2 346d1d8
Merge branch 'main' into Feature_Set_Column_Widths_Default_#9867
ferrariofilippo 0a15922
Merge branch 'main' into Feature_Set_Column_Widths_Default_#9867
yaira2 6a47303
Merge branch 'main' into pr/10117
yaira2 105af70
Refactor
yaira2 fffecb5
Update LayoutPreferences.cs
yaira2 c9c31af
Removed code not needed
ferrariofilippo ab43af8
Requested Changes
ferrariofilippo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
139 changes: 72 additions & 67 deletions
139
src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
70 changes: 35 additions & 35 deletions
70
src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)There was a problem hiding this comment.
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