Skip to content

Commit d2612a1

Browse files
authored
Merge branch 'main' into bug-10549
2 parents 2b6984b + be3288b commit d2612a1

18 files changed

+160
-146
lines changed

src/Files.App/Helpers/AppThemeResourcesHelper.cs

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1+
using CommunityToolkit.Mvvm.DependencyInjection;
2+
using CommunityToolkit.WinUI.Helpers;
3+
using Files.Backend.Services.Settings;
14
using Microsoft.UI.Xaml;
5+
using System;
26
using Windows.UI;
37

48
namespace Files.App.Helpers
59
{
610
public sealed class AppThemeResourcesHelper
711
{
12+
public IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
13+
814
/// <summary>
9-
/// Forces the application to use the correct resource styles
15+
/// Applies updated resource styles
1016
/// </summary>
1117
public void ApplyResources()
1218
{
1319
// Get the index of the current theme
1420
var selTheme = ThemeHelper.RootTheme;
1521

16-
// Toggle between the themes to force the controls to use the new resource styles
22+
// Toggle between the themes to force reload the resource styles
1723
ThemeHelper.RootTheme = ElementTheme.Dark;
1824
ThemeHelper.RootTheme = ElementTheme.Light;
1925

@@ -75,16 +81,47 @@ public void SetAppThemeFontFamily(string contentControlThemeFontFamily)
7581
/// <param name="useCompactSpacing"></param>
7682
public void SetCompactSpacing(bool useCompactSpacing)
7783
{
78-
if (useCompactSpacing)
79-
{
80-
Application.Current.Resources["ListItemHeight"] = 24;
81-
Application.Current.Resources["NavigationViewItemOnLeftMinHeight"] = 20;
82-
}
84+
var listItemHeight = useCompactSpacing ? 24 : 36;
85+
var navigationViewItemOnLeftMinHeight = useCompactSpacing ? 20 : 32;
86+
87+
Application.Current.Resources["ListItemHeight"] = listItemHeight;
88+
Application.Current.Resources["NavigationViewItemOnLeftMinHeight"] = navigationViewItemOnLeftMinHeight;
89+
}
90+
91+
/// <summary>
92+
/// Loads the resource styles from settings
93+
/// </summary>
94+
public void LoadAppResources()
95+
{
96+
var useCompactStyles = UserSettingsService.AppearanceSettingsService.UseCompactStyles;
97+
var appThemeBackgroundColor = ColorHelper.ToColor(UserSettingsService.AppearanceSettingsService.AppThemeBackgroundColor);
98+
var appThemeAddressBarBackgroundColor = UserSettingsService.AppearanceSettingsService.AppThemeAddressBarBackgroundColor;
99+
var appThemeSidebarBackgroundColor = UserSettingsService.AppearanceSettingsService.AppThemeSidebarBackgroundColor;
100+
var appThemeFileAreaBackgroundColor = UserSettingsService.AppearanceSettingsService.AppThemeFileAreaBackgroundColor;
101+
var appThemeFontFamily = UserSettingsService.AppearanceSettingsService.AppThemeFontFamily;
102+
103+
SetCompactSpacing(useCompactStyles);
104+
SetAppThemeBackgroundColor(appThemeBackgroundColor);
105+
106+
if (!String.IsNullOrWhiteSpace(appThemeAddressBarBackgroundColor) && appThemeAddressBarBackgroundColor != "#00000000")
107+
SetAppThemeAddressBarBackgroundColor(ColorHelper.ToColor(appThemeAddressBarBackgroundColor));
108+
else
109+
UserSettingsService.AppearanceSettingsService.AppThemeAddressBarBackgroundColor = ""; //migrate to new default
110+
111+
if (!String.IsNullOrWhiteSpace(appThemeSidebarBackgroundColor) && appThemeAddressBarBackgroundColor != "#00000000")
112+
SetAppThemeSidebarBackgroundColor(ColorHelper.ToColor(appThemeSidebarBackgroundColor));
83113
else
84-
{
85-
Application.Current.Resources["ListItemHeight"] = 36;
86-
Application.Current.Resources["NavigationViewItemOnLeftMinHeight"] = 32;
87-
}
114+
UserSettingsService.AppearanceSettingsService.AppThemeSidebarBackgroundColor = ""; //migrate to new default
115+
116+
if (!String.IsNullOrWhiteSpace(appThemeFileAreaBackgroundColor) && appThemeAddressBarBackgroundColor != "#00000000")
117+
SetAppThemeFileAreaBackgroundColor(ColorHelper.ToColor(appThemeFileAreaBackgroundColor));
118+
else
119+
UserSettingsService.AppearanceSettingsService.AppThemeFileAreaBackgroundColor = ""; //migrate to new default
120+
121+
if (appThemeFontFamily != "Segoe UI Variable")
122+
SetAppThemeFontFamily(appThemeFontFamily);
123+
124+
ApplyResources();
88125
}
89126
}
90127
}

src/Files.App/Helpers/ContextFlyoutItemHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
658658
Tag = "OpenWith",
659659
CollapseLabel = true,
660660
ShowInSearchPage = true,
661-
ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder && i.IsArchive)),
661+
ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == StorageItemTypes.Folder && i.IsArchive)),
662662
},
663663
new ContextMenuFlyoutItemViewModel()
664664
{
@@ -675,7 +675,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
675675
}
676676
},
677677
ShowInSearchPage = true,
678-
ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder && i.IsArchive)),
678+
ShowItem = selectedItems.All(i => (i.PrimaryItemAttribute == StorageItemTypes.File && !i.IsShortcut && !i.IsExecutable) || (i.PrimaryItemAttribute == StorageItemTypes.Folder && i.IsArchive)),
679679
},
680680
new ContextMenuFlyoutItemViewModel()
681681
{
@@ -688,10 +688,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
688688
new ContextMenuFlyoutItemViewModel()
689689
{
690690
Text = "BaseLayoutItemContextFlyoutOpenInNewPane/Text".GetLocalizedResource(),
691-
Glyph = "\uE117",
691+
Glyph = "\xF117",
692692
GlyphFontFamilyName = "CustomGlyph",
693693
Command = commandsViewModel.OpenDirectoryInNewPaneCommand,
694-
ShowItem = userSettingsService.PreferencesSettingsService.IsDualPaneEnabled && selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder),
694+
ShowItem = userSettingsService.PreferencesSettingsService.IsDualPaneEnabled && selectedItems.All(i => i.PrimaryItemAttribute == StorageItemTypes.Folder),
695695
SingleItemOnly = true,
696696
ShowInSearchPage = true,
697697
ShowInFtpPage = true,
@@ -703,7 +703,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
703703
Glyph = "\uF113",
704704
GlyphFontFamilyName = "CustomGlyph",
705705
Command = commandsViewModel.OpenDirectoryInNewTabCommand,
706-
ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder),
706+
ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == StorageItemTypes.Folder),
707707
ShowInSearchPage = true,
708708
ShowInFtpPage = true,
709709
ShowInZipPage = true,
@@ -713,7 +713,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
713713
Text = "BaseLayoutItemContextFlyoutOpenInNewWindow/Text".GetLocalizedResource(),
714714
Glyph = "\uE737",
715715
Command = commandsViewModel.OpenInNewWindowItemCommand,
716-
ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == Windows.Storage.StorageItemTypes.Folder),
716+
ShowItem = selectedItems.Count < 5 && selectedItems.All(i => i.PrimaryItemAttribute == StorageItemTypes.Folder),
717717
ShowInSearchPage = true,
718718
ShowInFtpPage = true,
719719
ShowOnShift = true,

