Skip to content
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

MainPage MVVM #4161

Merged
merged 10 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
6 changes: 3 additions & 3 deletions Files/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)
}
else
{
if (!(string.IsNullOrEmpty(e.Arguments) && MainPage.AppInstances.Count > 0))
if (!(string.IsNullOrEmpty(e.Arguments) && MainPageViewModel.AppInstances.Count > 0))
{
await MainPage.AddNewTabByPathAsync(typeof(PaneHolderPage), e.Arguments);
await MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), e.Arguments);
}
}

Expand Down Expand Up @@ -421,7 +421,7 @@ public static void SaveSessionTabs() // Enumerates through all tabs and gets the
{
if (AppSettings != null)
{
AppSettings.LastSessionPages = MainPage.AppInstances.DefaultIfEmpty().Select(tab =>
AppSettings.LastSessionPages = MainPageViewModel.AppInstances.DefaultIfEmpty().Select(tab =>
{
if (tab != null && tab.TabItemArguments != null)
{
Expand Down
19 changes: 10 additions & 9 deletions Files/DataModels/SidebarPinnedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Files.Controllers;
using Files.Filesystem;
using Files.Helpers;
using Files.UserControls;
using Files.ViewModels;
using Files.Views;
using Microsoft.Toolkit.Uwp;
using Newtonsoft.Json;
using System;
Expand All @@ -12,6 +12,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI.Xaml;
Expand Down Expand Up @@ -96,7 +97,7 @@ public async void AddItem(string item)

public async Task ShowHideRecycleBinItemAsync(bool show)
{
await MainPage.SideBarItemsSemaphore.WaitAsync();
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
try
{
if (show)
Expand Down Expand Up @@ -129,7 +130,7 @@ public async Task ShowHideRecycleBinItemAsync(bool show)
}
finally
{
MainPage.SideBarItemsSemaphore.Release();
SidebarControl.SideBarItemsSemaphore.Release();
}
}

Expand Down Expand Up @@ -303,10 +304,10 @@ private void AddItemToSidebarAsync(LocationItem section)
/// </summary>
public async Task AddAllItemsToSidebar()
{
await MainPage.SideBarItemsSemaphore.WaitAsync();
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
try
{
MainPage.SideBarItems.BeginBulkOperation();
SidebarControl.SideBarItems.BeginBulkOperation();

if (homeSection != null)
{
Expand All @@ -319,16 +320,16 @@ public async Task AddAllItemsToSidebar()
await AddItemToSidebarAsync(path);
}

if (!MainPage.SideBarItems.Contains(favoriteSection))
if (!SidebarControl.SideBarItems.Contains(favoriteSection))
{
MainPage.SideBarItems.Add(favoriteSection);
SidebarControl.SideBarItems.Add(favoriteSection);
}

MainPage.SideBarItems.EndBulkOperation();
SidebarControl.SideBarItems.EndBulkOperation();
}
finally
{
MainPage.SideBarItemsSemaphore.Release();
SidebarControl.SideBarItemsSemaphore.Release();
}

await ShowHideRecycleBinItemAsync(App.AppSettings.PinRecycleBinToSideBar);
Expand Down
9 changes: 5 additions & 4 deletions Files/Dialogs/ExceptionDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Files.Views;
using Files.ViewModels;
using Files.Views;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand All @@ -20,13 +21,13 @@ public ExceptionDialog()

private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
if (MainPage.MultitaskingControl.Items.Count == 1)
if (MainPageViewModel.MultitaskingControl.Items.Count == 1)
{
App.CloseApp();
}
else if (MainPage.MultitaskingControl.Items.Count > 1)
else if (MainPageViewModel.MultitaskingControl.Items.Count > 1)
{
MainPage.MultitaskingControl.RemoveTab(MainPage.MultitaskingControl.Items.ElementAt(App.InteractionViewModel.TabStripSelectedIndex));
MainPageViewModel.MultitaskingControl?.CloseTab(MainPageViewModel.MultitaskingControl.Items.ElementAt(App.InteractionViewModel.TabStripSelectedIndex));
}
}

Expand Down
4 changes: 3 additions & 1 deletion Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<Compile Include="UserControls\RestartControl.xaml.cs">
<DependentUpon>RestartControl.xaml</DependentUpon>
</Compile>
<Compile Include="Helpers\DeviceHelpers.cs" />
<Compile Include="Helpers\DriveHelpers.cs" />
<Compile Include="Helpers\ExternalResourcesHelper.cs" />
<Compile Include="Helpers\GlyphHelper.cs" />
<Compile Include="Helpers\FileThumbnailHelper.cs" />
Expand All @@ -236,6 +236,7 @@
<Compile Include="Helpers\ExtensionManager.cs" />
<Compile Include="Helpers\IntervalSampler.cs" />
<Compile Include="Helpers\QuickLookHelpers.cs" />
<Compile Include="Helpers\MultitaskingTabsHelpers.cs" />
<Compile Include="Helpers\RegistryHelper.cs" />
<Compile Include="Helpers\SidebarHelpers.cs" />
<Compile Include="Helpers\XamlHelpers\DependencyObjectHelpers.cs" />
Expand Down Expand Up @@ -290,6 +291,7 @@
<Compile Include="ViewModels\Bundles\BundlesViewModel.cs" />
<Compile Include="ViewModels\Dialogs\DynamicDialogViewModel.cs" />
<Compile Include="ViewModels\FolderSettingsViewModel.cs" />
<Compile Include="ViewModels\MainPageViewModel.cs" />
<Compile Include="ViewModels\PreviewPaneViewModel.cs" />
<Compile Include="ViewModels\Previews\BasePreviewModel.cs" />
<Compile Include="ViewModels\Previews\BasicPreviewViewModel.cs" />
Expand Down
14 changes: 7 additions & 7 deletions Files/Filesystem/CloudDrivesManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Files.Filesystem.Cloud;
using Files.Views;
using Files.UserControls;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Uwp;
using NLog;
Expand Down Expand Up @@ -84,12 +84,12 @@ private async Task SyncSideBarItemsUI()
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await MainPage.SideBarItemsSemaphore.WaitAsync();
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
try
{
MainPage.SideBarItems.BeginBulkOperation();
SidebarControl.SideBarItems.BeginBulkOperation();

var section = MainPage.SideBarItems.FirstOrDefault(x => x.Text == "SidebarCloudDrives".GetLocalized()) as LocationItem;
var section = SidebarControl.SideBarItems.FirstOrDefault(x => x.Text == "SidebarCloudDrives".GetLocalized()) as LocationItem;
if (section == null)
{
section = new LocationItem()
Expand All @@ -100,7 +100,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
SelectsOnInvoked = false,
ChildItems = new ObservableCollection<INavigationControlItem>()
};
MainPage.SideBarItems.Add(section);
SidebarControl.SideBarItems.Add(section);
}

foreach (DriveItem drive in Drives.ToList())
Expand All @@ -111,11 +111,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
}
}

MainPage.SideBarItems.EndBulkOperation();
SidebarControl.SideBarItems.EndBulkOperation();
}
finally
{
MainPage.SideBarItemsSemaphore.Release();
SidebarControl.SideBarItemsSemaphore.Release();
}
});
}
Expand Down
14 changes: 7 additions & 7 deletions Files/Filesystem/Drives.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Files.Common;
using Files.Enums;
using Files.UserControls;
using Files.UserControls.Widgets;
using Files.Views;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Uwp;
using Microsoft.Toolkit.Uwp.Helpers;
Expand Down Expand Up @@ -122,12 +122,12 @@ private async Task SyncSideBarItemsUI()
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await MainPage.SideBarItemsSemaphore.WaitAsync();
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
try
{
MainPage.SideBarItems.BeginBulkOperation();
SidebarControl.SideBarItems.BeginBulkOperation();

var section = MainPage.SideBarItems.FirstOrDefault(x => x.Text == "SidebarDrives".GetLocalized()) as LocationItem;
var section = SidebarControl.SideBarItems.FirstOrDefault(x => x.Text == "SidebarDrives".GetLocalized()) as LocationItem;
if (section == null)
{
section = new LocationItem()
Expand All @@ -138,7 +138,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
SelectsOnInvoked = false,
ChildItems = new ObservableCollection<INavigationControlItem>()
};
MainPage.SideBarItems.Add(section);
SidebarControl.SideBarItems.Add(section);
}

