Skip to content

Commit 0292839

Browse files
authored
MainPage MVVM (#4161)
1 parent aaddb45 commit 0292839

31 files changed

+840
-684
lines changed

Files/App.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)
195195
}
196196
else
197197
{
198-
if (!(string.IsNullOrEmpty(e.Arguments) && MainPage.AppInstances.Count > 0))
198+
if (!(string.IsNullOrEmpty(e.Arguments) && MainPageViewModel.AppInstances.Count > 0))
199199
{
200-
await MainPage.AddNewTabByPathAsync(typeof(PaneHolderPage), e.Arguments);
200+
await MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), e.Arguments);
201201
}
202202
}
203203

@@ -421,7 +421,7 @@ public static void SaveSessionTabs() // Enumerates through all tabs and gets the
421421
{
422422
if (AppSettings != null)
423423
{
424-
AppSettings.LastSessionPages = MainPage.AppInstances.DefaultIfEmpty().Select(tab =>
424+
AppSettings.LastSessionPages = MainPageViewModel.AppInstances.DefaultIfEmpty().Select(tab =>
425425
{
426426
if (tab != null && tab.TabItemArguments != null)
427427
{

Files/DataModels/SidebarPinnedModel.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
using Files.Controllers;
33
using Files.Filesystem;
44
using Files.Helpers;
5+
using Files.UserControls;
56
using Files.ViewModels;
6-
using Files.Views;
77
using Microsoft.Toolkit.Uwp;
88
using Newtonsoft.Json;
99
using System;
@@ -12,6 +12,7 @@
1212
using System.Diagnostics;
1313
using System.IO;
1414
using System.Linq;
15+
using System.Threading;
1516
using System.Threading.Tasks;
1617
using Windows.Storage;
1718
using Windows.UI.Xaml;
@@ -96,7 +97,7 @@ public async void AddItem(string item)
9697

9798
public async Task ShowHideRecycleBinItemAsync(bool show)
9899
{
99-
await MainPage.SideBarItemsSemaphore.WaitAsync();
100+
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
100101
try
101102
{
102103
if (show)
@@ -129,7 +130,7 @@ public async Task ShowHideRecycleBinItemAsync(bool show)
129130
}
130131
finally
131132
{
132-
MainPage.SideBarItemsSemaphore.Release();
133+
SidebarControl.SideBarItemsSemaphore.Release();
133134
}
134135
}
135136

@@ -303,10 +304,10 @@ private void AddItemToSidebarAsync(LocationItem section)
303304
/// </summary>
304305
public async Task AddAllItemsToSidebar()
305306
{
306-
await MainPage.SideBarItemsSemaphore.WaitAsync();
307+
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
307308
try
308309
{
309-
MainPage.SideBarItems.BeginBulkOperation();
310+
SidebarControl.SideBarItems.BeginBulkOperation();
310311

311312
if (homeSection != null)
312313
{
@@ -319,16 +320,16 @@ public async Task AddAllItemsToSidebar()
319320
await AddItemToSidebarAsync(path);
320321
}
321322

322-
if (!MainPage.SideBarItems.Contains(favoriteSection))
323+
if (!SidebarControl.SideBarItems.Contains(favoriteSection))
323324
{
324-
MainPage.SideBarItems.Add(favoriteSection);
325+
SidebarControl.SideBarItems.Add(favoriteSection);
325326
}
326327

327-
MainPage.SideBarItems.EndBulkOperation();
328+
SidebarControl.SideBarItems.EndBulkOperation();
328329
}
329330
finally
330331
{
331-
MainPage.SideBarItemsSemaphore.Release();
332+
SidebarControl.SideBarItemsSemaphore.Release();
332333
}
333334

334335
await ShowHideRecycleBinItemAsync(App.AppSettings.PinRecycleBinToSideBar);

Files/Dialogs/ExceptionDialog.xaml.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Files.Views;
1+
using Files.ViewModels;
2+
using Files.Views;
23
using System.Linq;
34
using Windows.UI.Xaml;
45
using Windows.UI.Xaml.Controls;
@@ -20,13 +21,13 @@ public ExceptionDialog()
2021

2122
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
2223
{
23-
if (MainPage.MultitaskingControl.Items.Count == 1)
24+
if (MainPageViewModel.MultitaskingControl.Items.Count == 1)
2425
{
2526
App.CloseApp();
2627
}
27-
else if (MainPage.MultitaskingControl.Items.Count > 1)
28+
else if (MainPageViewModel.MultitaskingControl.Items.Count > 1)
2829
{
29-
MainPage.MultitaskingControl.RemoveTab(MainPage.MultitaskingControl.Items.ElementAt(App.InteractionViewModel.TabStripSelectedIndex));
30+
MainPageViewModel.MultitaskingControl?.CloseTab(MainPageViewModel.MultitaskingControl.Items.ElementAt(App.InteractionViewModel.TabStripSelectedIndex));
3031
}
3132
}
3233

Files/Files.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
<Compile Include="UserControls\RestartControl.xaml.cs">
221221
<DependentUpon>RestartControl.xaml</DependentUpon>
222222
</Compile>
223-
<Compile Include="Helpers\DeviceHelpers.cs" />
223+
<Compile Include="Helpers\DriveHelpers.cs" />
224224
<Compile Include="Helpers\ExternalResourcesHelper.cs" />
225225
<Compile Include="Helpers\GlyphHelper.cs" />
226226
<Compile Include="Helpers\FileThumbnailHelper.cs" />
@@ -236,6 +236,7 @@
236236
<Compile Include="Helpers\ExtensionManager.cs" />
237237
<Compile Include="Helpers\IntervalSampler.cs" />
238238
<Compile Include="Helpers\QuickLookHelpers.cs" />
239+
<Compile Include="Helpers\MultitaskingTabsHelpers.cs" />
239240
<Compile Include="Helpers\RegistryHelper.cs" />
240241
<Compile Include="Helpers\SidebarHelpers.cs" />
241242
<Compile Include="Helpers\XamlHelpers\DependencyObjectHelpers.cs" />
@@ -290,6 +291,7 @@
290291
<Compile Include="ViewModels\Bundles\BundlesViewModel.cs" />
291292
<Compile Include="ViewModels\Dialogs\DynamicDialogViewModel.cs" />
292293
<Compile Include="ViewModels\FolderSettingsViewModel.cs" />
294+
<Compile Include="ViewModels\MainPageViewModel.cs" />
293295
<Compile Include="ViewModels\PreviewPaneViewModel.cs" />
294296
<Compile Include="ViewModels\Previews\BasePreviewModel.cs" />
295297
<Compile Include="ViewModels\Previews\BasicPreviewViewModel.cs" />

Files/Filesystem/CloudDrivesManager.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Files.Filesystem.Cloud;
2-
using Files.Views;
2+
using Files.UserControls;
33
using Microsoft.Toolkit.Mvvm.ComponentModel;
44
using Microsoft.Toolkit.Uwp;
55
using NLog;
@@ -84,12 +84,12 @@ private async Task SyncSideBarItemsUI()
8484
{
8585
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
8686
{
87-
await MainPage.SideBarItemsSemaphore.WaitAsync();
87+
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
8888
try
8989
{
90-
MainPage.SideBarItems.BeginBulkOperation();
90+
SidebarControl.SideBarItems.BeginBulkOperation();
9191

92-
var section = MainPage.SideBarItems.FirstOrDefault(x => x.Text == "SidebarCloudDrives".GetLocalized()) as LocationItem;
92+
var section = SidebarControl.SideBarItems.FirstOrDefault(x => x.Text == "SidebarCloudDrives".GetLocalized()) as LocationItem;
9393
if (section == null)
9494
{
9595
section = new LocationItem()
@@ -100,7 +100,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
100100
SelectsOnInvoked = false,
101101
ChildItems = new ObservableCollection<INavigationControlItem>()
102102
};
103-
MainPage.SideBarItems.Add(section);
103+
SidebarControl.SideBarItems.Add(section);
104104
}
105105

106106
foreach (DriveItem drive in Drives.ToList())
@@ -111,11 +111,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
111111
}
112112
}
113113

114-
MainPage.SideBarItems.EndBulkOperation();
114+
SidebarControl.SideBarItems.EndBulkOperation();
115115
}
116116
finally
117117
{
118-
MainPage.SideBarItemsSemaphore.Release();
118+
SidebarControl.SideBarItemsSemaphore.Release();
119119
}
120120
});
121121
}

Files/Filesystem/Drives.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Files.Common;
22
using Files.Enums;
3+
using Files.UserControls;
34
using Files.UserControls.Widgets;
4-
using Files.Views;
55
using Microsoft.Toolkit.Mvvm.ComponentModel;
66
using Microsoft.Toolkit.Uwp;
77
using Microsoft.Toolkit.Uwp.Helpers;
@@ -122,12 +122,12 @@ private async Task SyncSideBarItemsUI()
122122
{
123123
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
124124
{
125-
await MainPage.SideBarItemsSemaphore.WaitAsync();
125+
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
126126
try
127127
{
128-
MainPage.SideBarItems.BeginBulkOperation();
128+
SidebarControl.SideBarItems.BeginBulkOperation();
129129

130-
var section = MainPage.SideBarItems.FirstOrDefault(x => x.Text == "SidebarDrives".GetLocalized()) as LocationItem;
130+
var section = SidebarControl.SideBarItems.FirstOrDefault(x => x.Text == "SidebarDrives".GetLocalized()) as LocationItem;
131131
if (section == null)
132132
{
133133
section = new LocationItem()
@@ -138,7 +138,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
138138
SelectsOnInvoked = false,
139139
ChildItems = new ObservableCollection<INavigationControlItem>()
140140
};
141-
MainPage.SideBarItems.Add(section);
141+
SidebarControl.SideBarItems.Add(section);
142142
}
143143

144144
foreach (DriveItem drive in Drives.ToList())
@@ -163,11 +163,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
163163
}
164164
}
165165

166-
MainPage.SideBarItems.EndBulkOperation();
166+
SidebarControl.SideBarItems.EndBulkOperation();
167167
}
168168
finally
169169
{
170-
MainPage.SideBarItemsSemaphore.Release();
170+
SidebarControl.SideBarItemsSemaphore.Release();
171171
}
172172
});
173173
}

