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

[Farewell, Interaction]: Step 1 of removing the Interaction class #4016

Merged
merged 13 commits into from
Mar 20, 2021
22 changes: 15 additions & 7 deletions Files/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Files.Extensions;
using Files.Filesystem;
using Files.Helpers;
using Files.Interacts;
using Files.UserControls;
using Files.ViewModels;
using Files.Views;
Expand Down Expand Up @@ -37,9 +38,9 @@ namespace Files
/// <summary>
/// The base class which every layout page must derive from
/// </summary>
public abstract class BaseLayout : Page, INotifyPropertyChanged
public abstract class BaseLayout : Page, IBaseLayout, INotifyPropertyChanged
{
private NamedPipeAsAppServiceConnection Connection => ParentShellPageInstance?.ServiceConnection;
protected NamedPipeAsAppServiceConnection Connection => ParentShellPageInstance?.ServiceConnection;

public SelectedItemsPropertiesViewModel SelectedItemsPropertiesViewModel { get; }

Expand All @@ -59,6 +60,8 @@ public abstract class BaseLayout : Page, INotifyPropertyChanged

public MenuFlyout BaseLayoutItemContextFlyout { get; set; }

public BaseLayoutCommandsViewModel CommandsViewModel { get; protected set; }

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

public bool IsRenamingItem { get; set; } = false;
Expand Down Expand Up @@ -172,6 +175,8 @@ public BaseLayout()
dragOverTimer = timerQueue.CreateTimer();
}

protected abstract void InitializeCommandsViewModel();

public abstract void FocusFileList();

public abstract void SelectAllItems();
Expand Down Expand Up @@ -297,7 +302,7 @@ public virtual void SetItemOpacity(ListedItem item)

private void FolderSettings_LayoutModeChangeRequested(object sender, LayoutModeEventArgs e)
{
if (ParentShellPageInstance.ContentPage != null)
if (ParentShellPageInstance.SlimContentPage != null)
{
var layoutType = FolderSettings.GetLayoutType(ParentShellPageInstance.FilesystemViewModel.WorkingDirectory);

Expand Down Expand Up @@ -334,6 +339,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
Window.Current.CoreWindow.CharacterReceived += Page_CharacterReceived;
navigationArguments = (NavigationArguments)eventArgs.Parameter;
ParentShellPageInstance = navigationArguments.AssociatedTabInstance;
InitializeCommandsViewModel();
IsItemSelected = false;
FolderSettings.LayoutModeChangeRequested += FolderSettings_LayoutModeChangeRequested;
ParentShellPageInstance.FilesystemViewModel.IsFolderEmptyTextDisplayed = false;
Expand Down Expand Up @@ -793,7 +799,7 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
}

//check the file extension of the selected item
ParentShellPageInstance.ContentPage.SelectedItemsPropertiesViewModel.CheckFileExtension();
SelectedItemsPropertiesViewModel.CheckFileExtension();
}

protected virtual void Page_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
Expand Down Expand Up @@ -879,7 +885,7 @@ protected async void Item_DragStarting(object sender, DragStartingEventArgs e)
{
List<IStorageItem> selectedStorageItems = new List<IStorageItem>();

foreach (ListedItem item in ParentShellPageInstance.ContentPage.SelectedItems)
foreach (ListedItem item in ParentShellPageInstance.SlimContentPage.SelectedItems)
{
if (item is ShortcutItem)
{
Expand Down Expand Up @@ -943,7 +949,7 @@ protected async void Item_DragOver(object sender, DragEventArgs e)
{
dragOverItem = null;
dragOverTimer.Stop();
ParentShellPageInstance.InteractionOperations.OpenItem_Click(null, null);
ParentShellPageInstance.InteractionOperations.OpenSelectedItems(false);
}
}, TimeSpan.FromMilliseconds(1000), false);
}
Expand Down Expand Up @@ -1002,7 +1008,7 @@ protected async void Item_Drop(object sender, DragEventArgs e)
ListedItem rowItem = GetItemFromElement(sender);
if (rowItem != null)
{
await ParentShellPageInstance.InteractionOperations.FilesystemHelpers.PerformOperationTypeAsync(e.AcceptedOperation, e.DataView, (rowItem as ShortcutItem)?.TargetPath ?? rowItem.ItemPath, true);
await ParentShellPageInstance.FilesystemHelpers.PerformOperationTypeAsync(e.AcceptedOperation, e.DataView, (rowItem as ShortcutItem)?.TargetPath ?? rowItem.ItemPath, true);
}
deferral.Complete();
}
Expand Down Expand Up @@ -1076,5 +1082,7 @@ public void BaseLayout_PointerWheelChanged(object sender, PointerRoutedEventArgs
e.Handled = true;
}
}

