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 2 of removing the Interaction class #4189

Merged
merged 10 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from 9 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
65 changes: 60 additions & 5 deletions Files/BaseLayout.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Files.Common;
using Files.DataModels;
using Files.Dialogs;
using Files.Enums;
using Files.EventArguments;
using Files.Extensions;
using Files.Filesystem;
Expand All @@ -8,6 +10,7 @@
using Files.UserControls;
using Files.ViewModels;
using Files.Views;
using Microsoft.Toolkit.Mvvm.Input;
using Microsoft.Toolkit.Uwp;
using Microsoft.Toolkit.Uwp.UI;
using Newtonsoft.Json;
Expand Down Expand Up @@ -85,6 +88,58 @@ internal set
}
}

private string jumpString = string.Empty;

public string JumpString
{
get => jumpString;
set
{
// If current string is "a", and the next character typed is "a",
// search for next file that starts with "a" (a.k.a. _jumpString = "a")
if (jumpString.Length == 1 && value == jumpString + jumpString)
{
value = jumpString;
}
if (value != string.Empty)
{
ListedItem jumpedToItem = null;
ListedItem previouslySelectedItem = null;

// Use FilesAndFolders because only displayed entries should be jumped to
IEnumerable<ListedItem> candidateItems = ParentShellPageInstance.FilesystemViewModel.FilesAndFolders.Where(f => f.ItemName.Length >= value.Length && f.ItemName.Substring(0, value.Length).ToLower() == value);

if (IsItemSelected)
{
previouslySelectedItem = SelectedItem;
}

// If the user is trying to cycle through items
// starting with the same letter
if (value.Length == 1 && previouslySelectedItem != null)
{
// Try to select item lexicographically bigger than the previous item
jumpedToItem = candidateItems.FirstOrDefault(f => f.ItemName.CompareTo(previouslySelectedItem.ItemName) > 0);
}
if (jumpedToItem == null)
{
jumpedToItem = candidateItems.FirstOrDefault();
}

if (jumpedToItem != null)
{
SetSelectedItemOnUi(jumpedToItem);
ScrollIntoView(jumpedToItem);
}

// Reset
jumpString = "";
return;
}
jumpString = value;
}
}

private List<ListedItem> selectedItems = new List<ListedItem>();

public List<ListedItem> SelectedItems
Expand Down Expand Up @@ -611,7 +666,7 @@ public void RightClickContextMenu_Opening(object sender, object e)
Tag = "CreateNewFile"
};
}
menuLayoutItem.Command = ParentShellPageInstance.InteractionOperations.CreateNewFile;
menuLayoutItem.Command = new RelayCommand(() => UIFilesystemHelpers.CreateFileFromDialogResultType(AddItemType.File, null, ParentShellPageInstance));
menuLayoutItem.CommandParameter = newEntry;
newItemMenu.Items.Insert(separatorIndex + 1, menuLayoutItem);
}
Expand Down Expand Up @@ -820,8 +875,8 @@ protected virtual void Page_CharacterReceived(CoreWindow sender, CharacterReceiv
{
if (ParentShellPageInstance.IsCurrentInstance)
{
char letterPressed = Convert.ToChar(args.KeyCode);
ParentShellPageInstance.InteractionOperations.PushJumpChar(letterPressed);
char letter = Convert.ToChar(args.KeyCode);
JumpString += letter.ToString().ToLowerInvariant();
}
}

Expand Down Expand Up @@ -888,7 +943,7 @@ protected async void List_Drop(object sender, DragEventArgs e)

if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
await ParentShellPageInstance.InteractionOperations.FilesystemHelpers.PerformOperationTypeAsync(e.AcceptedOperation, e.DataView, ParentShellPageInstance.FilesystemViewModel.WorkingDirectory, true);
await ParentShellPageInstance.FilesystemHelpers.PerformOperationTypeAsync(e.AcceptedOperation, e.DataView, ParentShellPageInstance.FilesystemViewModel.WorkingDirectory, true);
e.Handled = true;
}