Files/Filesystem/LibraryManager.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Files.Helpers;
2+
using Files.UserControls;
23
using Files.ViewModels;
3-
using Files.Views;
44
using Microsoft.Toolkit.Mvvm.ComponentModel;
55
using Microsoft.Toolkit.Uwp;
66
using System;
@@ -69,34 +69,34 @@ private async void RemoveEnumerateDrivesAsync(CoreApplicationView sender, Window
6969

7070
public async Task RemoveLibrarySideBarItemsUI()
7171
{
72-
MainPage.SideBarItems.BeginBulkOperation();
72+
SidebarControl.SideBarItems.BeginBulkOperation();
7373

7474
try
7575
{
76-
var item = (from n in MainPage.SideBarItems where n.Text.Equals("SidebarLibraries".GetLocalized()) select n).FirstOrDefault();
76+
var item = (from n in SidebarControl.SideBarItems where n.Text.Equals("SidebarLibraries".GetLocalized()) select n).FirstOrDefault();
7777
if (!App.AppSettings.ShowLibrarySection && item != null)
7878
{
79-
MainPage.SideBarItems.Remove(item);
79+
SidebarControl.SideBarItems.Remove(item);
8080
}
8181
}
8282
catch (Exception)
8383
{ }
8484

85-
MainPage.SideBarItems.EndBulkOperation();
85+
SidebarControl.SideBarItems.EndBulkOperation();
8686
}
8787

8888
private async Task SyncLibrarySideBarItemsUI()
8989
{
9090
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
9191
{
92-
await MainPage.SideBarItemsSemaphore.WaitAsync();
92+
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
9393
try
9494
{
95-
MainPage.SideBarItems.BeginBulkOperation();
95+
SidebarControl.SideBarItems.BeginBulkOperation();
9696

9797
try
9898
{
99-
if (App.AppSettings.ShowLibrarySection && !MainPage.SideBarItems.Contains(librarySection))
99+
if (App.AppSettings.ShowLibrarySection && !SidebarControl.SideBarItems.Contains(librarySection))
100100
{
101101
librarySection = new LocationItem()
102102
{
@@ -107,8 +107,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
107107
SelectsOnInvoked = false,
108108
ChildItems = new ObservableCollection<INavigationControlItem>()
109109
};
110-
111-
MainPage.SideBarItems.Insert(1, librarySection);
110+
SidebarControl.SideBarItems.Insert(1, librarySection);
112111

113112
libraryItems.Clear();
114113
libraryItems.Add(AppSettings.DocumentsPath);
@@ -144,13 +143,13 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
144143
{
145144
}
146145

147-
MainPage.SideBarItems.EndBulkOperation();
146+
SidebarControl.SideBarItems.EndBulkOperation();
148147
}
149148
finally
150149
{
151-
MainPage.SideBarItemsSemaphore.Release();
150+
SidebarControl.SideBarItemsSemaphore.Release();
152151
}
153152
});
154153
}
155154
}
156-
}
155+
}

