Skip to content

Commit f51e79f

Browse files
authored
Refactor code to prepare for multi-panes (#8163)
1 parent 3ce0860 commit f51e79f

25 files changed

+382
-377
lines changed

src/Files/App.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ sealed partial class App : Application
4949
public static StorageHistoryWrapper HistoryWrapper = new StorageHistoryWrapper();
5050
public static SettingsViewModel AppSettings { get; private set; }
5151
public static MainViewModel MainViewModel { get; private set; }
52+
public static PreviewPaneViewModel PreviewPaneViewModel { get; private set; }
5253
public static JumpListManager JumpList { get; private set; }
5354
public static SidebarPinnedController SidebarPinnedController { get; private set; }
5455
public static TerminalController TerminalController { get; private set; }
@@ -102,7 +103,7 @@ private IServiceProvider ConfigureServices()
102103
.AddSingleton<IWidgetsSettingsService, WidgetsSettingsService>((sp) => new WidgetsSettingsService(sp.GetService<IUserSettingsService>().GetSharingContext()))
103104
.AddSingleton<IAppearanceSettingsService, AppearanceSettingsService>((sp) => new AppearanceSettingsService(sp.GetService<IUserSettingsService>().GetSharingContext()))
104105
.AddSingleton<IPreferencesSettingsService, PreferencesSettingsService>((sp) => new PreferencesSettingsService(sp.GetService<IUserSettingsService>().GetSharingContext()))
105-
.AddSingleton<IPreviewPaneSettingsService, PreviewPaneSettingsService>((sp) => new PreviewPaneSettingsService(sp.GetService<IUserSettingsService>().GetSharingContext()))
106+
.AddSingleton<IPaneSettingsService, PaneSettingsService>((sp) => new PaneSettingsService(sp.GetService<IUserSettingsService>().GetSharingContext()))
106107
.AddSingleton<ILayoutSettingsService, LayoutSettingsService>((sp) => new LayoutSettingsService(sp.GetService<IUserSettingsService>().GetSharingContext()))
107108
// Settings not related to IUserSettingsService:
108109
.AddSingleton<IFileTagsSettingsService, FileTagsSettingsService>()
@@ -131,6 +132,7 @@ private static async Task EnsureSettingsAndConfigurationAreBootstrapped()
131132

132133
JumpList ??= new JumpListManager();
133134
MainViewModel ??= new MainViewModel();
135+
PreviewPaneViewModel ??= new PreviewPaneViewModel();
134136
LibraryManager ??= new LibraryManager();
135137
DrivesManager ??= new DrivesManager();
136138
NetworkDrivesManager ??= new NetworkDrivesManager();
@@ -530,6 +532,7 @@ await Common.Extensions.IgnoreExceptions(async () =>
530532
}
531533

532534
DrivesManager?.Dispose();
535+
PreviewPaneViewModel?.Dispose();
533536

534537
// Try to maintain clipboard data after app close
535538
Common.Extensions.IgnoreExceptions(() =>

src/Files/BaseLayout.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public abstract class BaseLayout : Page, IBaseLayout, INotifyPropertyChanged
6363

6464
public CurrentInstanceViewModel InstanceViewModel => ParentShellPageInstance.InstanceViewModel;
6565

66+
public PreviewPaneViewModel PreviewPaneViewModel => App.PreviewPaneViewModel;
67+
6668
public MainViewModel MainViewModel => App.MainViewModel;
6769
public DirectoryPropertiesViewModel DirectoryPropertiesViewModel { get; }
6870

@@ -76,8 +78,6 @@ public abstract class BaseLayout : Page, IBaseLayout, INotifyPropertyChanged
7678

7779
public IShellPage ParentShellPageInstance { get; private set; } = null;
7880

79-
public PreviewPaneViewModel PreviewPaneViewModel { get; } = new PreviewPaneViewModel();
80-
8181
public bool IsRenamingItem { get; set; } = false;
8282
public ListedItem RenamingItem { get; set; } = null;
8383

@@ -234,9 +234,13 @@ internal set
234234
}
235235

236236
// check if the preview pane is open before updating the model
237-
if (((Window.Current.Content as Frame)?.Content as MainPage)?.LoadPreviewPane ?? false)
237+
if (PreviewPaneViewModel.IsPaneSelected)
238238
{
239-
PreviewPaneViewModel.UpdateSelectedItemPreview();
239+
bool isPaneEnabled = ((Window.Current.Content as Frame)?.Content as MainPage)?.IsPaneEnabled ?? false;
240+
if (isPaneEnabled)
241+
{
242+
PreviewPaneViewModel.UpdateSelectedItemPreview();
243+
}
240244
}
241245
}
242246