src/Files.App/Helpers/NavigationHelpers.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Files.App.Extensions;
33
using Files.App.Filesystem;
44
using Files.App.Filesystem.StorageItems;
5+
using Files.App.ServicesImplementation.Settings;
56
using Files.App.Shell;
67
using Files.App.ViewModels;
78
using Files.App.Views;
@@ -21,6 +22,8 @@ namespace Files.App.Helpers
2122
{
2223
public static class NavigationHelpers
2324
{
25+
private static readonly IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
26+
2427
public static Task OpenPathInNewTab(string path)
2528
=> MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), path);
2629

@@ -36,6 +39,17 @@ public static Task<bool> OpenTabInNewWindowAsync(string tabArgs)
3639
return Launcher.LaunchUriAsync(folderUri).AsTask();
3740
}
3841

42+
public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem listedItem)
43+
{
44+
if(associatedInstance is null || listedItem is null)
45+
return;
46+
47+
if (!userSettingsService.PreferencesSettingsService.IsDualPaneEnabled)
48+
return;
49+
50+
associatedInstance.PaneHolder?.OpenPathInNewPane((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
51+
}
52+
3953
public static Task LaunchNewWindowAsync()
4054
{
4155
var filesUWPUri = new Uri("files-uwp:");

src/Files.App/Helpers/ResourceHelpers.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@ namespace Files.App.Helpers
66
[MarkupExtensionReturnType(ReturnType = typeof(string))]
77
public sealed class ResourceString : MarkupExtension
88
{
9-
private static ResourceLoader resourceLoader = new ResourceLoader();
9+
private static readonly ResourceLoader resourceLoader = new();
1010

11-
public string Name
12-
{
13-
get; set;
14-
}
11+
public string Name { get; set; } = string.Empty;
1512

16-
protected override object ProvideValue()
17-
{
18-
return resourceLoader.GetString(this.Name);
19-
}
13+
protected override object ProvideValue() => resourceLoader.GetString(Name);
2014
}
2115
}

src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,7 @@ await App.Window.DispatcherQueue.EnqueueAsync(async () =>
261261

262262
public virtual void OpenDirectoryInNewPane(RoutedEventArgs e)
263263
{
264-
ListedItem listedItem = SlimContentPage.SelectedItems.FirstOrDefault();
265-
if (listedItem is not null)
266-
associatedInstance.PaneHolder?.OpenPathInNewPane((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
264+
NavigationHelpers.OpenInSecondaryPane(associatedInstance, SlimContentPage.SelectedItems.FirstOrDefault());
267265
}
268266

269267
public virtual async void OpenInNewWindowItem(RoutedEventArgs e)

src/Files.App/Serialization/BaseObservableJsonSettings.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,16 @@ internal abstract class BaseObservableJsonSettings : BaseJsonSettings, INotifyPr
77
{
88
public event PropertyChangedEventHandler? PropertyChanged;
99

10-
protected override bool Set<TValue>(TValue? value, [CallerMemberName] string propertyName = "")
11-
where TValue : default
10+
protected override bool Set<TValue>(TValue? value, [CallerMemberName] string propertyName = "") where TValue : default
1211
{
13-
if (base.Set<TValue>(value, propertyName))
14-
{
15-
OnPropertyChanged(propertyName);
16-
return true;
17-
}
12+
if (!base.Set<TValue>(value, propertyName))
13+
return false;
1814

19-
return false;
15+
OnPropertyChanged(propertyName);
16+
return true;
2017
}
2118

2219
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
23-
{
24-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
25-
}
20+
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
2621
}
2722
}

src/Files.App/Shell/ContextMenuItem.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ namespace Files.App.Shell
66
{
77
public class ContextMenuItem : Win32ContextMenuItem, IDisposable
88
{
9-
public ContextMenuItem()
10-
{
11-
SubItems = new List<Win32ContextMenuItem>();
12-
}
9+
public ContextMenuItem() => SubItems = new List<Win32ContextMenuItem>();
1310

1411
public void Dispose()
1512
{
@@ -19,17 +16,12 @@ public void Dispose()
1916

2017
protected virtual void Dispose(bool disposing)
2118
{
22-
if (disposing)
19+
if (disposing && SubItems is not null)
2320
{
24-
if (SubItems is not null)
25-
{
26-
foreach (var si in SubItems)
27-
{
28-
(si as IDisposable)?.Dispose();
29-
}
21+
foreach (var subItem in SubItems)
22+
(subItem as IDisposable)?.Dispose();
3023

31-
SubItems = null;
32-
}
24+
SubItems = null;
3325
}
3426
}
3527
}

src/Files.App/ValueConverters/ColorToSolidColorBrushValueConverter.cs renamed to src/Files.App/ValueConverters/StringToSolidColorBrushValueConverter.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
using Microsoft.UI.Xaml.Data;
1+
using CommunityToolkit.WinUI.Helpers;
2+
using Microsoft.UI.Xaml.Data;
23
using Microsoft.UI.Xaml.Media;
34
using System;
45
using Windows.UI;
56

67
namespace Files.App.ValueConverters
78
{
8-
public class ColorToSolidColorBrushValueConverter : IValueConverter
9+
public class StringToSolidColorBrushValueConverter : IValueConverter
910
{
1011
public object? Convert(object value, Type targetType, object parameter, string language)
1112
{
1213
if (null == value)
1314
return null;
1415

15-
if (value is Color)
16+
if (value is string colorString)
1617
{
17-
Color color = (Color)value;
18+
Color color = ColorHelper.ToColor(colorString);
1819
return new SolidColorBrush(color);
1920
}
2021

src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,10 @@ public bool IsWindowCompactOverlay
5050
}
5151

5252
public ICommand NavigateToNumberedTabKeyboardAcceleratorCommand { get; private set; }
53-
5453
public IAsyncRelayCommand OpenNewWindowAcceleratorCommand { get; private set; }
55-
5654
public ICommand CloseSelectedTabKeyboardAcceleratorCommand { get; private set; }
57-
5855
public IAsyncRelayCommand AddNewInstanceAcceleratorCommand { get; private set; }
59-
6056
public ICommand ReopenClosedTabAcceleratorCommand { get; private set; }
61-
6257
public ICommand OpenSettingsCommand { get; private set; }
6358

6459
public MainPageViewModel()
@@ -408,6 +403,10 @@ public async void OnNavigatedTo(NavigationEventArgs e)
408403
else if (e.Parameter is TabItemArguments tabArgs)
409404
await AddNewTabByParam(tabArgs.InitialPageType, tabArgs.NavigationArg);
410405
}
406+
407+
408+
// Load the app theme resources
409+
App.AppThemeResourcesHelper.LoadAppResources();
411410
}
412411

413412
public static Task AddNewTabAsync()

0 commit comments

Comments
 (0)