public abstract void Dispose();
}
}
9 changes: 3 additions & 6 deletions Files/Dialogs/ConfirmDeleteDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,29 @@ public enum DialogResult

public sealed partial class ConfirmDeleteDialog : ContentDialog
{
private SelectedItemsPropertiesViewModel SelectedItemsPropertiesViewModel { get; set; } = null;

public bool PermanentlyDelete { get; set; }

public string Description { get; set; }

public DialogResult Result { get; set; }

public ConfirmDeleteDialog(bool deleteFromRecycleBin, bool permanently, SelectedItemsPropertiesViewModel propertiesViewModel)
public ConfirmDeleteDialog(bool deleteFromRecycleBin, bool permanently, int itemsSelected)
{
this.InitializeComponent();

Result = DialogResult.Nothing; //clear the result in case the value is set from last time
PermanentlyDelete = permanently;
SelectedItemsPropertiesViewModel = propertiesViewModel;

// If deleting from recycle bin disable "permanently delete" option
chkPermanentlyDelete.IsEnabled = !deleteFromRecycleBin;

if (SelectedItemsPropertiesViewModel.SelectedItemsCount == 1)
if (itemsSelected == 1)
{
Description = "ConfirmDeleteDialogDeleteOneItem/Text".GetLocalized();
}
else
{
Description = string.Format("ConfirmDeleteDialogDeleteMultipleItems/Text".GetLocalized(), SelectedItemsPropertiesViewModel.SelectedItemsCount);
Description = string.Format("ConfirmDeleteDialogDeleteMultipleItems/Text".GetLocalized(), itemsSelected);
}
}

Expand Down
17 changes: 17 additions & 0 deletions Files/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Reflection;

namespace Files.Extensions
{
public static class EnumExtensions
{
public static TEnum GetEnum<TEnum>(string text) where TEnum : struct
{
if (!typeof(TEnum).GetTypeInfo().IsEnum)
{
throw new InvalidOperationException("Generic parameter 'TEnum' must be an enum.");
}
return (TEnum)Enum.Parse(typeof(TEnum), text);
}
}
}
7 changes: 7 additions & 0 deletions Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<Compile Include="Enums\FolderLayout.cs" />
<Compile Include="Enums\FolderLayoutModes.cs" />
<Compile Include="EventArguments\LayoutPreferenceEventArgs.cs" />
<Compile Include="Extensions\EnumExtensions.cs" />
<Compile Include="Extensions\TaskExtensions.cs" />
<Compile Include="Filesystem\FolderHelpers.cs" />
<Compile Include="Filesystem\LibraryManager.cs" />
Expand Down Expand Up @@ -228,9 +229,15 @@
<Compile Include="Helpers\FileListCache\PersistentSQLiteCacheAdapter.cs" />
<Compile Include="Helpers\ExtensionManager.cs" />
<Compile Include="Helpers\IntervalSampler.cs" />
<Compile Include="Helpers\QuickLookHelpers.cs" />
<Compile Include="Helpers\RegistryHelper.cs" />
<Compile Include="Helpers\SidebarHelpers.cs" />
<Compile Include="Helpers\XamlHelpers\DependencyObjectHelpers.cs" />
<Compile Include="Helpers\XamlHelpers\SystemTypeToXaml.cs" />
<Compile Include="IBaseLayout.cs" />
<Compile Include="Interacts\BaseLayoutCommandImplementationModel.cs" />
<Compile Include="Interacts\BaseLayoutCommandsViewModel.cs" />
<Compile Include="Interacts\IBaseLayoutCommandImplementationModel.cs" />
<Compile Include="Interacts\IStatusCenterActions.cs" />
<Compile Include="UserControls\FilePreviews\BasicPreview.xaml.cs">
<DependentUpon>BasicPreview.xaml</DependentUpon>
Expand Down
8 changes: 4 additions & 4 deletions Files/Filesystem/FilesystemOperations/FilesystemOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ await DialogDisplayHelper.ShowDialogAsync(

if (copiedListedItems.Count > 0)
{
associatedInstance.ContentPage.AddSelectedItemsOnUi(copiedListedItems);
associatedInstance.ContentPage.FocusSelectedItems();
associatedInstance.SlimContentPage.AddSelectedItemsOnUi(copiedListedItems);
associatedInstance.SlimContentPage.FocusSelectedItems();
}
}, Windows.UI.Core.CoreDispatcherPriority.Low);
}
Expand Down Expand Up @@ -515,8 +515,8 @@ await DialogDisplayHelper.ShowDialogAsync(

if (movedListedItems.Count > 0)
{
associatedInstance.ContentPage.AddSelectedItemsOnUi(movedListedItems);
associatedInstance.ContentPage.FocusSelectedItems();
associatedInstance.SlimContentPage.AddSelectedItemsOnUi(movedListedItems);
associatedInstance.SlimContentPage.FocusSelectedItems();
}
}, Windows.UI.Core.CoreDispatcherPriority.Low);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPat
ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(
deleteFromRecycleBin,
!deleteFromRecycleBin ? permanently : deleteFromRecycleBin,
associatedInstance.ContentPage.SelectedItemsPropertiesViewModel);
associatedInstance.SlimContentPage.SelectedItems.Count);