Expand Down Expand Up @@ -963,7 +1018,7 @@ protected async void Item_DragOver(object sender, DragEventArgs e)
{
dragOverItem = null;
dragOverTimer.Stop();
ParentShellPageInstance.InteractionOperations.OpenSelectedItems(false);
NavigationHelpers.OpenSelectedItems(ParentShellPageInstance, false);
}
}, TimeSpan.FromMilliseconds(1000), false);
}
Expand Down
7 changes: 6 additions & 1 deletion Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@
<Compile Include="Dialogs\ConfirmDeleteDialog.xaml.cs">
<DependentUpon>ConfirmDeleteDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Helpers\FilePropertiesHelpers.cs" />
<Compile Include="Helpers\UIFilesystemHelpers.cs" />
<Compile Include="Helpers\NavigationHelpers.cs" />
<Compile Include="Helpers\UIHelpers.cs" />
<Compile Include="Helpers\WallpaperHelpers.cs" />
<Compile Include="Helpers\Win32Helpers.cs" />
<Compile Include="UserControls\RestartControl.xaml.cs">
<DependentUpon>RestartControl.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -448,7 +454,6 @@
<Compile Include="ViewModels\InteractionViewModel.cs" />
<Compile Include="ViewModels\DirectoryPropertiesViewModel.cs" />
<Compile Include="ViewModels\SelectedItemsPropertiesViewModel.cs" />
<Compile Include="Interacts\Interaction.cs" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FINALLY!!!

<Compile Include="IShellPage.cs" />
<Compile Include="Views\LayoutModes\GridViewBrowser.xaml.cs">
<DependentUpon>GridViewBrowser.xaml</DependentUpon>
Expand Down
10 changes: 5 additions & 5 deletions Files/Filesystem/FilesystemOperations/FilesystemOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ await DialogDisplayHelper.ShowDialogAsync(
CloseButtonText = "ItemAlreadyExistsDialogCloseButtonText".GetLocalized()
};

