Skip to content

Use database to store layout preferences #9437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 67 commits into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
180dded
Prepare
gave92 May 9, 2022
8fc310c
Make Adaptive look like another layout
gave92 May 9, 2022
534de9f
Revert "Prepare"
gave92 May 9, 2022
ef6435e
Fix revert
gave92 May 9, 2022
df31461
Switch to Binding to use StaticResource on ConverterParameter
gave92 May 9, 2022
a9a65f3
Revert changes & disable adaptive when glocal options enabled
gave92 May 10, 2022
5d6aa8e
Fix layout button not updating
gave92 May 10, 2022
e762371
Go back to x:Bind + App.xaml
gave92 May 10, 2022
ed0f1e8
Simplify toobar update
gave92 May 10, 2022
ba0a6e2
Update FolderSettingsViewModel.cs
gave92 May 10, 2022
1daf18f
Update Files.Uwp.csproj
gave92 May 10, 2022
78a168a
Fix build
gave92 May 10, 2022
6a41263
Merge branch 'main' of https://github.com/files-community/Files into …
gave92 May 14, 2022
56c842e
Implement Equals method for ColumnsViewModel
gave92 May 14, 2022
697e4f2
Remove unused pagetype param from UniversalStorageEnumerator
gave92 May 14, 2022
84d3477
Simplify GetLayoutType
gave92 May 14, 2022
da17bb2
Make GetLayoutType async
gave92 May 14, 2022
0175097
[WIP] Read/store prefs in db
gave92 May 14, 2022
171751a
Change jsonignore to bsonignore, refactor db method into LayoutPrefsDb
gave92 May 14, 2022
d6b6e48
Separate LayoutPreferences and LayoutPrefsDb classes
gave92 May 14, 2022
3ab75ae
Add layout prefs db to settings import/export
gave92 May 14, 2022
44c7f50
Port existing preferences to Db
gave92 May 14, 2022
b976f93
Add missing files to project
gave92 May 15, 2022
63c9b8e
Do not pass ItemViewModel to AdaptiveLayoutHelpers
gave92 May 15, 2022
1fc3ae6
Add methods to apply to all/reset all prefs
gave92 May 15, 2022
b151b59
[WIP]
gave92 May 15, 2022
247be77
Merge branch 'main' of https://github.com/files-community/Files into …
gave92 May 15, 2022
8db490b
Move default SortDirectoriesAlongsideFiles to LayoutSettingsService
gave92 May 15, 2022
535eb85
Merge branch 'imp_listalong' into default_layout
gave92 May 15, 2022
733ecbc
Merge branch 'default_layout' into default_layout2
gave92 May 15, 2022
61dae4e
Fix build
gave92 May 15, 2022
c733496
Remove extra prop
gave92 May 15, 2022
84678a2
Revert extra change
gave92 May 15, 2022
a831423
Merge branch 'main' into default_layout
gave92 May 15, 2022
763dff1
Merge branch 'default_layout' into default_layout2
gave92 May 15, 2022
04f200b
Merge branch 'main' of https://github.com/files-community/Files into …
gave92 May 21, 2022
5278d7a
Merge branch 'main' of https://github.com/files-community/Files into …
gave92 May 21, 2022
a337234
Merge branch 'default_layout' into default_layout2
gave92 May 21, 2022
e786fff
Get folder frn using GetFileInformationByHandleEx (sync)
gave92 May 21, 2022
c69a0cd
Merge branch 'main' into pr/9132
yaira2 Jun 9, 2022
ac16338
Merge branch 'main' of https://github.com/files-community/Files into …
gave92 Jun 9, 2022
aae94d5
Merge branch 'default_layout' of https://github.com/gave92/files-uwp …
gave92 Jun 9, 2022
29e107e
Merge branch 'main' of https://github.com/files-community/Files into …
gave92 Jun 9, 2022
294bf9e
Merge branch 'default_layout' into default_layout2
gave92 Jun 9, 2022
5f0f9c9
Solution1: bad
gave92 Jun 9, 2022
0eeabe2
Solution2
gave92 Jun 9, 2022
6fee1f6
Solution3: clean up
gave92 Jun 9, 2022
7bfa888
Merge branch 'default_layout' into default_layout2
gave92 Jun 9, 2022
4face43
Fix merge conflicts
gave92 Jun 9, 2022
f58d561
Merge branch 'main' of https://github.com/files-community/Files into …
gave92 Jun 19, 2022
86fad01
Simplify LargeInteger to long
gave92 Jun 19, 2022
3ada23c
Merge branch 'main' of https://github.com/files-community/Files into …
gave92 Jun 22, 2022
2a8ce01
Fix private decl
gave92 Jun 22, 2022
7e3e920
Fix indentiation
gave92 Jun 25, 2022
92188ac
Enabled nullable for LayoutPrefsDb
gave92 Jun 25, 2022
f271ac8
Add EnsureIndex on Frn and FilePath
gave92 Jun 25, 2022
c91b75c
Changed DB name so it can be used for all future DB-based settings
gave92 Jun 25, 2022
adfa2c8
Override for GetHasCode
gave92 Jun 25, 2022
3bc106d
No need for shared mode, removed unused imports
gave92 Jun 25, 2022
594095c
LiteDB classes must have parameterless constructor
gave92 Jun 25, 2022
639e393
Added missing nullable decl
gave92 Jun 25, 2022
2cbbdea
Added missing nullable decl
gave92 Jun 25, 2022
ddf25de
Init non-nullable fields to not null
gave92 Jun 26, 2022
79a2e78
Merge branch 'default_layout2' of https://github.com/gave92/files-uwp…
gave92 Jun 26, 2022
27fa17b
Moved ensureIndex after insert
gave92 Jun 26, 2022
599679d
Merge branch 'main' of https://github.com/files-community/Files into …
gave92 Jun 26, 2022
7b6d9e8
Making get static to match set
gave92 Jun 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Files.Shared/FileTagsDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public void SetTags(string filePath, ulong? frn, string[]? tags)
if (tags != null && tags.Any())
{
// Insert new tagged file (Id will be auto-incremented)
var newTag = new TaggedFile
var newTag = new TaggedFile()
{
FilePath = filePath,
Frn = frn,
Tags = tags
};
col.Insert(newTag);
col.EnsureIndex(x => x.Frn);
col.EnsureIndex(x => x.FilePath);
}
}
else
Expand All @@ -60,6 +62,7 @@ public void SetTags(string filePath, ulong? frn, string[]? tags)
{
// Get a collection (or create, if doesn't exist)
var col = db.GetCollection<TaggedFile>(TaggedFiles);

if (filePath != null)
{
var tmp = col.FindOne(x => x.FilePath == filePath);
Expand Down Expand Up @@ -189,8 +192,8 @@ public class TaggedFile
{
[BsonId] public int Id { get; set; }
public ulong? Frn { get; set; }
public string FilePath { get; set; } = null!;
public string[] Tags { get; set; } = null!;
public string FilePath { get; set; } = string.Empty;
public string[] Tags { get; set; } = Array.Empty<string>();
}
}
}
3 changes: 1 addition & 2 deletions src/Files.Uwp/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,10 @@ protected virtual void BaseFolderSettings_LayoutModeChangeRequested(object sende
{
if (ParentShellPageInstance.SlimContentPage != null)
{
var layoutType = FolderSettings.GetLayoutType(ParentShellPageInstance.FilesystemViewModel.WorkingDirectory, false);
var layoutType = FolderSettings.GetLayoutType(ParentShellPageInstance.FilesystemViewModel.WorkingDirectory);

if (layoutType != ParentShellPageInstance.CurrentPageType)
{
FolderSettings.IsLayoutModeChanging = true;
ParentShellPageInstance.NavigateWithArguments(layoutType, new NavigationArguments()
{
NavPathParam = navigationArguments.NavPathParam,
Expand Down
2 changes: 1 addition & 1 deletion src/Files.Uwp/EventArguments/LayoutPreferenceEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using static Files.Uwp.ViewModels.FolderSettingsViewModel;
using Files.Uwp.Helpers.LayoutPreferences;

namespace Files.Uwp.EventArguments
{
Expand Down
4 changes: 3 additions & 1 deletion src/Files.Uwp/Files.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@
<Compile Include="Helpers\StorageSenseHelper.cs" />
<Compile Include="Helpers\WindowDecorationsHelper.cs" />
<Compile Include="Helpers\UniversalLogWriter.cs" />
<Compile Include="Helpers\LayoutPreferences\LayoutPreferences.cs" />
<Compile Include="Helpers\LayoutPreferences\LayoutPrefsDb.cs" />
<Compile Include="Filesystem\FolderHelpers.cs" />
<Compile Include="Filesystem\LibraryLocationItem.cs" />
<Compile Include="Filesystem\LibraryManager.cs" />
Expand Down Expand Up @@ -1693,4 +1695,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public static class UniversalStorageEnumerator
public static async Task<List<ListedItem>> ListEntries(
BaseStorageFolder rootFolder,
StorageFolderWithPath currentStorageFolder,
Type sourcePageType,
CancellationToken cancellationToken,
int countLimit,
Func<List<ListedItem>, Task> intermediateAction,
Expand Down
56 changes: 16 additions & 40 deletions src/Files.Uwp/Helpers/AdaptiveLayoutHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
using System;
using System.Linq;
using Windows.Storage;
using System.Collections.Generic;
using Files.Uwp.Filesystem;

namespace Files.Uwp.Helpers
{
public static class AdaptiveLayoutHelpers
{
public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, ItemViewModel filesystemViewModel)
public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, string path, IList<ListedItem> filesAndFolders)
{
IUserSettingsService userSettingsService = Ioc.Default.GetService<IUserSettingsService>();

Expand All @@ -24,8 +26,6 @@ public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, Ite

bool desktopIniFound = false;

string path = filesystemViewModel?.WorkingDirectory;

if (string.IsNullOrWhiteSpace(path))
{
return false;
Expand All @@ -46,39 +46,15 @@ public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, Ite
var folderTypeKey = viewModeSection.Keys.FirstOrDefault(s => "FolderType".Equals(s.KeyName, StringComparison.OrdinalIgnoreCase));
if (folderTypeKey != null)
{
switch (folderTypeKey.Value)
var setLayout = (folderTypeKey.Value) switch
{
case "Documents":
{
layoutDetails();
break;
}

case "Pictures":
{
layoutGridView();
break;
}

case "Music":
{
layoutDetails();
break;
}

case "Videos":
{
layoutGridView();
break;
}

default:
{
layoutDetails();
break;
}
}

"Documents" => layoutDetails,
"Pictures" => layoutGridView,
"Music" => layoutDetails,
"Videos" => layoutGridView,
_ => layoutDetails
};
setLayout();
desktopIniFound = true;
}
}
Expand All @@ -89,12 +65,12 @@ public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, Ite
{
return true;
}
if (filesystemViewModel.FilesAndFolders.Count == 0)
if (filesAndFolders.Count == 0)
{
return false;
}

int allItemsCount = filesystemViewModel.FilesAndFolders.Count;
int allItemsCount = filesAndFolders.Count;

int mediaCount;
int imagesCount;
Expand All @@ -106,15 +82,15 @@ public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, Ite
float foldersPercentage;
float miscFilesPercentage;

mediaCount = filesystemViewModel.FilesAndFolders.Where((item) =>
mediaCount = filesAndFolders.Where((item) =>
{
return !string.IsNullOrEmpty(item.FileExtension) && MediaPreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant());
}).Count();
imagesCount = filesystemViewModel.FilesAndFolders.Where((item) =>
imagesCount = filesAndFolders.Where((item) =>
{
return !string.IsNullOrEmpty(item.FileExtension) && ImagePreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant());
}).Count();
foldersCount = filesystemViewModel.FilesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count();
foldersCount = filesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count();
miscFilesCount = allItemsCount - (mediaCount + imagesCount + foldersCount);

mediaPercentage = (float)((float)mediaCount / (float)allItemsCount) * 100.0f;
Expand Down
79 changes: 79 additions & 0 deletions src/Files.Uwp/Helpers/LayoutPreferences/LayoutPreferences.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.Backend.Services.Settings;
using Files.Shared.Enums;
using Files.Uwp.ViewModels;

namespace Files.Uwp.Helpers.LayoutPreferences
{
public class LayoutPreferences
{
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetService<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 LayoutPreferences()
{
this.LayoutMode = UserSettingsService.LayoutSettingsService.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.LayoutSettingsService.ShowDateCreatedColumn;
this.ColumnsViewModel.DateModifiedColumn.UserCollapsed = !UserSettingsService.LayoutSettingsService.ShowDateColumn;
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)
{
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.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) ^ DirectorySortOption.GetHashCode();
hashCode = (hashCode * 397) ^ DirectorySortDirection.GetHashCode();
hashCode = (hashCode * 397) ^ SortDirectoriesAlongsideFiles.GetHashCode();
hashCode = (hashCode * 397) ^ IsAdaptiveLayoutOverridden.GetHashCode();
hashCode = (hashCode * 397) ^ ColumnsViewModel.GetHashCode();
return hashCode;
}
}
}
Loading