foreach (DriveItem drive in Drives.ToList())
Expand All @@ -163,11 +163,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
}
}

MainPage.SideBarItems.EndBulkOperation();
SidebarControl.SideBarItems.EndBulkOperation();
}
finally
{
MainPage.SideBarItemsSemaphore.Release();
SidebarControl.SideBarItemsSemaphore.Release();
}
});
}
Expand Down
24 changes: 12 additions & 12 deletions Files/Filesystem/LibraryManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Files.Helpers;
using Files.UserControls;
using Files.ViewModels;
using Files.Views;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Uwp;
using System;
Expand Down Expand Up @@ -69,34 +69,34 @@ private async void RemoveEnumerateDrivesAsync(CoreApplicationView sender, Window

public async Task RemoveLibrarySideBarItemsUI()
{
MainPage.SideBarItems.BeginBulkOperation();
SidebarControl.SideBarItems.BeginBulkOperation();

try
{
var item = (from n in MainPage.SideBarItems where n.Text.Equals("SidebarLibraries".GetLocalized()) select n).FirstOrDefault();
var item = (from n in SidebarControl.SideBarItems where n.Text.Equals("SidebarLibraries".GetLocalized()) select n).FirstOrDefault();
if (!App.AppSettings.ShowLibrarySection && item != null)
{
MainPage.SideBarItems.Remove(item);
SidebarControl.SideBarItems.Remove(item);
}
}
catch (Exception)
{ }

MainPage.SideBarItems.EndBulkOperation();
SidebarControl.SideBarItems.EndBulkOperation();
}

private async Task SyncLibrarySideBarItemsUI()
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await MainPage.SideBarItemsSemaphore.WaitAsync();
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
try
{
MainPage.SideBarItems.BeginBulkOperation();
SidebarControl.SideBarItems.BeginBulkOperation();

try
{
if (App.AppSettings.ShowLibrarySection && !MainPage.SideBarItems.Contains(librarySection))
if (App.AppSettings.ShowLibrarySection && !SidebarControl.SideBarItems.Contains(librarySection))
{
librarySection = new LocationItem()
{
Expand All @@ -107,8 +107,8 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
SelectsOnInvoked = false,
ChildItems = new ObservableCollection<INavigationControlItem>()
};

MainPage.SideBarItems.Insert(1, librarySection);
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
SidebarControl.SideBarItems.Insert(1, librarySection);

libraryItems.Clear();
libraryItems.Add(AppSettings.DocumentsPath);
Expand Down Expand Up @@ -144,11 +144,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
{
}

MainPage.SideBarItems.EndBulkOperation();
SidebarControl.SideBarItems.EndBulkOperation();
}
finally
{
MainPage.SideBarItemsSemaphore.Release();
SidebarControl.SideBarItemsSemaphore.Release();
}
});
}
Expand Down
14 changes: 7 additions & 7 deletions Files/Filesystem/NetworkDrivesManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Files.Helpers;
using Files.Views;
using Files.UserControls;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Uwp;
using NLog;
Expand Down Expand Up @@ -107,12 +107,12 @@ private async Task SyncSideBarItemsUI()
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await MainPage.SideBarItemsSemaphore.WaitAsync();
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
try
{
MainPage.SideBarItems.BeginBulkOperation();
SidebarControl.SideBarItems.BeginBulkOperation();

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

if (section != null)
Expand All @@ -139,11 +139,11 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
}
}

MainPage.SideBarItems.EndBulkOperation();
SidebarControl.SideBarItems.EndBulkOperation();
}
finally
{
MainPage.SideBarItemsSemaphore.Release();
SidebarControl.SideBarItemsSemaphore.Release();
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion Files/Filesystem/StorageFileHelpers/StorageFileExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Files.Common;
using Files.Extensions;
using Files.UserControls;
using Files.ViewModels;
using Files.Views;
using System;
Expand Down Expand Up @@ -29,7 +30,7 @@ private static PathBoxItem GetPathItem(string component, string path)
}
else if (component.Contains(":"))
{
var allDrives = MainPage.SideBarItems.Where(x => (x as LocationItem)?.ChildItems != null).SelectMany(x => (x as LocationItem).ChildItems);
var allDrives = SidebarControl.SideBarItems.Where(x => (x as LocationItem)?.ChildItems != null).SelectMany(x => (x as LocationItem).ChildItems);
return new PathBoxItem()
{
Title = allDrives.FirstOrDefault(y => y.ItemType == NavigationControlItemType.Drive && y.Path.Contains(component, StringComparison.OrdinalIgnoreCase)) != null ?
Expand Down
Loading