if (Interacts.Interaction.IsAnyContentDialogOpen())
if (UIHelpers.IsAnyContentDialogOpen())
{
// Only a single ContentDialog can be open at any time.
return null;
Expand Down Expand Up @@ -249,7 +249,7 @@ await DialogDisplayHelper.ShowDialogAsync(
CloseButtonText = "ItemAlreadyExistsDialogCloseButtonText".GetLocalized()
};

if (Interacts.Interaction.IsAnyContentDialogOpen())
if (UIHelpers.IsAnyContentDialogOpen())
{
// Only a single ContentDialog can be open at any time.
return null;
Expand Down Expand Up @@ -411,7 +411,7 @@ await DialogDisplayHelper.ShowDialogAsync(
CloseButtonText = "ItemAlreadyExistsDialogCloseButtonText".GetLocalized()
};

if (Interacts.Interaction.IsAnyContentDialogOpen())
if (UIHelpers.IsAnyContentDialogOpen())
{
// Only a single ContentDialog can be open at any time.
return null;
Expand Down Expand Up @@ -474,7 +474,7 @@ await DialogDisplayHelper.ShowDialogAsync(
CloseButtonText = "ItemAlreadyExistsDialogCloseButtonText".GetLocalized()
};

if (Interacts.Interaction.IsAnyContentDialogOpen())
if (UIHelpers.IsAnyContentDialogOpen())
{
// Only a single ContentDialog can be open at any time.
return null;
Expand Down Expand Up @@ -754,7 +754,7 @@ public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source,
CloseButtonText = "ItemAlreadyExistsDialogCloseButtonText".GetLocalized()
};

if (Interacts.Interaction.IsAnyContentDialogOpen())
if (UIHelpers.IsAnyContentDialogOpen())
{
// Only a single ContentDialog can be open at any time.
return null;
Expand Down
21 changes: 18 additions & 3 deletions Files/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation.Collections;
using Windows.Storage;
using static Files.Helpers.NativeFindStorageItemHelper;
using FileAttributes = System.IO.FileAttributes;
Expand Down Expand Up @@ -119,7 +120,7 @@ public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPat
!deleteFromRecycleBin ? permanently : deleteFromRecycleBin,
associatedInstance.SlimContentPage.SelectedItems.Count);

if (Interacts.Interaction.IsAnyContentDialogOpen())
if (UIHelpers.IsAnyContentDialogOpen())
{
// Can show only one dialog at a time
banner.Remove();
Expand Down Expand Up @@ -223,7 +224,7 @@ public async Task<ReturnResult> DeleteItemAsync(IStorageItemWithPath source, boo
permanently,
associatedInstance.SlimContentPage.SelectedItems.Count);

if (Interacts.Interaction.IsAnyContentDialogOpen())
if (UIHelpers.IsAnyContentDialogOpen())
{
// Can show only one dialog at a time
banner.Remove();
Expand Down Expand Up @@ -301,7 +302,7 @@ public async Task<ReturnResult> DeleteItemAsync(IStorageItem source, bool showDi
permanently,
associatedInstance.SlimContentPage.SelectedItems.Count);

if (Interacts.Interaction.IsAnyContentDialogOpen())
if (UIHelpers.IsAnyContentDialogOpen())
{
// Can show only one dialog at a time
banner.Remove();
Expand Down Expand Up @@ -925,6 +926,20 @@ public static bool ContainsRestrictedFileName(string input)
return false;
}

public async Task OpenShellCommandInExplorerAsync(string shellCommand, NamedPipeAsAppServiceConnection serviceConnection)
{
Debug.WriteLine("Launching shell command in FullTrustProcess");
if (serviceConnection != null)
{
ValueSet value = new ValueSet()
{
{ "ShellCommand", shellCommand },
{ "Arguments", "ShellCommand" }
};
await serviceConnection.SendMessageAsync(value);
}
}

#endregion Public Helpers

#region IDisposable
Expand Down
100 changes: 100 additions & 0 deletions Files/Helpers/FilePropertiesHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using Files.Dialogs;
using Files.Views;
using Microsoft.Toolkit.Uwp;
using System;
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Foundation.Metadata;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;
using static Files.Views.Properties;

namespace Files.Helpers
{
public static class FilePropertiesHelpers
{
public static async void ShowProperties(IShellPage associatedInstance)
{
if (associatedInstance.SlimContentPage.IsItemSelected)
{
if (associatedInstance.SlimContentPage.SelectedItems.Count > 1)
{
await OpenPropertiesWindowAsync(associatedInstance.SlimContentPage.SelectedItems, associatedInstance);
}
else
{
await OpenPropertiesWindowAsync(associatedInstance.SlimContentPage.SelectedItem, associatedInstance);
}
}
else
{
if (!System.IO.Path.GetPathRoot(associatedInstance.FilesystemViewModel.CurrentFolder.ItemPath)
.Equals(associatedInstance.FilesystemViewModel.CurrentFolder.ItemPath, StringComparison.OrdinalIgnoreCase))
{
await OpenPropertiesWindowAsync(associatedInstance.FilesystemViewModel.CurrentFolder, associatedInstance);
}
else
{
await OpenPropertiesWindowAsync(App.DrivesManager.Drives
.SingleOrDefault(x => x.Path.Equals(associatedInstance.FilesystemViewModel.CurrentFolder.ItemPath)), associatedInstance);
}
}
}

public static async Task OpenPropertiesWindowAsync(object item, IShellPage associatedInstance)
{
if (item == null)
{
return;
}

if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
{
CoreApplicationView newWindow = CoreApplication.CreateNewView();
ApplicationView newView = null;

await newWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
frame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
{
Item = item,
AppInstanceArgument = associatedInstance
}, new SuppressNavigationTransitionInfo());
Window.Current.Content = frame;
Window.Current.Activate();

newView = ApplicationView.GetForCurrentView();
newWindow.TitleBar.ExtendViewIntoTitleBar = true;
newView.Title = "PropertiesTitle".GetLocalized();
newView.PersistedStateId = "Properties";
newView.SetPreferredMinSize(new Size(400, 550));
newView.Consolidated += delegate
{
Window.Current.Close();
};
});

bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newView.Id);
// Set window size again here as sometimes it's not resized in the page Loaded event
newView.TryResizeView(new Size(400, 550));
}
else
{
var propertiesDialog = new PropertiesDialog();
propertiesDialog.propertiesFrame.Tag = propertiesDialog;
propertiesDialog.propertiesFrame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
{
Item = item,
AppInstanceArgument = associatedInstance
}, new SuppressNavigationTransitionInfo());
await propertiesDialog.ShowAsync(ContentDialogPlacement.Popup);
}
}
}
}
Loading