From 2a5b8699a76094fc782f6855b33310306b71cb9c Mon Sep 17 00:00:00 2001 From: ferrariofilippo Date: Mon, 3 Oct 2022 21:32:13 +0200 Subject: [PATCH 1/7] Feature: Add menu option to set current directories column sizes as the default --- .../LayoutPreferences/LayoutPreferences.cs | 19 +-- .../Settings/LayoutSettingsService.cs | 40 ++++++- .../ViewModels/FolderSettingsViewModel.cs | 113 ++++++++---------- .../PreferencesViewModel.cs | 44 +------ .../Settings/ILayoutSettingsService.cs | 32 ++++- 5 files changed, 132 insertions(+), 116 deletions(-) diff --git a/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs b/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs index c353d12125c1..cbf3808ea854 100644 --- a/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs +++ b/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs @@ -1,13 +1,13 @@ 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.GetService(); + private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); public SortOption DirectorySortOption; public SortDirection DirectorySortDirection; @@ -38,18 +38,21 @@ public LayoutPreferences() this.ColumnsViewModel.ItemTypeColumn.UserCollapsed = !UserSettingsService.LayoutSettingsService.ShowTypeColumn; this.ColumnsViewModel.SizeColumn.UserCollapsed = !UserSettingsService.LayoutSettingsService.ShowSizeColumn; this.ColumnsViewModel.TagColumn.UserCollapsed = !UserSettingsService.LayoutSettingsService.ShowFileTagColumn; - } - public override bool Equals(object obj) + this.ColumnsViewModel.NameColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.NameColumnWidth; + this.ColumnsViewModel.DateModifiedColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.DateModifiedColumnWidth; + this.ColumnsViewModel.DateCreatedColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.DateCreatedColumnWidth; + this.ColumnsViewModel.ItemTypeColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.ItemTypeColumnWidth; + this.ColumnsViewModel.SizeColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.SizeColumnWidth; + this.ColumnsViewModel.TagColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.TagColumnWidth; + } + + public override bool Equals(object? obj) { if (obj == null) - { return false; - } if (obj == this) - { return true; - } if (obj is LayoutPreferences prefs) { return ( diff --git a/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs index a973f8c1141b..47f4262d6232 100644 --- a/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs @@ -1,6 +1,6 @@ +using Files.App.Serialization; using Files.Backend.Services.Settings; using Files.Shared.Enums; -using Files.App.Serialization; namespace Files.App.ServicesImplementation.Settings { @@ -42,7 +42,43 @@ public bool ShowFileTagColumn set => Set(value); } - public int DefaultGridViewSize + public double TagColumnWidth + { + get => Get(200d); + set => Set(value); + } + + public double NameColumnWidth + { + get => Get(200d); + set => Set(value); + } + + public double DateModifiedColumnWidth + { + get => Get(200d); + set => Set(value); + } + + public double ItemTypeColumnWidth + { + get => Get(200d); + set => Set(value); + } + + public double DateCreatedColumnWidth + { + get => Get(200d); + set => Set(value); + } + + public double SizeColumnWidth + { + get => Get(200d); + set => Set(value); + } + + public int DefaultGridViewSize { get => (int)Get((long)Constants.Browser.GridViewBrowser.GridViewSizeSmall); set => Set((long)value); diff --git a/src/Files.App/ViewModels/FolderSettingsViewModel.cs b/src/Files.App/ViewModels/FolderSettingsViewModel.cs index 3dca80208c84..1ac872a4fa70 100644 --- a/src/Files.App/ViewModels/FolderSettingsViewModel.cs +++ b/src/Files.App/ViewModels/FolderSettingsViewModel.cs @@ -1,17 +1,17 @@ -using Files.Shared.Enums; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.DependencyInjection; +using CommunityToolkit.Mvvm.Input; using Files.App.EventArguments; using Files.App.Helpers; using Files.App.Helpers.LayoutPreferences; -using Files.Backend.Services.Settings; using Files.App.Views.LayoutModes; -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.DependencyInjection; -using CommunityToolkit.Mvvm.Input; +using Files.Backend.Services.Settings; +using Files.Shared.Enums; +using Files.Shared.Extensions; using System; using System.Text.Json; using System.Windows.Input; using Windows.Storage; -using Files.Shared.Extensions; using IO = System.IO; namespace Files.App.ViewModels @@ -23,9 +23,9 @@ public class FolderSettingsViewModel : ObservableObject private static readonly Lazy dbInstance = new(() => new LayoutPrefsDb(LayoutSettingsDbPath, true)); public static LayoutPrefsDb DbInstance => dbInstance.Value; - public event EventHandler LayoutPreferencesUpdateRequired; + public event EventHandler? LayoutPreferencesUpdateRequired; - private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetService(); + private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); public FolderSettingsViewModel() { @@ -55,9 +55,7 @@ public bool IsAdaptiveLayoutEnabled set { if (SetProperty(ref LayoutPreference.IsAdaptiveLayoutOverridden, !value, nameof(IsAdaptiveLayoutEnabled))) - { LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference, true)); - } } } @@ -67,42 +65,27 @@ public FolderLayoutModes LayoutMode set { if (SetProperty(ref LayoutPreference.LayoutMode, value, nameof(LayoutMode))) - { LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); - } } } public uint GetIconSize() { if (LayoutMode == FolderLayoutModes.DetailsView) - { return Constants.Browser.DetailsLayoutBrowser.DetailsViewSize; // ListView thumbnail - } + if (LayoutMode == FolderLayoutModes.ColumnView) - { return Constants.Browser.ColumnViewBrowser.ColumnViewSize; // ListView thumbnail - } else if (LayoutMode == FolderLayoutModes.TilesView) - { return Constants.Browser.GridViewBrowser.GridViewSizeSmall; // Small thumbnail - } else if (GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeSmall) - { return Constants.Browser.GridViewBrowser.GridViewSizeSmall; // Small thumbnail - } else if (GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeMedium) - { return Constants.Browser.GridViewBrowser.GridViewSizeMedium; // Medium thumbnail - } else if (GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeLarge) - { return Constants.Browser.GridViewBrowser.GridViewSizeLarge; // Large thumbnail - } else - { return Constants.Browser.GridViewBrowser.GridViewSizeMax; // Extra large thumbnail - } } private bool isLayoutModeChanging; @@ -129,9 +112,9 @@ public Type GetLayoutType(string folderPath) }; } - public event EventHandler LayoutModeChangeRequested; + public event EventHandler? LayoutModeChangeRequested; - public event EventHandler GridViewSizeChangeRequested; + public event EventHandler? GridViewSizeChangeRequested; public ICommand ToggleLayoutModeGridViewLargeCommand { get; } public ICommand ToggleLayoutModeColumnViewCommand { get; } @@ -147,17 +130,11 @@ public GridViewSizeKind GridViewSizeKind get { if (GridViewSize < Constants.Browser.GridViewBrowser.GridViewSizeMedium) - { return GridViewSizeKind.Small; - } else if (GridViewSize >= Constants.Browser.GridViewBrowser.GridViewSizeMedium && GridViewSize < Constants.Browser.GridViewBrowser.GridViewSizeLarge) - { return GridViewSizeKind.Medium; - } else - { return GridViewSizeKind.Large; - } } } @@ -224,21 +201,19 @@ public int GridViewSize } if (value < Constants.Browser.GridViewBrowser.GridViewSizeMax) // Don't request a grid resize if it is already at the max size - { GridViewSizeChangeRequested?.Invoke(this, EventArgs.Empty); - } } } } } - public event EventHandler SortOptionPreferenceUpdated; + public event EventHandler? SortOptionPreferenceUpdated; - public event EventHandler GroupOptionPreferenceUpdated; + public event EventHandler? GroupOptionPreferenceUpdated; - public event EventHandler SortDirectionPreferenceUpdated; + public event EventHandler? SortDirectionPreferenceUpdated; - public event EventHandler SortDirectoriesAlongsideFilesPreferenceUpdated; + public event EventHandler? SortDirectoriesAlongsideFilesPreferenceUpdated; public SortOption DirectorySortOption { @@ -309,7 +284,7 @@ public ColumnsViewModel ColumnsViewModel private static LayoutPreferences GetLayoutPreferencesForPath(string folderPath) { - IUserSettingsService userSettingsService = Ioc.Default.GetService(); + IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); if (!userSettingsService.PreferencesSettingsService.ForceLayoutPreferencesOnAllDirectories) { folderPath = folderPath.TrimPath(); @@ -324,7 +299,7 @@ private static LayoutPreferences GetLayoutPreferencesForPath(string folderPath) public static void SetLayoutPreferencesForPath(string folderPath, LayoutPreferences prefs) { - IUserSettingsService userSettingsService = Ioc.Default.GetService(); + IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); if (!userSettingsService.PreferencesSettingsService.ForceLayoutPreferencesOnAllDirectories) { @@ -356,8 +331,15 @@ public static void SetLayoutPreferencesForPath(string folderPath, LayoutPreferen userSettingsService.LayoutSettingsService.ShowTypeColumn = !prefs.ColumnsViewModel.ItemTypeColumn.UserCollapsed; userSettingsService.LayoutSettingsService.ShowSizeColumn = !prefs.ColumnsViewModel.SizeColumn.UserCollapsed; userSettingsService.LayoutSettingsService.ShowFileTagColumn = !prefs.ColumnsViewModel.TagColumn.UserCollapsed; - } - } + + userSettingsService.LayoutSettingsService.NameColumnWidth = prefs.ColumnsViewModel.NameColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.DateModifiedColumnWidth = prefs.ColumnsViewModel.DateModifiedColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.DateCreatedColumnWidth = prefs.ColumnsViewModel.DateCreatedColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.ItemTypeColumnWidth = prefs.ColumnsViewModel.ItemTypeColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.SizeColumnWidth = prefs.ColumnsViewModel.SizeColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.TagColumnWidth = prefs.ColumnsViewModel.TagColumn.UserLengthPixels; + } + } private static LayoutPreferences ReadLayoutPreferencesFromAds(string folderPath, ulong? frn) { @@ -369,12 +351,10 @@ private static LayoutPreferences ReadLayoutPreferencesFromAds(string folderPath, return adsPrefs; } - private static LayoutPreferences ReadLayoutPreferencesFromDb(string folderPath, ulong? frn) + private static LayoutPreferences? ReadLayoutPreferencesFromDb(string folderPath, ulong? frn) { if (string.IsNullOrEmpty(folderPath)) - { return null; - } return DbInstance.GetPreferences(folderPath, frn); } @@ -382,41 +362,27 @@ private static LayoutPreferences ReadLayoutPreferencesFromDb(string folderPath, private static LayoutPreferences GetDefaultLayoutPreferences(string folderPath) { if (string.IsNullOrEmpty(folderPath)) - { return LayoutPreferences.DefaultLayoutPreferences; - } - - IUserSettingsService userSettingsService = Ioc.Default.GetService(); if (folderPath == CommonPaths.DownloadsPath) - { // Default for downloads folder is to group by date created return new LayoutPreferences() { DirectoryGroupOption = GroupOption.DateCreated }; - } else if (LibraryHelper.IsLibraryPath(folderPath)) - { // Default for libraries is to group by folder path return new LayoutPreferences() { DirectoryGroupOption = GroupOption.FolderPath }; - } else - { return LayoutPreferences.DefaultLayoutPreferences; // Either global setting or smart guess - } } private static void WriteLayoutPreferencesToDb(string folderPath, ulong? frn, LayoutPreferences prefs) { if (string.IsNullOrEmpty(folderPath)) - { return; - } if (DbInstance.GetPreferences(folderPath, frn) is null) { if (LayoutPreferences.DefaultLayoutPreferences.Equals(prefs)) - { return; // Do not create setting if it's default - } } DbInstance.SetPreferences(folderPath, frn, prefs); } @@ -538,13 +504,30 @@ public void OnDefaultPreferencesChanged(string folderPath, string settingsName) public void SetDefaultLayoutPreferences(ColumnsViewModel columns) { - IUserSettingsService userSettingsService = Ioc.Default.GetService(); + IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); userSettingsService.LayoutSettingsService.ShowDateColumn = !columns.DateModifiedColumn.UserCollapsed; userSettingsService.LayoutSettingsService.ShowDateCreatedColumn = !columns.DateCreatedColumn.UserCollapsed; userSettingsService.LayoutSettingsService.ShowTypeColumn = !columns.ItemTypeColumn.UserCollapsed; userSettingsService.LayoutSettingsService.ShowSizeColumn = !columns.SizeColumn.UserCollapsed; userSettingsService.LayoutSettingsService.ShowFileTagColumn = !columns.TagColumn.UserCollapsed; - //TODO: save column sizes - } - } + + userSettingsService.LayoutSettingsService.NameColumnWidth = columns.NameColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.DateModifiedColumnWidth = columns.DateModifiedColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.DateCreatedColumnWidth = columns.DateCreatedColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.ItemTypeColumnWidth = columns.ItemTypeColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.SizeColumnWidth = columns.SizeColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.TagColumnWidth = columns.TagColumn.UserLengthPixels; + } + + public static void ResetColumnsWidth() + { + IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); + userSettingsService.LayoutSettingsService.NameColumnWidth = 200d; + userSettingsService.LayoutSettingsService.DateModifiedColumnWidth = 200d; + userSettingsService.LayoutSettingsService.DateCreatedColumnWidth = 200d; + userSettingsService.LayoutSettingsService.ItemTypeColumnWidth = 200d; + userSettingsService.LayoutSettingsService.SizeColumnWidth = 200d; + userSettingsService.LayoutSettingsService.TagColumnWidth = 200d; + } + } } diff --git a/src/Files.App/ViewModels/SettingsViewModels/PreferencesViewModel.cs b/src/Files.App/ViewModels/SettingsViewModels/PreferencesViewModel.cs index f68403abfc13..a31e36a0be95 100644 --- a/src/Files.App/ViewModels/SettingsViewModels/PreferencesViewModel.cs +++ b/src/Files.App/ViewModels/SettingsViewModels/PreferencesViewModel.cs @@ -30,7 +30,7 @@ namespace Files.App.ViewModels.SettingsViewModels { public class PreferencesViewModel : ObservableObject, IDisposable { - private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetService(); + private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); private bool disposed; private ReadOnlyCollection addFlyoutItemsSource; @@ -65,9 +65,7 @@ public int SelectedPageIndex set { if (SetProperty(ref selectedPageIndex, value)) - { IsPageListEditEnabled = value >= 0; - } } } @@ -146,7 +144,6 @@ public bool IsResetLayoutPreferencesTipOpen public ObservableCollection Terminals { get; set; } public ObservableCollection AppLanguages { get; set; } - public PreferencesViewModel() { EditTerminalApplicationsCommand = new AsyncRelayCommand(LaunchTerminalsConfigFile); @@ -170,13 +167,9 @@ public PreferencesViewModel() App.TerminalController.ModelChanged += ReloadTerminals; if (UserSettingsService.PreferencesSettingsService.TabsOnStartupList != null) - { PagesOnStartupList = new ObservableCollection(UserSettingsService.PreferencesSettingsService.TabsOnStartupList.Select((p) => new PageOnStartupViewModel(p))); - } else - { PagesOnStartupList = new ObservableCollection(); - } PagesOnStartupList.CollectionChanged += PagesOnStartupList_CollectionChanged; @@ -198,9 +191,7 @@ private void AddSupportedAppLanguages() AppLanguages = new ObservableCollection { }; foreach (var language in supportedLanguages) - { AppLanguages.Add(new AppLanguageItem(language)); - } SelectedAppLanguageIndex = AppLanguages.IndexOf(AppLanguages.FirstOrDefault(dl => dl.LanguagID == ApplicationLanguages.PrimaryLanguageOverride) ?? AppLanguages.FirstOrDefault()); } @@ -233,9 +224,7 @@ private Task PopulateRecentItems(MenuFlyoutSubItemViewModel menu) // add separator if (recentFolders.Any()) - { menu.Items.Add(new MenuFlyoutSeparatorViewModel()); - } foreach (var recentFolder in recentFolders) { @@ -259,13 +248,9 @@ private Task PopulateRecentItems(MenuFlyoutSubItemViewModel menu) private void PagesOnStartupList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (PagesOnStartupList.Count > 0) - { UserSettingsService.PreferencesSettingsService.TabsOnStartupList = PagesOnStartupList.Select((p) => p.Path).ToList(); - } else - { UserSettingsService.PreferencesSettingsService.TabsOnStartupList = null; - } } public int SelectedStartupSettingIndex => ContinueLastSessionOnStartUp ? 1 : OpenASpecificPageOnStartup ? 2 : 0; @@ -311,14 +296,12 @@ public bool OpenASpecificPageOnStartup public ObservableCollection PagesOnStartupList { get; set; } - - - public ReadOnlyCollection AddFlyoutItemsSource { get => addFlyoutItemsSource; set => SetProperty(ref addFlyoutItemsSource, value); } + public bool AlwaysOpenANewInstance { get => UserSettingsService.PreferencesSettingsService.AlwaysOpenNewInstance; @@ -342,9 +325,7 @@ private async Task ChangePage() if (folder != null) { if (SelectedPageIndex >= 0) - { PagesOnStartupList[SelectedPageIndex] = new PageOnStartupViewModel(folder.Path); - } } } @@ -362,13 +343,9 @@ private void RemovePage() { PagesOnStartupList.RemoveAt(index); if (index > 0) - { SelectedPageIndex = index - 1; - } else if (PagesOnStartupList.Count > 0) - { SelectedPageIndex = 0; - } } } @@ -381,15 +358,11 @@ private async Task AddPage(string path = null) var folder = await folderPicker.PickSingleFolderAsync(); if (folder != null) - { path = folder.Path; - } } if (path != null && PagesOnStartupList != null) - { PagesOnStartupList.Add(new PageOnStartupViewModel(path)); - } } public class PageOnStartupViewModel @@ -399,13 +372,9 @@ public string Text get { if (Path == "Home".GetLocalizedResource()) - { return "Home".GetLocalizedResource(); - } if (Path == CommonPaths.RecycleBinPath) - { return ApplicationData.Current.LocalSettings.Values.Get("RecycleBin_Title", "Recycle Bin"); - } return Path; } } @@ -475,9 +444,7 @@ private async Task LaunchTerminalsConfigFile() var configFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/settings/terminal.json")); if (!await Launcher.LaunchFileAsync(configFile)) - { await ContextMenu.InvokeVerb("open", configFile.Path); - } } private bool openInLogin; @@ -513,13 +480,9 @@ public async Task OpenFilesAtStartup() { StartupTask startupTask = await StartupTask.GetAsync("3AA55462-A5FA-4933-88C4-712D0B6CDEBB"); if (OpenInLogin) - { await startupTask.RequestEnableAsync(); - } else - { startupTask.Disable(); - } await DetectOpenFilesAtStartup(); } } @@ -562,6 +525,7 @@ public async Task ReadState() public void ResetLayoutPreferences() { FolderSettingsViewModel.DbInstance.ResetAll(); + FolderSettingsViewModel.ResetColumnsWidth(); IsResetLayoutPreferencesTipOpen = false; IsLayoutResetCheckmarkVisible = true; } @@ -851,7 +815,7 @@ public class DateTimeFormatItem public DateTimeFormatItem(DateTimeFormats style, DateTimeOffset sampleDate1, DateTimeOffset sampleDate2) { - var factory = Ioc.Default.GetService(); + var factory = Ioc.Default.GetRequiredService(); var formatter = factory.GetDateTimeFormatter(style); Label = formatter.Name; diff --git a/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs b/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs index 9799c773d652..55385d013e28 100644 --- a/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs +++ b/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs @@ -30,7 +30,37 @@ public interface ILayoutSettingsService : IBaseSettingsService, INotifyPropertyC /// bool ShowFileTagColumn { get; set; } - int DefaultGridViewSize { get; set; } + /// + /// Gets or sets a value indicating tags column's default width + /// + double TagColumnWidth { get; set; } + + /// + /// Gets or sets a value indicating name column's default width + /// + double NameColumnWidth { get; set; } + + /// + /// Gets or sets a value indicating date modified column's default width + /// + double DateModifiedColumnWidth { get; set; } + + /// + /// Gets or sets a value indicating item type column's default width + /// + double ItemTypeColumnWidth { get; set; } + + /// + /// Gets or sets a value indicating date created column's default width + /// + double DateCreatedColumnWidth { get; set; } + + /// + /// Gets or sets a value indicating size column's default width + /// + double SizeColumnWidth { get; set; } + + int DefaultGridViewSize { get; set; } FolderLayoutModes DefaultLayoutMode { get; set; } From dfa1b4e9072e38d85718a954e9073e838ab4415d Mon Sep 17 00:00:00 2001 From: ferrariofilippo Date: Mon, 3 Oct 2022 21:46:48 +0200 Subject: [PATCH 2/7] Bug Fixed --- .../Settings/LayoutSettingsService.cs | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs index 47f4262d6232..31bf4dae349b 100644 --- a/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs @@ -45,37 +45,61 @@ public bool ShowFileTagColumn public double TagColumnWidth { get => Get(200d); - set => Set(value); + set + { + if (value != 0) + Set(value); + } } public double NameColumnWidth { get => Get(200d); - set => Set(value); + set + { + if (value != 0) + Set(value); + } } public double DateModifiedColumnWidth { get => Get(200d); - set => Set(value); + set + { + if (value != 0) + Set(value); + } } public double ItemTypeColumnWidth { get => Get(200d); - set => Set(value); + set + { + if (value != 0) + Set(value); + } } public double DateCreatedColumnWidth { get => Get(200d); - set => Set(value); + set + { + if (value != 0) + Set(value); + } } public double SizeColumnWidth { get => Get(200d); - set => Set(value); + set + { + if (value != 0) + Set(value); + } } public int DefaultGridViewSize From 74b386d9d66ad5eb33b65691820b742a76de6a68 Mon Sep 17 00:00:00 2001 From: ferrariofilippo Date: Mon, 3 Oct 2022 22:46:51 +0200 Subject: [PATCH 3/7] Var names --- .../Helpers/LayoutPreferences/LayoutPreferences.cs | 2 +- .../Settings/LayoutSettingsService.cs | 2 +- src/Files.App/ViewModels/FolderSettingsViewModel.cs | 6 +++--- .../Services/Settings/ILayoutSettingsService.cs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs b/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs index cbf3808ea854..6b70e7dc0294 100644 --- a/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs +++ b/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs @@ -42,7 +42,7 @@ public LayoutPreferences() this.ColumnsViewModel.NameColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.NameColumnWidth; this.ColumnsViewModel.DateModifiedColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.DateModifiedColumnWidth; this.ColumnsViewModel.DateCreatedColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.DateCreatedColumnWidth; - this.ColumnsViewModel.ItemTypeColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.ItemTypeColumnWidth; + this.ColumnsViewModel.ItemTypeColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.TypeColumnWidth; this.ColumnsViewModel.SizeColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.SizeColumnWidth; this.ColumnsViewModel.TagColumn.UserLengthPixels = UserSettingsService.LayoutSettingsService.TagColumnWidth; } diff --git a/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs index 31bf4dae349b..e8ed7184c7eb 100644 --- a/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/LayoutSettingsService.cs @@ -72,7 +72,7 @@ public double DateModifiedColumnWidth } } - public double ItemTypeColumnWidth + public double TypeColumnWidth { get => Get(200d); set diff --git a/src/Files.App/ViewModels/FolderSettingsViewModel.cs b/src/Files.App/ViewModels/FolderSettingsViewModel.cs index 1ac872a4fa70..53d57fb9ad9d 100644 --- a/src/Files.App/ViewModels/FolderSettingsViewModel.cs +++ b/src/Files.App/ViewModels/FolderSettingsViewModel.cs @@ -335,7 +335,7 @@ public static void SetLayoutPreferencesForPath(string folderPath, LayoutPreferen userSettingsService.LayoutSettingsService.NameColumnWidth = prefs.ColumnsViewModel.NameColumn.UserLengthPixels; userSettingsService.LayoutSettingsService.DateModifiedColumnWidth = prefs.ColumnsViewModel.DateModifiedColumn.UserLengthPixels; userSettingsService.LayoutSettingsService.DateCreatedColumnWidth = prefs.ColumnsViewModel.DateCreatedColumn.UserLengthPixels; - userSettingsService.LayoutSettingsService.ItemTypeColumnWidth = prefs.ColumnsViewModel.ItemTypeColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.TypeColumnWidth = prefs.ColumnsViewModel.ItemTypeColumn.UserLengthPixels; userSettingsService.LayoutSettingsService.SizeColumnWidth = prefs.ColumnsViewModel.SizeColumn.UserLengthPixels; userSettingsService.LayoutSettingsService.TagColumnWidth = prefs.ColumnsViewModel.TagColumn.UserLengthPixels; } @@ -514,7 +514,7 @@ public void SetDefaultLayoutPreferences(ColumnsViewModel columns) userSettingsService.LayoutSettingsService.NameColumnWidth = columns.NameColumn.UserLengthPixels; userSettingsService.LayoutSettingsService.DateModifiedColumnWidth = columns.DateModifiedColumn.UserLengthPixels; userSettingsService.LayoutSettingsService.DateCreatedColumnWidth = columns.DateCreatedColumn.UserLengthPixels; - userSettingsService.LayoutSettingsService.ItemTypeColumnWidth = columns.ItemTypeColumn.UserLengthPixels; + userSettingsService.LayoutSettingsService.TypeColumnWidth = columns.ItemTypeColumn.UserLengthPixels; userSettingsService.LayoutSettingsService.SizeColumnWidth = columns.SizeColumn.UserLengthPixels; userSettingsService.LayoutSettingsService.TagColumnWidth = columns.TagColumn.UserLengthPixels; } @@ -525,7 +525,7 @@ public static void ResetColumnsWidth() userSettingsService.LayoutSettingsService.NameColumnWidth = 200d; userSettingsService.LayoutSettingsService.DateModifiedColumnWidth = 200d; userSettingsService.LayoutSettingsService.DateCreatedColumnWidth = 200d; - userSettingsService.LayoutSettingsService.ItemTypeColumnWidth = 200d; + userSettingsService.LayoutSettingsService.TypeColumnWidth = 200d; userSettingsService.LayoutSettingsService.SizeColumnWidth = 200d; userSettingsService.LayoutSettingsService.TagColumnWidth = 200d; } diff --git a/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs b/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs index 55385d013e28..3a6b929c14ba 100644 --- a/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs +++ b/src/Files.Backend/Services/Settings/ILayoutSettingsService.cs @@ -48,7 +48,7 @@ public interface ILayoutSettingsService : IBaseSettingsService, INotifyPropertyC /// /// Gets or sets a value indicating item type column's default width /// - double ItemTypeColumnWidth { get; set; } + double TypeColumnWidth { get; set; } /// /// Gets or sets a value indicating date created column's default width From 105af70bfa83dd64f7829a52900c6906ac5aa969 Mon Sep 17 00:00:00 2001 From: Yair Aichenbaum <39923744+yaichenbaum@users.noreply.github.com> Date: Thu, 6 Oct 2022 11:19:38 -0400 Subject: [PATCH 4/7] Refactor --- .../Settings/PreferencesSettingsService.cs | 60 ++ .../ViewModels/FolderSettingsViewModel.cs | 966 +++++++++--------- .../Settings/IPreferencesSettingsService.cs | 30 + 3 files changed, 573 insertions(+), 483 deletions(-) diff --git a/src/Files.App/ServicesImplementation/Settings/PreferencesSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/PreferencesSettingsService.cs index dd8ef6ac47e9..b5645ce94540 100644 --- a/src/Files.App/ServicesImplementation/Settings/PreferencesSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/PreferencesSettingsService.cs @@ -189,6 +189,66 @@ public FolderLayoutModes DefaultLayoutMode set => Set((long)value); } + public double TagColumnWidth + { + get => Get(200d); + set + { + if (value != 0) + 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) diff --git a/src/Files.App/ViewModels/FolderSettingsViewModel.cs b/src/Files.App/ViewModels/FolderSettingsViewModel.cs index a76cb017c048..8d19f20a1857 100644 --- a/src/Files.App/ViewModels/FolderSettingsViewModel.cs +++ b/src/Files.App/ViewModels/FolderSettingsViewModel.cs @@ -16,324 +16,324 @@ namespace Files.App.ViewModels { - public class FolderSettingsViewModel : ObservableObject - { - public static string LayoutSettingsDbPath => IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, "user_settings.db"); - - private static readonly Lazy dbInstance = new(() => new LayoutPrefsDb(LayoutSettingsDbPath, true)); - public static LayoutPrefsDb DbInstance => dbInstance.Value; - - public event EventHandler? LayoutPreferencesUpdateRequired; - - private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); - - public FolderSettingsViewModel() - { - LayoutPreference = new LayoutPreferences(); - - ToggleLayoutModeGridViewLargeCommand = new RelayCommand(ToggleLayoutModeGridViewLarge); - ToggleLayoutModeColumnViewCommand = new RelayCommand(ToggleLayoutModeColumnView); - ToggleLayoutModeGridViewMediumCommand = new RelayCommand(ToggleLayoutModeGridViewMedium); - ToggleLayoutModeGridViewSmallCommand = new RelayCommand(ToggleLayoutModeGridViewSmall); - ToggleLayoutModeGridViewCommand = new RelayCommand(ToggleLayoutModeGridView); - ToggleLayoutModeTilesCommand = new RelayCommand(ToggleLayoutModeTiles); - ToggleLayoutModeDetailsViewCommand = new RelayCommand(ToggleLayoutModeDetailsView); - ToggleLayoutModeAdaptiveCommand = new RelayCommand(ToggleLayoutModeAdaptive); - - ChangeGroupOptionCommand = new RelayCommand(ChangeGroupOption); - } - public FolderSettingsViewModel(FolderLayoutModes modeOverride) : this() - => (rootLayoutMode, LayoutPreference.IsAdaptiveLayoutOverridden) = (modeOverride, true); - - private readonly FolderLayoutModes? rootLayoutMode; - - public bool IsLayoutModeFixed => rootLayoutMode is not null; - - public bool IsAdaptiveLayoutEnabled - { - get => !LayoutPreference.IsAdaptiveLayoutOverridden; - set - { - if (SetProperty(ref LayoutPreference.IsAdaptiveLayoutOverridden, !value, nameof(IsAdaptiveLayoutEnabled))) - LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference, true)); - } - } - - public FolderLayoutModes LayoutMode - { - get => rootLayoutMode ?? LayoutPreference.LayoutMode; - set - { - if (SetProperty(ref LayoutPreference.LayoutMode, value, nameof(LayoutMode))) - LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); - } - } - - public uint GetIconSize() - { - if (LayoutMode == FolderLayoutModes.DetailsView) - return Constants.Browser.DetailsLayoutBrowser.DetailsViewSize; // ListView thumbnail - - if (LayoutMode == FolderLayoutModes.ColumnView) - return Constants.Browser.ColumnViewBrowser.ColumnViewSize; // ListView thumbnail - else if (LayoutMode == FolderLayoutModes.TilesView) - return Constants.Browser.GridViewBrowser.GridViewSizeSmall; // Small thumbnail - else if (GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeSmall) - return Constants.Browser.GridViewBrowser.GridViewSizeSmall; // Small thumbnail - else if (GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeMedium) - return Constants.Browser.GridViewBrowser.GridViewSizeMedium; // Medium thumbnail - else if (GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeLarge) - return Constants.Browser.GridViewBrowser.GridViewSizeLarge; // Large thumbnail - else - return Constants.Browser.GridViewBrowser.GridViewSizeMax; // Extra large thumbnail - } - - private bool isLayoutModeChanging; - - public bool IsLayoutModeChanging - { - get => isLayoutModeChanging; - set => SetProperty(ref isLayoutModeChanging, value); - } - - public Type GetLayoutType(string folderPath) - { - var prefsForPath = GetLayoutPreferencesForPath(folderPath); - IsLayoutModeChanging = LayoutPreference.LayoutMode != prefsForPath.LayoutMode; - LayoutPreference = prefsForPath; - - return (prefsForPath.LayoutMode) switch - { - FolderLayoutModes.DetailsView => typeof(DetailsLayoutBrowser), - FolderLayoutModes.TilesView => typeof(GridViewBrowser), - FolderLayoutModes.GridView => typeof(GridViewBrowser), - FolderLayoutModes.ColumnView => typeof(ColumnViewBrowser), - _ => typeof(DetailsLayoutBrowser) - }; - } - - public event EventHandler? LayoutModeChangeRequested; - - public event EventHandler? GridViewSizeChangeRequested; - - public ICommand ToggleLayoutModeGridViewLargeCommand { get; } - public ICommand ToggleLayoutModeColumnViewCommand { get; } - public ICommand ToggleLayoutModeGridViewMediumCommand { get; } - public ICommand ToggleLayoutModeGridViewSmallCommand { get; } - public ICommand ToggleLayoutModeGridViewCommand { get; } - public ICommand ToggleLayoutModeTilesCommand { get; } - public ICommand ToggleLayoutModeDetailsViewCommand { get; } - public ICommand ToggleLayoutModeAdaptiveCommand { get; } - - public GridViewSizeKind GridViewSizeKind - { - get - { - if (GridViewSize < Constants.Browser.GridViewBrowser.GridViewSizeMedium) - return GridViewSizeKind.Small; - else if (GridViewSize >= Constants.Browser.GridViewBrowser.GridViewSizeMedium && GridViewSize < Constants.Browser.GridViewBrowser.GridViewSizeLarge) - return GridViewSizeKind.Medium; - else - return GridViewSizeKind.Large; - } - } - - public int GridViewSize - { - get => LayoutPreference.GridViewSize; - set - { - if (value < LayoutPreference.GridViewSize) // Size down - { - if (LayoutMode == FolderLayoutModes.TilesView) // Size down from tiles to list - { - LayoutPreference.IsAdaptiveLayoutOverridden = true; - LayoutMode = FolderLayoutModes.DetailsView; - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); - } - else if (LayoutMode == FolderLayoutModes.GridView && value < Constants.Browser.GridViewBrowser.GridViewSizeSmall) // Size down from grid to tiles - { - LayoutPreference.IsAdaptiveLayoutOverridden = true; - LayoutMode = FolderLayoutModes.TilesView; - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); - } - else if (LayoutMode != FolderLayoutModes.DetailsView) // Resize grid view - { - var newValue = (value >= Constants.Browser.GridViewBrowser.GridViewSizeSmall) ? value : Constants.Browser.GridViewBrowser.GridViewSizeSmall; // Set grid size to allow immediate UI update - SetProperty(ref LayoutPreference.GridViewSize, newValue, nameof(GridViewSize)); - - if (LayoutMode != FolderLayoutModes.GridView) // Only update layout mode if it isn't already in grid view - { - LayoutPreference.IsAdaptiveLayoutOverridden = true; - LayoutMode = FolderLayoutModes.GridView; - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); - } - else - { - LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); - } - - GridViewSizeChangeRequested?.Invoke(this, EventArgs.Empty); - } - } - else if (value > LayoutPreference.GridViewSize) // Size up - { - if (LayoutMode == FolderLayoutModes.DetailsView) // Size up from list to tiles - { - LayoutPreference.IsAdaptiveLayoutOverridden = true; - LayoutMode = FolderLayoutModes.TilesView; - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); - } - else // Size up from tiles to grid - { - var newValue = (LayoutMode == FolderLayoutModes.TilesView) ? Constants.Browser.GridViewBrowser.GridViewSizeSmall : (value <= Constants.Browser.GridViewBrowser.GridViewSizeMax) ? value : Constants.Browser.GridViewBrowser.GridViewSizeMax; // Set grid size to allow immediate UI update - SetProperty(ref LayoutPreference.GridViewSize, newValue, nameof(GridViewSize)); - - if (LayoutMode != FolderLayoutModes.GridView) // Only update layout mode if it isn't already in grid view - { - LayoutPreference.IsAdaptiveLayoutOverridden = true; - LayoutMode = FolderLayoutModes.GridView; - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); - } - else - { - LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); - } - - if (value < Constants.Browser.GridViewBrowser.GridViewSizeMax) // Don't request a grid resize if it is already at the max size - GridViewSizeChangeRequested?.Invoke(this, EventArgs.Empty); - } - } - } - } - - public event EventHandler? SortOptionPreferenceUpdated; - - public event EventHandler? GroupOptionPreferenceUpdated; - - public event EventHandler? SortDirectionPreferenceUpdated; - - public event EventHandler? SortDirectoriesAlongsideFilesPreferenceUpdated; - - public SortOption DirectorySortOption - { - get => LayoutPreference.DirectorySortOption; - set - { - if (SetProperty(ref LayoutPreference.DirectorySortOption, value, nameof(DirectorySortOption))) - { - LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); - SortOptionPreferenceUpdated?.Invoke(this, DirectorySortOption); - } - } - } - - public ICommand ChangeGroupOptionCommand { get; } - - public GroupOption DirectoryGroupOption - { - get => LayoutPreference.DirectoryGroupOption; - set - { - if (SetProperty(ref LayoutPreference.DirectoryGroupOption, value, nameof(DirectoryGroupOption))) - { - LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); - GroupOptionPreferenceUpdated?.Invoke(this, DirectoryGroupOption); - } - } - } - - public SortDirection DirectorySortDirection - { - get => LayoutPreference.DirectorySortDirection; - set - { - if (SetProperty(ref LayoutPreference.DirectorySortDirection, value, nameof(DirectorySortDirection))) - { - LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); - SortDirectionPreferenceUpdated?.Invoke(this, DirectorySortDirection); - } - } - } - - public bool SortDirectoriesAlongsideFiles - { - get - { - return LayoutPreference.SortDirectoriesAlongsideFiles; - } - set - { - if (SetProperty(ref LayoutPreference.SortDirectoriesAlongsideFiles, value, nameof(SortDirectoriesAlongsideFiles))) - { - LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); - SortDirectoriesAlongsideFilesPreferenceUpdated?.Invoke(this, SortDirectoriesAlongsideFiles); - } - } - } - - public ColumnsViewModel ColumnsViewModel - { - get => LayoutPreference.ColumnsViewModel; - set - { - SetProperty(ref LayoutPreference.ColumnsViewModel, value, nameof(ColumnsViewModel)); - LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); - } - } - - private static LayoutPreferences GetLayoutPreferencesForPath(string folderPath) - { - IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); - if (!userSettingsService.PreferencesSettingsService.ForceLayoutPreferencesOnAllDirectories) - { - folderPath = folderPath.TrimPath(); - var folderFRN = NativeFileOperationsHelper.GetFolderFRN(folderPath); - return ReadLayoutPreferencesFromDb(folderPath, folderFRN) - ?? ReadLayoutPreferencesFromAds(folderPath, folderFRN) - ?? GetDefaultLayoutPreferences(folderPath); - } - - return LayoutPreferences.DefaultLayoutPreferences; - } - - public static void SetLayoutPreferencesForPath(string folderPath, LayoutPreferences prefs) - { - IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); - - if (!userSettingsService.PreferencesSettingsService.ForceLayoutPreferencesOnAllDirectories) - { - var folderFRN = NativeFileOperationsHelper.GetFolderFRN(folderPath); - WriteLayoutPreferencesToDb(folderPath.TrimPath(), folderFRN, prefs); - } - else - { - userSettingsService.PreferencesSettingsService.DefaultLayoutMode = prefs.LayoutMode; - userSettingsService.LayoutSettingsService.DefaultGridViewSize = prefs.GridViewSize; - // Do not save OriginalPath as global sort option (only works in recycle bin) - if (prefs.DirectorySortOption != SortOption.OriginalFolder && - prefs.DirectorySortOption != SortOption.DateDeleted && - prefs.DirectorySortOption != SortOption.SyncStatus) - { - userSettingsService.LayoutSettingsService.DefaultDirectorySortOption = prefs.DirectorySortOption; - } - if (prefs.DirectoryGroupOption != GroupOption.OriginalFolder && - prefs.DirectoryGroupOption != GroupOption.DateDeleted && - prefs.DirectoryGroupOption != GroupOption.FolderPath && - prefs.DirectoryGroupOption != GroupOption.SyncStatus) - { - userSettingsService.LayoutSettingsService.DefaultDirectoryGroupOption = prefs.DirectoryGroupOption; - } - userSettingsService.LayoutSettingsService.DefaultDirectorySortDirection = prefs.DirectorySortDirection; - userSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles = prefs.SortDirectoriesAlongsideFiles; - - userSettingsService.PreferencesSettingsService.ShowDateColumn = !prefs.ColumnsViewModel.DateModifiedColumn.UserCollapsed; - userSettingsService.PreferencesSettingsService.ShowDateCreatedColumn = !prefs.ColumnsViewModel.DateCreatedColumn.UserCollapsed; - userSettingsService.PreferencesSettingsService.ShowTypeColumn = !prefs.ColumnsViewModel.ItemTypeColumn.UserCollapsed; - userSettingsService.PreferencesSettingsService.ShowSizeColumn = !prefs.ColumnsViewModel.SizeColumn.UserCollapsed; - userSettingsService.PreferencesSettingsService.ShowFileTagColumn = !prefs.ColumnsViewModel.TagColumn.UserCollapsed; - - userSettingsService.PreferencesSettingsService.NameColumnWidth = prefs.ColumnsViewModel.NameColumn.UserLengthPixels; + public class FolderSettingsViewModel : ObservableObject + { + public static string LayoutSettingsDbPath => IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, "user_settings.db"); + + private static readonly Lazy dbInstance = new(() => new LayoutPrefsDb(LayoutSettingsDbPath, true)); + public static LayoutPrefsDb DbInstance => dbInstance.Value; + + public event EventHandler? LayoutPreferencesUpdateRequired; + + private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); + + public FolderSettingsViewModel() + { + LayoutPreference = new LayoutPreferences(); + + ToggleLayoutModeGridViewLargeCommand = new RelayCommand(ToggleLayoutModeGridViewLarge); + ToggleLayoutModeColumnViewCommand = new RelayCommand(ToggleLayoutModeColumnView); + ToggleLayoutModeGridViewMediumCommand = new RelayCommand(ToggleLayoutModeGridViewMedium); + ToggleLayoutModeGridViewSmallCommand = new RelayCommand(ToggleLayoutModeGridViewSmall); + ToggleLayoutModeGridViewCommand = new RelayCommand(ToggleLayoutModeGridView); + ToggleLayoutModeTilesCommand = new RelayCommand(ToggleLayoutModeTiles); + ToggleLayoutModeDetailsViewCommand = new RelayCommand(ToggleLayoutModeDetailsView); + ToggleLayoutModeAdaptiveCommand = new RelayCommand(ToggleLayoutModeAdaptive); + + ChangeGroupOptionCommand = new RelayCommand(ChangeGroupOption); + } + public FolderSettingsViewModel(FolderLayoutModes modeOverride) : this() + => (rootLayoutMode, LayoutPreference.IsAdaptiveLayoutOverridden) = (modeOverride, true); + + private readonly FolderLayoutModes? rootLayoutMode; + + public bool IsLayoutModeFixed => rootLayoutMode is not null; + + public bool IsAdaptiveLayoutEnabled + { + get => !LayoutPreference.IsAdaptiveLayoutOverridden; + set + { + if (SetProperty(ref LayoutPreference.IsAdaptiveLayoutOverridden, !value, nameof(IsAdaptiveLayoutEnabled))) + LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference, true)); + } + } + + public FolderLayoutModes LayoutMode + { + get => rootLayoutMode ?? LayoutPreference.LayoutMode; + set + { + if (SetProperty(ref LayoutPreference.LayoutMode, value, nameof(LayoutMode))) + LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); + } + } + + public uint GetIconSize() + { + if (LayoutMode == FolderLayoutModes.DetailsView) + return Constants.Browser.DetailsLayoutBrowser.DetailsViewSize; // ListView thumbnail + + if (LayoutMode == FolderLayoutModes.ColumnView) + return Constants.Browser.ColumnViewBrowser.ColumnViewSize; // ListView thumbnail + else if (LayoutMode == FolderLayoutModes.TilesView) + return Constants.Browser.GridViewBrowser.GridViewSizeSmall; // Small thumbnail + else if (GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeSmall) + return Constants.Browser.GridViewBrowser.GridViewSizeSmall; // Small thumbnail + else if (GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeMedium) + return Constants.Browser.GridViewBrowser.GridViewSizeMedium; // Medium thumbnail + else if (GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeLarge) + return Constants.Browser.GridViewBrowser.GridViewSizeLarge; // Large thumbnail + else + return Constants.Browser.GridViewBrowser.GridViewSizeMax; // Extra large thumbnail + } + + private bool isLayoutModeChanging; + + public bool IsLayoutModeChanging + { + get => isLayoutModeChanging; + set => SetProperty(ref isLayoutModeChanging, value); + } + + public Type GetLayoutType(string folderPath) + { + var prefsForPath = GetLayoutPreferencesForPath(folderPath); + IsLayoutModeChanging = LayoutPreference.LayoutMode != prefsForPath.LayoutMode; + LayoutPreference = prefsForPath; + + return (prefsForPath.LayoutMode) switch + { + FolderLayoutModes.DetailsView => typeof(DetailsLayoutBrowser), + FolderLayoutModes.TilesView => typeof(GridViewBrowser), + FolderLayoutModes.GridView => typeof(GridViewBrowser), + FolderLayoutModes.ColumnView => typeof(ColumnViewBrowser), + _ => typeof(DetailsLayoutBrowser) + }; + } + + public event EventHandler? LayoutModeChangeRequested; + + public event EventHandler? GridViewSizeChangeRequested; + + public ICommand ToggleLayoutModeGridViewLargeCommand { get; } + public ICommand ToggleLayoutModeColumnViewCommand { get; } + public ICommand ToggleLayoutModeGridViewMediumCommand { get; } + public ICommand ToggleLayoutModeGridViewSmallCommand { get; } + public ICommand ToggleLayoutModeGridViewCommand { get; } + public ICommand ToggleLayoutModeTilesCommand { get; } + public ICommand ToggleLayoutModeDetailsViewCommand { get; } + public ICommand ToggleLayoutModeAdaptiveCommand { get; } + + public GridViewSizeKind GridViewSizeKind + { + get + { + if (GridViewSize < Constants.Browser.GridViewBrowser.GridViewSizeMedium) + return GridViewSizeKind.Small; + else if (GridViewSize >= Constants.Browser.GridViewBrowser.GridViewSizeMedium && GridViewSize < Constants.Browser.GridViewBrowser.GridViewSizeLarge) + return GridViewSizeKind.Medium; + else + return GridViewSizeKind.Large; + } + } + + public int GridViewSize + { + get => LayoutPreference.GridViewSize; + set + { + if (value < LayoutPreference.GridViewSize) // Size down + { + if (LayoutMode == FolderLayoutModes.TilesView) // Size down from tiles to list + { + LayoutPreference.IsAdaptiveLayoutOverridden = true; + LayoutMode = FolderLayoutModes.DetailsView; + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); + } + else if (LayoutMode == FolderLayoutModes.GridView && value < Constants.Browser.GridViewBrowser.GridViewSizeSmall) // Size down from grid to tiles + { + LayoutPreference.IsAdaptiveLayoutOverridden = true; + LayoutMode = FolderLayoutModes.TilesView; + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); + } + else if (LayoutMode != FolderLayoutModes.DetailsView) // Resize grid view + { + var newValue = (value >= Constants.Browser.GridViewBrowser.GridViewSizeSmall) ? value : Constants.Browser.GridViewBrowser.GridViewSizeSmall; // Set grid size to allow immediate UI update + SetProperty(ref LayoutPreference.GridViewSize, newValue, nameof(GridViewSize)); + + if (LayoutMode != FolderLayoutModes.GridView) // Only update layout mode if it isn't already in grid view + { + LayoutPreference.IsAdaptiveLayoutOverridden = true; + LayoutMode = FolderLayoutModes.GridView; + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); + } + else + { + LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); + } + + GridViewSizeChangeRequested?.Invoke(this, EventArgs.Empty); + } + } + else if (value > LayoutPreference.GridViewSize) // Size up + { + if (LayoutMode == FolderLayoutModes.DetailsView) // Size up from list to tiles + { + LayoutPreference.IsAdaptiveLayoutOverridden = true; + LayoutMode = FolderLayoutModes.TilesView; + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); + } + else // Size up from tiles to grid + { + var newValue = (LayoutMode == FolderLayoutModes.TilesView) ? Constants.Browser.GridViewBrowser.GridViewSizeSmall : (value <= Constants.Browser.GridViewBrowser.GridViewSizeMax) ? value : Constants.Browser.GridViewBrowser.GridViewSizeMax; // Set grid size to allow immediate UI update + SetProperty(ref LayoutPreference.GridViewSize, newValue, nameof(GridViewSize)); + + if (LayoutMode != FolderLayoutModes.GridView) // Only update layout mode if it isn't already in grid view + { + LayoutPreference.IsAdaptiveLayoutOverridden = true; + LayoutMode = FolderLayoutModes.GridView; + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); + } + else + { + LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); + } + + if (value < Constants.Browser.GridViewBrowser.GridViewSizeMax) // Don't request a grid resize if it is already at the max size + GridViewSizeChangeRequested?.Invoke(this, EventArgs.Empty); + } + } + } + } + + public event EventHandler? SortOptionPreferenceUpdated; + + public event EventHandler? GroupOptionPreferenceUpdated; + + public event EventHandler? SortDirectionPreferenceUpdated; + + public event EventHandler? SortDirectoriesAlongsideFilesPreferenceUpdated; + + public SortOption DirectorySortOption + { + get => LayoutPreference.DirectorySortOption; + set + { + if (SetProperty(ref LayoutPreference.DirectorySortOption, value, nameof(DirectorySortOption))) + { + LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); + SortOptionPreferenceUpdated?.Invoke(this, DirectorySortOption); + } + } + } + + public ICommand ChangeGroupOptionCommand { get; } + + public GroupOption DirectoryGroupOption + { + get => LayoutPreference.DirectoryGroupOption; + set + { + if (SetProperty(ref LayoutPreference.DirectoryGroupOption, value, nameof(DirectoryGroupOption))) + { + LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); + GroupOptionPreferenceUpdated?.Invoke(this, DirectoryGroupOption); + } + } + } + + public SortDirection DirectorySortDirection + { + get => LayoutPreference.DirectorySortDirection; + set + { + if (SetProperty(ref LayoutPreference.DirectorySortDirection, value, nameof(DirectorySortDirection))) + { + LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); + SortDirectionPreferenceUpdated?.Invoke(this, DirectorySortDirection); + } + } + } + + public bool SortDirectoriesAlongsideFiles + { + get + { + return LayoutPreference.SortDirectoriesAlongsideFiles; + } + set + { + if (SetProperty(ref LayoutPreference.SortDirectoriesAlongsideFiles, value, nameof(SortDirectoriesAlongsideFiles))) + { + LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); + SortDirectoriesAlongsideFilesPreferenceUpdated?.Invoke(this, SortDirectoriesAlongsideFiles); + } + } + } + + public ColumnsViewModel ColumnsViewModel + { + get => LayoutPreference.ColumnsViewModel; + set + { + SetProperty(ref LayoutPreference.ColumnsViewModel, value, nameof(ColumnsViewModel)); + LayoutPreferencesUpdateRequired?.Invoke(this, new LayoutPreferenceEventArgs(LayoutPreference)); + } + } + + private static LayoutPreferences GetLayoutPreferencesForPath(string folderPath) + { + IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); + if (!userSettingsService.PreferencesSettingsService.ForceLayoutPreferencesOnAllDirectories) + { + folderPath = folderPath.TrimPath(); + var folderFRN = NativeFileOperationsHelper.GetFolderFRN(folderPath); + return ReadLayoutPreferencesFromDb(folderPath, folderFRN) + ?? ReadLayoutPreferencesFromAds(folderPath, folderFRN) + ?? GetDefaultLayoutPreferences(folderPath); + } + + return LayoutPreferences.DefaultLayoutPreferences; + } + + public static void SetLayoutPreferencesForPath(string folderPath, LayoutPreferences prefs) + { + IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); + + if (!userSettingsService.PreferencesSettingsService.ForceLayoutPreferencesOnAllDirectories) + { + var folderFRN = NativeFileOperationsHelper.GetFolderFRN(folderPath); + WriteLayoutPreferencesToDb(folderPath.TrimPath(), folderFRN, prefs); + } + else + { + userSettingsService.PreferencesSettingsService.DefaultLayoutMode = prefs.LayoutMode; + userSettingsService.LayoutSettingsService.DefaultGridViewSize = prefs.GridViewSize; + // Do not save OriginalPath as global sort option (only works in recycle bin) + if (prefs.DirectorySortOption != SortOption.OriginalFolder && + prefs.DirectorySortOption != SortOption.DateDeleted && + prefs.DirectorySortOption != SortOption.SyncStatus) + { + userSettingsService.LayoutSettingsService.DefaultDirectorySortOption = prefs.DirectorySortOption; + } + if (prefs.DirectoryGroupOption != GroupOption.OriginalFolder && + prefs.DirectoryGroupOption != GroupOption.DateDeleted && + prefs.DirectoryGroupOption != GroupOption.FolderPath && + prefs.DirectoryGroupOption != GroupOption.SyncStatus) + { + userSettingsService.LayoutSettingsService.DefaultDirectoryGroupOption = prefs.DirectoryGroupOption; + } + userSettingsService.LayoutSettingsService.DefaultDirectorySortDirection = prefs.DirectorySortDirection; + userSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles = prefs.SortDirectoriesAlongsideFiles; + + userSettingsService.PreferencesSettingsService.ShowDateColumn = !prefs.ColumnsViewModel.DateModifiedColumn.UserCollapsed; + userSettingsService.PreferencesSettingsService.ShowDateCreatedColumn = !prefs.ColumnsViewModel.DateCreatedColumn.UserCollapsed; + userSettingsService.PreferencesSettingsService.ShowTypeColumn = !prefs.ColumnsViewModel.ItemTypeColumn.UserCollapsed; + userSettingsService.PreferencesSettingsService.ShowSizeColumn = !prefs.ColumnsViewModel.SizeColumn.UserCollapsed; + userSettingsService.PreferencesSettingsService.ShowFileTagColumn = !prefs.ColumnsViewModel.TagColumn.UserCollapsed; + + userSettingsService.PreferencesSettingsService.NameColumnWidth = prefs.ColumnsViewModel.NameColumn.UserLengthPixels; userSettingsService.PreferencesSettingsService.DateModifiedColumnWidth = prefs.ColumnsViewModel.DateModifiedColumn.UserLengthPixels; userSettingsService.PreferencesSettingsService.DateCreatedColumnWidth = prefs.ColumnsViewModel.DateCreatedColumn.UserLengthPixels; userSettingsService.PreferencesSettingsService.TypeColumnWidth = prefs.ColumnsViewModel.ItemTypeColumn.UserLengthPixels; @@ -342,176 +342,176 @@ public static void SetLayoutPreferencesForPath(string folderPath, LayoutPreferen } } - private static LayoutPreferences ReadLayoutPreferencesFromAds(string folderPath, ulong? frn) - { - var str = NativeFileOperationsHelper.ReadStringFromFile($"{folderPath}:files_layoutmode"); - var adsPrefs = SafetyExtensions.IgnoreExceptions(() => - string.IsNullOrEmpty(str) ? null : JsonSerializer.Deserialize(str)); - WriteLayoutPreferencesToDb(folderPath, frn, adsPrefs); // Port settings to DB, delete ADS - NativeFileOperationsHelper.DeleteFileFromApp($"{folderPath}:files_layoutmode"); - return adsPrefs; - } - - private static LayoutPreferences? ReadLayoutPreferencesFromDb(string folderPath, ulong? frn) - { - if (string.IsNullOrEmpty(folderPath)) - return null; - - return DbInstance.GetPreferences(folderPath, frn); - } - - private static LayoutPreferences GetDefaultLayoutPreferences(string folderPath) - { - if (string.IsNullOrEmpty(folderPath)) - return LayoutPreferences.DefaultLayoutPreferences; - - if (folderPath == CommonPaths.DownloadsPath) - // Default for downloads folder is to group by date created - return new LayoutPreferences() { DirectoryGroupOption = GroupOption.DateCreated }; - else if (LibraryHelper.IsLibraryPath(folderPath)) - // Default for libraries is to group by folder path - return new LayoutPreferences() { DirectoryGroupOption = GroupOption.FolderPath }; - else - return LayoutPreferences.DefaultLayoutPreferences; // Either global setting or smart guess - } - - private static void WriteLayoutPreferencesToDb(string folderPath, ulong? frn, LayoutPreferences prefs) - { - if (string.IsNullOrEmpty(folderPath)) - return; + private static LayoutPreferences ReadLayoutPreferencesFromAds(string folderPath, ulong? frn) + { + var str = NativeFileOperationsHelper.ReadStringFromFile($"{folderPath}:files_layoutmode"); + var adsPrefs = SafetyExtensions.IgnoreExceptions(() => + string.IsNullOrEmpty(str) ? null : JsonSerializer.Deserialize(str)); + WriteLayoutPreferencesToDb(folderPath, frn, adsPrefs); // Port settings to DB, delete ADS + NativeFileOperationsHelper.DeleteFileFromApp($"{folderPath}:files_layoutmode"); + return adsPrefs; + } + + private static LayoutPreferences? ReadLayoutPreferencesFromDb(string folderPath, ulong? frn) + { + if (string.IsNullOrEmpty(folderPath)) + return null; + + return DbInstance.GetPreferences(folderPath, frn); + } + + private static LayoutPreferences GetDefaultLayoutPreferences(string folderPath) + { + if (string.IsNullOrEmpty(folderPath)) + return LayoutPreferences.DefaultLayoutPreferences; + + if (folderPath == CommonPaths.DownloadsPath) + // Default for downloads folder is to group by date created + return new LayoutPreferences() { DirectoryGroupOption = GroupOption.DateCreated }; + else if (LibraryHelper.IsLibraryPath(folderPath)) + // Default for libraries is to group by folder path + return new LayoutPreferences() { DirectoryGroupOption = GroupOption.FolderPath }; + else + return LayoutPreferences.DefaultLayoutPreferences; // Either global setting or smart guess + } + + private static void WriteLayoutPreferencesToDb(string folderPath, ulong? frn, LayoutPreferences prefs) + { + if (string.IsNullOrEmpty(folderPath)) + return; + + if (DbInstance.GetPreferences(folderPath, frn) is null) + { + if (LayoutPreferences.DefaultLayoutPreferences.Equals(prefs)) + return; // Do not create setting if it's default + } + DbInstance.SetPreferences(folderPath, frn, prefs); + } + + private LayoutPreferences layoutPreference; + + public LayoutPreferences LayoutPreference + { + get => layoutPreference; + private set + { + if (SetProperty(ref layoutPreference, value)) + { + OnPropertyChanged(nameof(LayoutMode)); + OnPropertyChanged(nameof(GridViewSize)); + OnPropertyChanged(nameof(GridViewSizeKind)); + OnPropertyChanged(nameof(IsAdaptiveLayoutEnabled)); + OnPropertyChanged(nameof(DirectoryGroupOption)); + OnPropertyChanged(nameof(DirectorySortOption)); + OnPropertyChanged(nameof(DirectorySortDirection)); + OnPropertyChanged(nameof(SortDirectoriesAlongsideFiles)); + OnPropertyChanged(nameof(ColumnsViewModel)); + } + } + } + + public void ToggleLayoutModeGridViewLarge(bool manuallySet) + { + IsAdaptiveLayoutEnabled &= !manuallySet; + + LayoutMode = FolderLayoutModes.GridView; // Grid View + + GridViewSize = Constants.Browser.GridViewBrowser.GridViewSizeLarge; // Size + + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.GridView, GridViewSize)); + } + + public void ToggleLayoutModeColumnView(bool manuallySet) + { + IsAdaptiveLayoutEnabled &= !manuallySet; - if (DbInstance.GetPreferences(folderPath, frn) is null) - { - if (LayoutPreferences.DefaultLayoutPreferences.Equals(prefs)) - return; // Do not create setting if it's default - } - DbInstance.SetPreferences(folderPath, frn, prefs); - } + LayoutMode = FolderLayoutModes.ColumnView; // Column View - private LayoutPreferences layoutPreference; + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.ColumnView, GridViewSize)); + } + + public void ToggleLayoutModeGridViewMedium(bool manuallySet) + { + IsAdaptiveLayoutEnabled &= !manuallySet; - public LayoutPreferences LayoutPreference - { - get => layoutPreference; - private set - { - if (SetProperty(ref layoutPreference, value)) - { - OnPropertyChanged(nameof(LayoutMode)); - OnPropertyChanged(nameof(GridViewSize)); - OnPropertyChanged(nameof(GridViewSizeKind)); - OnPropertyChanged(nameof(IsAdaptiveLayoutEnabled)); - OnPropertyChanged(nameof(DirectoryGroupOption)); - OnPropertyChanged(nameof(DirectorySortOption)); - OnPropertyChanged(nameof(DirectorySortDirection)); - OnPropertyChanged(nameof(SortDirectoriesAlongsideFiles)); - OnPropertyChanged(nameof(ColumnsViewModel)); - } - } - } - - public void ToggleLayoutModeGridViewLarge(bool manuallySet) - { - IsAdaptiveLayoutEnabled &= !manuallySet; - - LayoutMode = FolderLayoutModes.GridView; // Grid View - - GridViewSize = Constants.Browser.GridViewBrowser.GridViewSizeLarge; // Size - - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.GridView, GridViewSize)); - } - - public void ToggleLayoutModeColumnView(bool manuallySet) - { - IsAdaptiveLayoutEnabled &= !manuallySet; - - LayoutMode = FolderLayoutModes.ColumnView; // Column View - - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.ColumnView, GridViewSize)); - } - - public void ToggleLayoutModeGridViewMedium(bool manuallySet) - { - IsAdaptiveLayoutEnabled &= !manuallySet; - - LayoutMode = FolderLayoutModes.GridView; // Grid View - - GridViewSize = Constants.Browser.GridViewBrowser.GridViewSizeMedium; // Size - - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.GridView, GridViewSize)); - } - - public void ToggleLayoutModeGridViewSmall(bool manuallySet) - { - IsAdaptiveLayoutEnabled &= !manuallySet; - - LayoutMode = FolderLayoutModes.GridView; // Grid View - - GridViewSize = Constants.Browser.GridViewBrowser.GridViewSizeSmall; // Size - - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.GridView, GridViewSize)); - } - - public void ToggleLayoutModeGridView(int size) - { - LayoutMode = FolderLayoutModes.GridView; // Grid View - - GridViewSize = size; // Size - - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); - } - - public void ToggleLayoutModeTiles(bool manuallySet) - { - IsAdaptiveLayoutEnabled &= !manuallySet; - - LayoutMode = FolderLayoutModes.TilesView; // Tiles View - - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.TilesView, GridViewSize)); - } - - public void ToggleLayoutModeDetailsView(bool manuallySet) - { - IsAdaptiveLayoutEnabled &= !manuallySet; - - LayoutMode = FolderLayoutModes.DetailsView; // Details View - - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.DetailsView, GridViewSize)); - } + LayoutMode = FolderLayoutModes.GridView; // Grid View - public void ToggleLayoutModeAdaptive() - { - IsAdaptiveLayoutEnabled = true; // Adaptive + GridViewSize = Constants.Browser.GridViewBrowser.GridViewSizeMedium; // Size + + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.GridView, GridViewSize)); + } - LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.Adaptive, GridViewSize)); - } + public void ToggleLayoutModeGridViewSmall(bool manuallySet) + { + IsAdaptiveLayoutEnabled &= !manuallySet; - private void ChangeGroupOption(GroupOption option) => DirectoryGroupOption = option; + LayoutMode = FolderLayoutModes.GridView; // Grid View + + GridViewSize = Constants.Browser.GridViewBrowser.GridViewSizeSmall; // Size + + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.GridView, GridViewSize)); + } - public void OnDefaultPreferencesChanged(string folderPath, string settingsName) - { - var prefs = GetLayoutPreferencesForPath(folderPath); - switch (settingsName) - { - case nameof(UserSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles): - SortDirectoriesAlongsideFiles = prefs.SortDirectoriesAlongsideFiles; - break; - case nameof(UserSettingsService.PreferencesSettingsService.ForceLayoutPreferencesOnAllDirectories): - LayoutPreference = prefs; - // TODO: update layout - break; - } - } + public void ToggleLayoutModeGridView(int size) + { + LayoutMode = FolderLayoutModes.GridView; // Grid View - public void SetDefaultLayoutPreferences(ColumnsViewModel columns) - { - IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); - - userSettingsService.PreferencesSettingsService.ShowDateColumn = !columns.DateModifiedColumn.UserCollapsed; - userSettingsService.PreferencesSettingsService.ShowDateCreatedColumn = !columns.DateCreatedColumn.UserCollapsed; - userSettingsService.PreferencesSettingsService.ShowTypeColumn = !columns.ItemTypeColumn.UserCollapsed; - userSettingsService.PreferencesSettingsService.ShowSizeColumn = !columns.SizeColumn.UserCollapsed; - userSettingsService.PreferencesSettingsService.ShowFileTagColumn = !columns.TagColumn.UserCollapsed; + GridViewSize = size; // Size + + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(LayoutMode, GridViewSize)); + } + + public void ToggleLayoutModeTiles(bool manuallySet) + { + IsAdaptiveLayoutEnabled &= !manuallySet; + + LayoutMode = FolderLayoutModes.TilesView; // Tiles View + + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.TilesView, GridViewSize)); + } + + public void ToggleLayoutModeDetailsView(bool manuallySet) + { + IsAdaptiveLayoutEnabled &= !manuallySet; + + LayoutMode = FolderLayoutModes.DetailsView; // Details View + + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.DetailsView, GridViewSize)); + } + + public void ToggleLayoutModeAdaptive() + { + IsAdaptiveLayoutEnabled = true; // Adaptive + + LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.Adaptive, GridViewSize)); + } + + private void ChangeGroupOption(GroupOption option) => DirectoryGroupOption = option; + + public void OnDefaultPreferencesChanged(string folderPath, string settingsName) + { + var prefs = GetLayoutPreferencesForPath(folderPath); + switch (settingsName) + { + case nameof(UserSettingsService.LayoutSettingsService.DefaultSortDirectoriesAlongsideFiles): + SortDirectoriesAlongsideFiles = prefs.SortDirectoriesAlongsideFiles; + break; + case nameof(UserSettingsService.PreferencesSettingsService.ForceLayoutPreferencesOnAllDirectories): + LayoutPreference = prefs; + // TODO: update layout + break; + } + } + + public void SetDefaultLayoutPreferences(ColumnsViewModel columns) + { + IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); + + userSettingsService.PreferencesSettingsService.ShowDateColumn = !columns.DateModifiedColumn.UserCollapsed; + userSettingsService.PreferencesSettingsService.ShowDateCreatedColumn = !columns.DateCreatedColumn.UserCollapsed; + userSettingsService.PreferencesSettingsService.ShowTypeColumn = !columns.ItemTypeColumn.UserCollapsed; + userSettingsService.PreferencesSettingsService.ShowSizeColumn = !columns.SizeColumn.UserCollapsed; + userSettingsService.PreferencesSettingsService.ShowFileTagColumn = !columns.TagColumn.UserCollapsed; userSettingsService.PreferencesSettingsService.NameColumnWidth = columns.NameColumn.UserLengthPixels; userSettingsService.PreferencesSettingsService.DateModifiedColumnWidth = columns.DateModifiedColumn.UserLengthPixels; @@ -521,15 +521,15 @@ public void SetDefaultLayoutPreferences(ColumnsViewModel columns) userSettingsService.PreferencesSettingsService.TagColumnWidth = columns.TagColumn.UserLengthPixels; } - public static void ResetColumnsWidth() - { + public static void ResetColumnsWidth() + { IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); userSettingsService.PreferencesSettingsService.NameColumnWidth = 200d; userSettingsService.PreferencesSettingsService.DateModifiedColumnWidth = 200d; userSettingsService.PreferencesSettingsService.DateCreatedColumnWidth = 200d; userSettingsService.PreferencesSettingsService.TypeColumnWidth = 200d; userSettingsService.PreferencesSettingsService.SizeColumnWidth = 200d; - userSettingsService.PreferencesSettingsService.TagColumnWidth = 200d; + userSettingsService.PreferencesSettingsService.TagColumnWidth = 200d; } } } diff --git a/src/Files.Backend/Services/Settings/IPreferencesSettingsService.cs b/src/Files.Backend/Services/Settings/IPreferencesSettingsService.cs index 193807a3e920..eaf4fb1950ba 100644 --- a/src/Files.Backend/Services/Settings/IPreferencesSettingsService.cs +++ b/src/Files.Backend/Services/Settings/IPreferencesSettingsService.cs @@ -150,5 +150,35 @@ public interface IPreferencesSettingsService : IBaseSettingsService, INotifyProp /// Gets or sets a value indicating the default layout mode. /// FolderLayoutModes DefaultLayoutMode { get; set; } + + /// + /// Gets or sets a value indicating tags column's default width + /// + double TagColumnWidth { get; set; } + + /// + /// Gets or sets a value indicating name column's default width + /// + double NameColumnWidth { get; set; } + + /// + /// Gets or sets a value indicating date modified column's default width + /// + double DateModifiedColumnWidth { get; set; } + + /// + /// Gets or sets a value indicating item type column's default width + /// + double TypeColumnWidth { get; set; } + + /// + /// Gets or sets a value indicating date created column's default width + /// + double DateCreatedColumnWidth { get; set; } + + /// + /// Gets or sets a value indicating size column's default width + /// + double SizeColumnWidth { get; set; } } } From fffecb50a74b7cb26e2373b382ff1315aaff6956 Mon Sep 17 00:00:00 2001 From: Yair Aichenbaum <39923744+yaichenbaum@users.noreply.github.com> Date: Thu, 6 Oct 2022 11:20:56 -0400 Subject: [PATCH 5/7] Update LayoutPreferences.cs --- .../LayoutPreferences/LayoutPreferences.cs | 122 +++++++++--------- 1 file changed, 62 insertions(+), 60 deletions(-) diff --git a/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs b/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs index 60fb6adefdd9..e7c89438eb3c 100644 --- a/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs +++ b/src/Files.App/Helpers/LayoutPreferences/LayoutPreferences.cs @@ -5,39 +5,39 @@ namespace Files.App.Helpers.LayoutPreferences { - public class LayoutPreferences - { - private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); + public class LayoutPreferences + { + private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); - public SortOption DirectorySortOption; - public SortDirection DirectorySortDirection; - public bool SortDirectoriesAlongsideFiles; - public GroupOption DirectoryGroupOption; - public FolderLayoutModes LayoutMode; - public int GridViewSize; - public bool IsAdaptiveLayoutOverridden; + public SortOption DirectorySortOption; + public SortDirection DirectorySortDirection; + public bool SortDirectoriesAlongsideFiles; + public GroupOption DirectoryGroupOption; + public FolderLayoutModes LayoutMode; + public int GridViewSize; + public bool IsAdaptiveLayoutOverridden; - public ColumnsViewModel ColumnsViewModel; + public ColumnsViewModel ColumnsViewModel; - [LiteDB.BsonIgnore] - public static LayoutPreferences DefaultLayoutPreferences => new LayoutPreferences(); + [LiteDB.BsonIgnore] + public static LayoutPreferences DefaultLayoutPreferences => new LayoutPreferences(); - 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 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; - 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; + 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; this.ColumnsViewModel.NameColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.NameColumnWidth; this.ColumnsViewModel.DateModifiedColumn.UserLengthPixels = UserSettingsService.PreferencesSettingsService.DateModifiedColumnWidth; @@ -48,37 +48,39 @@ public LayoutPreferences() } 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 == null) + return false; - 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; - } - } + 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); + } + + 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; + } + } } From c9c31af54dd111fc48a1633f313e184b4e5d69b4 Mon Sep 17 00:00:00 2001 From: Filippo Ferrario <102259289+ferrariofilippo@users.noreply.github.com> Date: Thu, 6 Oct 2022 18:20:57 +0200 Subject: [PATCH 6/7] Removed code not needed --- .../Settings/PreferencesSettingsService.cs | 36 ++++--------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/Files.App/ServicesImplementation/Settings/PreferencesSettingsService.cs b/src/Files.App/ServicesImplementation/Settings/PreferencesSettingsService.cs index b5645ce94540..2fb0c351042b 100644 --- a/src/Files.App/ServicesImplementation/Settings/PreferencesSettingsService.cs +++ b/src/Files.App/ServicesImplementation/Settings/PreferencesSettingsService.cs @@ -192,61 +192,37 @@ public FolderLayoutModes DefaultLayoutMode public double TagColumnWidth { get => Get(200d); - set - { - if (value != 0) - Set(value); - } + set => Set(value); } public double NameColumnWidth { get => Get(200d); - set - { - if (value != 0) - Set(value); - } + set => Set(value); } public double DateModifiedColumnWidth { get => Get(200d); - set - { - if (value != 0) - Set(value); - } + set => Set(value); } public double TypeColumnWidth { get => Get(200d); - set - { - if (value != 0) - Set(value); - } + set => Set(value); } public double DateCreatedColumnWidth { get => Get(200d); - set - { - if (value != 0) - Set(value); - } + set => Set(value); } public double SizeColumnWidth { get => Get(200d); - set - { - if (value != 0) - Set(value); - } + set => Set(value); } protected override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e) From ab43af821b0d4365c7e48a95571c65df9948e8fc Mon Sep 17 00:00:00 2001 From: Filippo Ferrario <102259289+ferrariofilippo@users.noreply.github.com> Date: Thu, 6 Oct 2022 22:05:24 +0200 Subject: [PATCH 7/7] Requested Changes --- src/Files.App/ViewModels/FolderSettingsViewModel.cs | 11 ----------- .../SettingsViewModels/PreferencesViewModel.cs | 1 - 2 files changed, 12 deletions(-) diff --git a/src/Files.App/ViewModels/FolderSettingsViewModel.cs b/src/Files.App/ViewModels/FolderSettingsViewModel.cs index 8d19f20a1857..b8d00dd94db9 100644 --- a/src/Files.App/ViewModels/FolderSettingsViewModel.cs +++ b/src/Files.App/ViewModels/FolderSettingsViewModel.cs @@ -520,16 +520,5 @@ public void SetDefaultLayoutPreferences(ColumnsViewModel columns) userSettingsService.PreferencesSettingsService.SizeColumnWidth = columns.SizeColumn.UserLengthPixels; userSettingsService.PreferencesSettingsService.TagColumnWidth = columns.TagColumn.UserLengthPixels; } - - public static void ResetColumnsWidth() - { - IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); - userSettingsService.PreferencesSettingsService.NameColumnWidth = 200d; - userSettingsService.PreferencesSettingsService.DateModifiedColumnWidth = 200d; - userSettingsService.PreferencesSettingsService.DateCreatedColumnWidth = 200d; - userSettingsService.PreferencesSettingsService.TypeColumnWidth = 200d; - userSettingsService.PreferencesSettingsService.SizeColumnWidth = 200d; - userSettingsService.PreferencesSettingsService.TagColumnWidth = 200d; - } } } diff --git a/src/Files.App/ViewModels/SettingsViewModels/PreferencesViewModel.cs b/src/Files.App/ViewModels/SettingsViewModels/PreferencesViewModel.cs index 4638914cd0eb..c3ea0bf22751 100644 --- a/src/Files.App/ViewModels/SettingsViewModels/PreferencesViewModel.cs +++ b/src/Files.App/ViewModels/SettingsViewModels/PreferencesViewModel.cs @@ -541,7 +541,6 @@ public async Task ReadState() public void ResetLayoutPreferences() { FolderSettingsViewModel.DbInstance.ResetAll(); - FolderSettingsViewModel.ResetColumnsWidth(); IsResetLayoutPreferencesTipOpen = false; IsLayoutResetCheckmarkVisible = true; }