Files/Filesystem/NetworkDrivesManager.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Files.Helpers;
2-
using Files.Views;
2+
using Files.UserControls;
33
using Microsoft.Toolkit.Mvvm.ComponentModel;
44
using Microsoft.Toolkit.Uwp;
55
using NLog;
@@ -107,12 +107,12 @@ private async Task SyncSideBarItemsUI()
107107
{
108108
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
109109
{
110-
await MainPage.SideBarItemsSemaphore.WaitAsync();
110+
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
111111
try
112112
{
113-
MainPage.SideBarItems.BeginBulkOperation();
113+
SidebarControl.SideBarItems.BeginBulkOperation();
114114

115-
var section = MainPage.SideBarItems.FirstOrDefault(x => x.Text == "SidebarNetworkDrives".GetLocalized()) as LocationItem;
115+
var section = SidebarControl.SideBarItems.FirstOrDefault(x => x.Text == "SidebarNetworkDrives".GetLocalized()) as LocationItem;
116116
if (section == null && this.drivesList.Any(d => d.DeviceID != "network-folder"))
117117
{
118118
section = new LocationItem()
@@ -123,7 +123,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
123123
SelectsOnInvoked = false,
124124
ChildItems = new ObservableCollection<INavigationControlItem>()
125125
};
126-
MainPage.SideBarItems.Add(section);
126+
SidebarControl.SideBarItems.Add(section);
127127
}
128128

129129
if (section != null)
@@ -139,11 +139,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
139139
}
140140
}
141141