src/Files/Enums/PaneContents.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Files.Enums
2+
{
3+
// type long because the others enums do not work as user setting.
4+
public enum PaneContents : long
5+
{
6+
None,
7+
Preview,
8+
}
9+
}

src/Files/Files.csproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
<Compile Include="DataModels\FilesystemItemsOperationDataModel.cs" />
146146
<Compile Include="DataModels\NavigationControlItems\WslDistroItem.cs" />
147147
<Compile Include="Enums\LocalizedEnum.cs" />
148+
<Compile Include="Enums\PaneContents.cs" />
148149
<Compile Include="Extensions\ShellNewEntryExtensions.cs" />
149150
<Compile Include="Dialogs\DecompressArchiveDialog.xaml.cs">
150151
<DependentUpon>DecompressArchiveDialog.xaml</DependentUpon>
@@ -259,12 +260,12 @@
259260
<Compile Include="Services\Implementation\LayoutSettingsService.cs" />
260261
<Compile Include="Services\Implementation\MultitaskingSettingsService.cs" />
261262
<Compile Include="Services\Implementation\PreferencesSettingsService.cs" />
262-
<Compile Include="Services\Implementation\PreviewPaneSettingsService.cs" />
263+
<Compile Include="Services\Implementation\PaneSettingsService.cs" />
263264
<Compile Include="Services\Implementation\UserSettingsService.cs" />
264265
<Compile Include="Services\Implementation\WidgetsSettingsService.cs" />
265266
<Compile Include="Services\IMultitaskingSettingsService.cs" />
266267
<Compile Include="Services\IPreferencesSettingsService.cs" />
267-
<Compile Include="Services\IPreviewPaneSettingsService.cs" />
268+
<Compile Include="Services\IPaneSettingsService.cs" />
268269
<Compile Include="Services\IUpdateSettingsService.cs" />
269270
<Compile Include="Services\IUserSettingsService.cs" />
270271
<Compile Include="Services\IWidgetsSettingsService.cs" />
@@ -285,6 +286,9 @@
285286
<Compile Include="UserControls\InnerNavigationToolbar.xaml.cs">
286287
<DependentUpon>InnerNavigationToolbar.xaml</DependentUpon>
287288
</Compile>
289+
<Compile Include="UserControls\PaneControl.xaml.cs">
290+
<DependentUpon>PaneControl.xaml</DependentUpon>
291+
</Compile>
288292
<Compile Include="UserControls\PathBreadcrumb.xaml.cs">
289293
<DependentUpon>PathBreadcrumb.xaml</DependentUpon>
290294
</Compile>
@@ -1243,6 +1247,10 @@
12431247
<SubType>Designer</SubType>
12441248
<Generator>MSBuild:Compile</Generator>
12451249
</Page>
1250+
<Page Include="UserControls\PaneControl.xaml">
1251+
<Generator>MSBuild:Compile</Generator>
1252+
<SubType>Designer</SubType>
1253+
</Page>
12461254
<Page Include="UserControls\PathBreadcrumb.xaml">
12471255
<SubType>Designer</SubType>
12481256
<Generator>MSBuild:Compile</Generator>

src/Files/Helpers/RegistryToJsonSettingsMerger.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Files.Enums;
22
using Files.Services;
3+
using Files.Services.Implementation;
34
using Files.ViewModels;
45
using Microsoft.Toolkit.Mvvm.DependencyInjection;
56
using System;
@@ -20,12 +21,12 @@ public static void MergeSettings()
2021

