From 13315304a532a26e806769c81c248698ae4c56be Mon Sep 17 00:00:00 2001 From: "ivan.haidov" Date: Sat, 4 Jan 2025 20:34:53 +0100 Subject: [PATCH 1/2] Add toolbar "Appearance" option to show file extensions --- .../Contracts/IAppearanceSettingsService.cs | 5 +++++ .../Settings/AppearanceSettingsService.cs | 9 +++++++- .../Services/Storage/StorageCacheService.cs | 21 ++++++++++++++++--- .../Enumerators/Win32StorageEnumerator.cs | 5 ++++- .../Settings/AppearanceViewModel.cs | 14 +++++++++++++ .../Views/Settings/AppearancePage.xaml | 9 ++++++++ 6 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/Files.App/Data/Contracts/IAppearanceSettingsService.cs b/src/Files.App/Data/Contracts/IAppearanceSettingsService.cs index 33e94449d359..6a22c1e0c505 100644 --- a/src/Files.App/Data/Contracts/IAppearanceSettingsService.cs +++ b/src/Files.App/Data/Contracts/IAppearanceSettingsService.cs @@ -111,5 +111,10 @@ public interface IAppearanceSettingsService : IBaseSettingsService, INotifyPrope /// Gets or sets a value whether the home button should be displayed. /// bool ShowHomeButton { get; set; } + + /// + /// Gets or sets a value whether the file extension should be displayed always or only during the editing. + /// + bool ShowFileExtensionsOnlyWhileEditing { get; set; } } } diff --git a/src/Files.App/Services/Settings/AppearanceSettingsService.cs b/src/Files.App/Services/Settings/AppearanceSettingsService.cs index b547549648b5..c0afaa5af9ce 100644 --- a/src/Files.App/Services/Settings/AppearanceSettingsService.cs +++ b/src/Files.App/Services/Settings/AppearanceSettingsService.cs @@ -148,7 +148,14 @@ public bool ShowTabActions /// public bool ShowHomeButton { - get => Get(false); + get => Get(true); + set => Set(value); + } + + /// + public bool ShowFileExtensionsOnlyWhileEditing + { + get => Get(true); set => Set(value); } diff --git a/src/Files.App/Services/Storage/StorageCacheService.cs b/src/Files.App/Services/Storage/StorageCacheService.cs index 59adf403faa9..074dec853899 100644 --- a/src/Files.App/Services/Storage/StorageCacheService.cs +++ b/src/Files.App/Services/Storage/StorageCacheService.cs @@ -10,13 +10,28 @@ internal sealed class StorageCacheService : IStorageCacheService { private readonly ConcurrentDictionary cachedDictionary = new(); + private readonly IUserSettingsService _userSettingsService; + + public StorageCacheService(IUserSettingsService userSettingsService) + { + _userSettingsService = userSettingsService; + } + /// public ValueTask GetDisplayName(string path, CancellationToken cancellationToken) { - return - cachedDictionary.TryGetValue(path, out var displayName) + if (_userSettingsService.AppearanceSettingsService.ShowFileExtensionsOnlyWhileEditing) + { + return cachedDictionary.TryGetValue(path, out var displayName) ? ValueTask.FromResult(displayName) - : ValueTask.FromResult(string.Empty); + : ValueTask.FromResult(SystemIO.Path.GetFileName(path)); + } + else + { + return cachedDictionary.TryGetValue(path, out var displayName) + ? ValueTask.FromResult(SystemIO.Path.GetFileNameWithoutExtension(displayName)) + : ValueTask.FromResult(SystemIO.Path.GetFileNameWithoutExtension(path)); + } } /// diff --git a/src/Files.App/Utils/Storage/Enumerators/Win32StorageEnumerator.cs b/src/Files.App/Utils/Storage/Enumerators/Win32StorageEnumerator.cs index 64bf1c0e2915..072f4693eff9 100644 --- a/src/Files.App/Utils/Storage/Enumerators/Win32StorageEnumerator.cs +++ b/src/Files.App/Utils/Storage/Enumerators/Win32StorageEnumerator.cs @@ -227,7 +227,10 @@ CancellationToken cancellationToken ) { var itemPath = Path.Combine(pathRoot, findData.cFileName); - var itemName = findData.cFileName; + + var itemName = await fileListCache.GetDisplayName(itemPath, cancellationToken); + if (string.IsNullOrEmpty(itemName)) + itemName = findData.cFileName; DateTime itemModifiedDate, itemCreatedDate, itemLastAccessDate; diff --git a/src/Files.App/ViewModels/Settings/AppearanceViewModel.cs b/src/Files.App/ViewModels/Settings/AppearanceViewModel.cs index aa8409e6332a..53437149ed41 100644 --- a/src/Files.App/ViewModels/Settings/AppearanceViewModel.cs +++ b/src/Files.App/ViewModels/Settings/AppearanceViewModel.cs @@ -315,5 +315,19 @@ public bool ShowHomeButton } } } + + public bool ShowFileExtensions + { + get => UserSettingsService.AppearanceSettingsService.ShowFileExtensionsOnlyWhileEditing; + set + { + if (value != UserSettingsService.AppearanceSettingsService.ShowFileExtensionsOnlyWhileEditing) + { + UserSettingsService.AppearanceSettingsService.ShowFileExtensionsOnlyWhileEditing = value; + + OnPropertyChanged(); + } + } + } } } diff --git a/src/Files.App/Views/Settings/AppearancePage.xaml b/src/Files.App/Views/Settings/AppearancePage.xaml index 9d0d643e543c..685639790fb9 100644 --- a/src/Files.App/Views/Settings/AppearancePage.xaml +++ b/src/Files.App/Views/Settings/AppearancePage.xaml @@ -277,6 +277,15 @@ IsOn="{x:Bind ViewModel.ShowToolbar, Mode=TwoWay}" Style="{StaticResource RightAlignedToggleSwitchStyle}" /> + + + + + From 958995dce36eb400255291967b7aaea4b6975890 Mon Sep 17 00:00:00 2001 From: "ivan.haidov" Date: Tue, 7 Jan 2025 00:07:44 +0100 Subject: [PATCH 2/2] Add file extension to be shown during the rename action --- src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs b/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs index 77c87b188575..fe7a9c64ff87 100644 --- a/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs +++ b/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs @@ -362,6 +362,11 @@ override public void StartRenameItem() return; Grid.SetColumnSpan(textBox.FindParent(), 8); + + if (RenamingItem is ListedItem item) + { + textBox.Text = SystemIO.Path.GetFileName(item.ItemPath); + } } private void ItemNameTextBox_BeforeTextChanging(TextBox textBox, TextBoxBeforeTextChangingEventArgs args)