142-
MainPage.SideBarItems.EndBulkOperation();
142+
SidebarControl.SideBarItems.EndBulkOperation();
143143
}
144144
finally
145145
{
146-
MainPage.SideBarItemsSemaphore.Release();
146+
SidebarControl.SideBarItemsSemaphore.Release();
147147
}
148148
});
149149
}

Files/Filesystem/StorageFileHelpers/StorageFileExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Files.Common;
22
using Files.Extensions;
3+
using Files.UserControls;
34
using Files.ViewModels;
45
using Files.Views;
56
using System;
@@ -29,7 +30,7 @@ private static PathBoxItem GetPathItem(string component, string path)
2930
}
3031
else if (component.Contains(":"))
3132
{
32-
var allDrives = MainPage.SideBarItems.Where(x => (x as LocationItem)?.ChildItems != null).SelectMany(x => (x as LocationItem).ChildItems);
33+
var allDrives = SidebarControl.SideBarItems.Where(x => (x as LocationItem)?.ChildItems != null).SelectMany(x => (x as LocationItem).ChildItems);
3334
return new PathBoxItem()
3435
{
3536
Title = allDrives.FirstOrDefault(y => y.ItemType == NavigationControlItemType.Drive && y.Path.Contains(component, StringComparison.OrdinalIgnoreCase)) != null ?

0 commit comments

Comments
 (0)