if (Interacts.Interaction.IsAnyContentDialogOpen())
{
Expand Down Expand Up @@ -221,7 +221,7 @@ public async Task<ReturnResult> DeleteItemAsync(IStorageItemWithPath source, boo
ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(
deleteFromRecycleBin,
permanently,
associatedInstance.ContentPage.SelectedItemsPropertiesViewModel);
associatedInstance.SlimContentPage.SelectedItems.Count);

if (Interacts.Interaction.IsAnyContentDialogOpen())
{
Expand Down Expand Up @@ -299,7 +299,7 @@ public async Task<ReturnResult> DeleteItemAsync(IStorageItem source, bool showDi
ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(
deleteFromRecycleBin,
permanently,
associatedInstance.ContentPage.SelectedItemsPropertiesViewModel);
associatedInstance.SlimContentPage.SelectedItems.Count);

if (Interacts.Interaction.IsAnyContentDialogOpen())
{
Expand Down Expand Up @@ -424,7 +424,7 @@ public async Task<ReturnResult> CopyItemsAsync(IEnumerable<IStorageItemWithPath>
IStorageHistory history;
List<IStorageHistory> rawStorageHistory = new List<IStorageHistory>();

associatedInstance.ContentPage.ClearSelection();
associatedInstance.SlimContentPage.ClearSelection();
float progress;
for (int i = 0; i < source.Count(); i++)
{
Expand Down Expand Up @@ -483,7 +483,7 @@ public async Task<ReturnResult> CopyItemAsync(IStorageItemWithPath source, strin
var sw = new Stopwatch();
sw.Start();

associatedInstance.ContentPage.ClearSelection();
associatedInstance.SlimContentPage.ClearSelection();
IStorageHistory history = await filesystemOperations.CopyAsync(source, destination, banner.Progress, banner.ErrorCode, cancellationToken);
((IProgress<float>)banner.Progress).Report(100.0f);

Expand Down Expand Up @@ -596,7 +596,7 @@ public async Task<ReturnResult> MoveItemsAsync(IEnumerable<IStorageItemWithPath>
IStorageHistory history;
var rawStorageHistory = new List<IStorageHistory>();

associatedInstance.ContentPage.ClearSelection();
associatedInstance.SlimContentPage.ClearSelection();
float progress;
for (int i = 0; i < source.Count(); i++)
{
Expand Down Expand Up @@ -655,7 +655,7 @@ public async Task<ReturnResult> MoveItemAsync(IStorageItemWithPath source, strin
var sw = new Stopwatch();
sw.Start();

associatedInstance.ContentPage.ClearSelection();
associatedInstance.SlimContentPage.ClearSelection();
IStorageHistory history = await filesystemOperations.MoveAsync(source, destination, banner.Progress, banner.ErrorCode, cancellationToken);
((IProgress<float>)banner.Progress).Report(100.0f);

Expand Down
43 changes: 43 additions & 0 deletions Files/Helpers/QuickLookHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using Microsoft.Toolkit.Uwp;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.Foundation.Collections;
using Windows.UI.Core;

namespace Files.Helpers
{
public static class QuickLookHelpers
{
public static async void ToggleQuickLook(IShellPage associatedInstance)
{
try
{
if (associatedInstance.SlimContentPage.IsItemSelected && !associatedInstance.SlimContentPage.IsRenamingItem)
{
Debug.WriteLine("Toggle QuickLook");
if (associatedInstance.ServiceConnection != null)
{
await associatedInstance.ServiceConnection.SendMessageAsync(new ValueSet()
{
{ "path", associatedInstance.SlimContentPage.SelectedItem.ItemPath },
{ "Arguments", "ToggleQuickLook" }
});
}
}
}
catch (FileNotFoundException)
{
await DialogDisplayHelper.ShowDialogAsync("FileNotFoundDialog/Title".GetLocalized(), "FileNotFoundPreviewDialog/Text".GetLocalized());
associatedInstance.NavigationToolbar.CanRefresh = false;
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
var ContentOwnedViewModelInstance = associatedInstance.FilesystemViewModel;
ContentOwnedViewModelInstance?.RefreshItems(null);
});
}
}
}
}
32 changes: 32 additions & 0 deletions Files/Helpers/RecycleBinHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Files.Common;
using Microsoft.Toolkit.Uwp;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
Expand All @@ -8,6 +9,7 @@
using Windows.ApplicationModel.AppService;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Xaml.Controls;

namespace Files.Helpers
{
Expand Down Expand Up @@ -80,6 +82,36 @@ public bool IsPathUnderRecycleBin(string path)
return recycleBinPathRegex.IsMatch(path);
}

public static void EmptyRecycleBin(IShellPage associatedInstance)
{
new RecycleBinHelpers(associatedInstance).EmptyRecycleBin();
}

public async void EmptyRecycleBin()
{
var ConfirmEmptyBinDialog = new ContentDialog()
{
Title = "ConfirmEmptyBinDialogTitle".GetLocalized(),
Content = "ConfirmEmptyBinDialogContent".GetLocalized(),
PrimaryButtonText = "ConfirmEmptyBinDialog/PrimaryButtonText".GetLocalized(),
SecondaryButtonText = "ConfirmEmptyBinDialog/SecondaryButtonText".GetLocalized()
};

ContentDialogResult result = await ConfirmEmptyBinDialog.ShowAsync();

if (result == ContentDialogResult.Primary)
{
if (Connection != null)
{
var value = new ValueSet();
value.Add("Arguments", "RecycleBin");
value.Add("action", "Empty");
// Send request to fulltrust process to empty recyclebin
await Connection.SendMessageAsync(value);
}
}
}

#region IDisposable

public void Dispose()
Expand Down
24 changes: 24 additions & 0 deletions Files/Helpers/SidebarHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Files.Filesystem;
using System.Collections.Generic;

namespace Files.Helpers
{
public static class SidebarHelpers
{
public static void UnpinItems(List<ListedItem> itemsToUnpin)
{
foreach (var item in itemsToUnpin)
{
App.SidebarPinnedController.Model.RemoveItem(item.ItemPath);
}
}

public static void PinItems(List<ListedItem> itemsToPin)
{
foreach (ListedItem listedItem in itemsToPin)
{
App.SidebarPinnedController.Model.AddItem(listedItem.ItemPath);
}
}
}
}
5 changes: 3 additions & 2 deletions Files/Helpers/ThemeHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Files.Extensions;
using System;
using Windows.Storage;
using Windows.UI;
using Windows.UI.ViewManagement;
Expand Down Expand Up @@ -29,7 +30,7 @@ public static ElementTheme RootTheme

if (!string.IsNullOrEmpty(savedTheme))
{
return Interacts.Interaction.GetEnum<ElementTheme>(savedTheme);
return EnumExtensions.GetEnum<ElementTheme>(savedTheme);
}
else
{
Expand Down
Loading