2122
try
2223
{
23-
// Preview pane
24-
userSettingsService.PreviewPaneSettingsService.PreviewPaneSizeHorizontalPx = appSettings.Get(300d, "PreviewPaneSizeHorizontal");
25-
userSettingsService.PreviewPaneSettingsService.PreviewPaneSizeVerticalPx = appSettings.Get(250d, "PreviewPaneSizeVertical");
26-
userSettingsService.PreviewPaneSettingsService.PreviewPaneEnabled = appSettings.Get(false, "PreviewPaneEnabled");
27-
userSettingsService.PreviewPaneSettingsService.ShowPreviewOnly = appSettings.Get(false, "ShowPreviewOnly");
28-
userSettingsService.PreviewPaneSettingsService.PreviewPaneMediaVolume = appSettings.Get(1.0d, "MediaVolume");
24+
// Pane
25+
userSettingsService.PaneSettingsService.Content = appSettings.Get(PaneContents.None, PaneSettingsService.ContentKey);
26+
userSettingsService.PaneSettingsService.HorizontalSizePx = appSettings.Get(300d, PaneSettingsService.HorizontalSizePxKey);
27+
userSettingsService.PaneSettingsService.VerticalSizePx = appSettings.Get(250d, PaneSettingsService.VerticalSizePxKey);
28+
userSettingsService.PaneSettingsService.MediaVolume = appSettings.Get(1.0d, PaneSettingsService.MediaVolumeKey);
29+
userSettingsService.PaneSettingsService.ShowPreviewOnly = appSettings.Get(false, PaneSettingsService.ShowPreviewOnlyKey);
2930

3031
// Files and folders
3132
userSettingsService.PreferencesSettingsService.ShowFileExtensions = appSettings.Get(true, "ShowFileExtensions");
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Files.Enums;
2+
using System.ComponentModel;
3+
4+
namespace Files.Services
5+
{
6+
public interface IPaneSettingsService : IBaseSettingsService, INotifyPropertyChanged
7+
{
8+
/// <summary>
9+
/// Gets or sets the selected content.
10+
/// </summary>
11+
PaneContents Content { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets a value indicating the height of the pane in a horizontal layout.
15+
/// </summary>
16+
double HorizontalSizePx { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets a value indicating the width of the pane in a vertical layout.
20+
/// </summary>
21+
double VerticalSizePx { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets a value indicating the default volume on media.
25+
/// </summary>
26+
double MediaVolume { get; set; }
27+
28+
/// <summary>
29+
/// Gets or sets a value indicating if the preview pane should only show the item preview without the details section
30+
/// </summary>
31+
bool ShowPreviewOnly { get; set; }
32+
}
33+
}

src/Files/Services/IPreviewPaneSettingsService.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/Files/Services/IUserSettingsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface IUserSettingsService : IBaseSettingsService
2222

2323
IAppearanceSettingsService AppearanceSettingsService { get; }
2424

25-
IPreviewPaneSettingsService PreviewPaneSettingsService { get; }
25+
IPaneSettingsService PaneSettingsService { get; }
2626

2727
ILayoutSettingsService LayoutSettingsService { get; }
2828
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using Files.Enums;
2+
using Files.EventArguments;
3+
using Files.Models.JsonSettings;
4+
using Microsoft.AppCenter.Analytics;
5+
using System;
6+
7+
namespace Files.Services.Implementation
8+
{
9+
public class PaneSettingsService : BaseObservableJsonSettingsModel, IPaneSettingsService
10+
{
11+
public const string ContentKey = "PaneContent";
12+
public const string HorizontalSizePxKey = "PaneHorizontalSizePx";
13+
public const string VerticalSizePxKey = "PaneVerticalSizePx";
14+
public const string MediaVolumeKey = "PaneMediaVolume";
15+
public const string ShowPreviewOnlyKey = "ShowPreviewOnly";
16+
17+
public PaneContents Content
18+
{
19+
get => Get(PaneContents.None);
20+
set => Set(value);
21+
}
22+
23+
public double HorizontalSizePx
24+
{
25+
get => Math.Max(100d, Get(300d));
26+
set => Set(Math.Max(100d, value));
27+
}
28+
public double VerticalSizePx
29+
{
30+
get => Math.Max(100d, Get(250d));
31+
set => Set(Math.Max(100d, value));
32+
}
33+
34+
public double MediaVolume
35+
{
36+
get => Math.Min(Math.Max(Get(1d), 0d), 1d);
37+
set => Set(Math.Max(0d, Math.Min(value, 1d)));
38+
}
39+
40+
public bool ShowPreviewOnly
41+
{
42+
get => Get(false);
43+
set => Set(value);
44+
}
45+
46+
public PaneSettingsService(ISettingsSharingContext settingsSharingContext)
47+
=> RegisterSettingsContext(settingsSharingContext);
48+
49+
public void ReportToAppCenter()
50+
=> Analytics.TrackEvent($"{nameof(ShowPreviewOnly)}, {ShowPreviewOnly}");
51+
52+
public override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
53+
{
54+
if (e.settingName is nameof(ShowPreviewOnly))
55+
{
56+
Analytics.TrackEvent($"{e.settingName} {e.newValue}");
57+
}
58+
base.RaiseOnSettingChangedEvent(sender, e);
59+
}
60+
61+
private void RaiseOnSettingChangedEvent(string propertyName, object newValue)
62+
{
63+
string settingName = propertyName switch
64+
{
65+
nameof(Content) => ContentKey,
66+
nameof(HorizontalSizePx) => HorizontalSizePxKey,
67+
nameof(VerticalSizePxKey) => VerticalSizePxKey,
68+
nameof(MediaVolume) => MediaVolumeKey,
69+
nameof(ShowPreviewOnly) => ShowPreviewOnlyKey,
70+
_ => throw new InvalidOperationException(),
71+
};
72+
base.RaiseOnSettingChangedEvent(this, new SettingChangedEventArgs(settingName, newValue));
73+
}
74+
}
75+
}

src/Files/Services/Implementation/PreviewPaneSettingsService.cs

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)