Skip to content

Commit

Permalink
Move more commands from BaseLayout to BaseLayoutCommandsViewModel (#4218
Browse files Browse the repository at this point in the history
)
  • Loading branch information
d2dyno1 authored Mar 31, 2021
1 parent e94244e commit 8f7c27b
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 147 deletions.
121 changes: 0 additions & 121 deletions Files/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,76 +500,6 @@ protected virtual void Page_CharacterReceived(CoreWindow sender, CharacterReceiv
}
}

protected async void List_DragEnter(object sender, DragEventArgs e)
{
var deferral = e.GetDeferral();

ClearSelection();
if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
e.Handled = true;
e.DragUIOverride.IsCaptionVisible = true;
IEnumerable<IStorageItem> draggedItems = new List<IStorageItem>();
try
{
draggedItems = await e.DataView.GetStorageItemsAsync();
}
catch (Exception dropEx) when ((uint)dropEx.HResult == 0x80040064)
{
if (Connection != null)
{
await Connection.SendMessageAsync(new ValueSet() {
{ "Arguments", "FileOperation" },
{ "fileop", "DragDrop" },
{ "droptext", "DragDropWindowText".GetLocalized() },
{ "droppath", ParentShellPageInstance.FilesystemViewModel.WorkingDirectory } });
}
}
catch (Exception ex)
{
NLog.LogManager.GetCurrentClassLogger().Warn(ex, ex.Message);
}
if (!draggedItems.Any())
{
e.AcceptedOperation = DataPackageOperation.None;
deferral.Complete();
return;
}

var folderName = Path.GetFileName(ParentShellPageInstance.FilesystemViewModel.WorkingDirectory);
// As long as one file doesn't already belong to this folder
if (InstanceViewModel.IsPageTypeSearchResults || draggedItems.AreItemsAlreadyInFolder(ParentShellPageInstance.FilesystemViewModel.WorkingDirectory))
{
e.AcceptedOperation = DataPackageOperation.None;
}
else if (draggedItems.AreItemsInSameDrive(ParentShellPageInstance.FilesystemViewModel.WorkingDirectory))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), folderName);
e.AcceptedOperation = DataPackageOperation.Move;
}
else
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
}
}

deferral.Complete();
}

protected async void List_Drop(object sender, DragEventArgs e)
{
var deferral = e.GetDeferral();

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

deferral.Complete();
}

protected async void Item_DragStarting(object sender, DragStartingEventArgs e)
{
List<IStorageItem> selectedStorageItems = new List<IStorageItem>();
Expand Down Expand Up @@ -737,57 +667,6 @@ protected void UninitializeDrag(UIElement element)

public readonly VirtualKey MinusKey = (VirtualKey)189;

public void GridViewSizeIncrease(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
{
FolderSettings.GridViewSize = FolderSettings.GridViewSize + Constants.Browser.GridViewBrowser.GridViewIncrement; // Make Larger
if (args != null)
{
args.Handled = true;
}
}

public void GridViewSizeDecrease(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
{
FolderSettings.GridViewSize = FolderSettings.GridViewSize - Constants.Browser.GridViewBrowser.GridViewIncrement; // Make Smaller
if (args != null)
{
args.Handled = true;
}
}

public void BaseLayout_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
if (e.KeyModifiers == VirtualKeyModifiers.Control)
{
if (e.GetCurrentPoint(null).Properties.MouseWheelDelta < 0) // Mouse wheel down
{
GridViewSizeDecrease(null, null);
}
else // Mouse wheel up
{
GridViewSizeIncrease(null, null);
}

e.Handled = true;
}
}

public async void PinItemToStart_Click(object sender, RoutedEventArgs e)
{
foreach (ListedItem listedItem in SelectedItems)
{
await App.SecondaryTileHelper.TryPinFolderAsync(listedItem.ItemPath, listedItem.ItemName);
}
}

public async void UnpinItemFromStart_Click(object sender, RoutedEventArgs e)
{
foreach (ListedItem listedItem in SelectedItems)
{
await App.SecondaryTileHelper.UnpinFromStartAsync(listedItem.ItemPath);
}
}

public abstract void Dispose();

public void RefreshItems()
Expand Down
5 changes: 2 additions & 3 deletions Files/Helpers/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
{
Text = "PinItemToStart/Text".GetLocalized(),
Glyph = "\uE840",
// TODO: Add command
Command = commandsViewModel.PinItemToStartCommand,
ShowOnShift = true,
ShowItem = selectedItems.All(x => x.PrimaryItemAttribute == StorageItemTypes.Folder && !x.IsItemPinnedToStart),
SingleItemOnly = true,
Expand All @@ -495,7 +495,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(BaseLayo
{
Text = "UnpinItemFromStart/Text".GetLocalized(),
Glyph = "\uE77A",
// TODO: Add command
Command = commandsViewModel.UnpinItemFromStartCommand,
ShowOnShift = true,
ShowItem = selectedItems.All(x => x.PrimaryItemAttribute == StorageItemTypes.Folder && x.IsItemPinnedToStart),
SingleItemOnly = true,
Expand Down Expand Up @@ -569,4 +569,3 @@ public static List<ContextMenuFlyoutItemViewModel> GetNewItemItems(BaseLayoutCom
}
}
}

123 changes: 123 additions & 0 deletions Files/Interacts/BaseLayoutCommandImplementationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,129 @@ public virtual void ItemPointerPressed(PointerRoutedEventArgs e)
}
}

public virtual async void UnpinItemFromStart(RoutedEventArgs e)
{
foreach (ListedItem listedItem in associatedInstance.SlimContentPage.SelectedItems)
{
await App.SecondaryTileHelper.UnpinFromStartAsync(listedItem.ItemPath);
}
}

public async void PinItemToStart(RoutedEventArgs e)
{
foreach (ListedItem listedItem in associatedInstance.SlimContentPage.SelectedItems)
{
await App.SecondaryTileHelper.TryPinFolderAsync(listedItem.ItemPath, listedItem.ItemName);
}
}

public virtual void PointerWheelChanged(PointerRoutedEventArgs e)
{
if (e.KeyModifiers == VirtualKeyModifiers.Control)
{
if (e.GetCurrentPoint(null).Properties.MouseWheelDelta < 0) // Mouse wheel down
{
GridViewSizeDecrease(null);
}
else // Mouse wheel up
{
GridViewSizeIncrease(null);
}

e.Handled = true;
}
}

public virtual void GridViewSizeDecrease(KeyboardAcceleratorInvokedEventArgs e)
{
associatedInstance.InstanceViewModel.FolderSettings.GridViewSize = associatedInstance.InstanceViewModel.FolderSettings.GridViewSize - Constants.Browser.GridViewBrowser.GridViewIncrement; // Make Smaller

if (e != null)
{
e.Handled = true;
}
}

public virtual void GridViewSizeIncrease(KeyboardAcceleratorInvokedEventArgs e)
{
associatedInstance.InstanceViewModel.FolderSettings.GridViewSize = associatedInstance.InstanceViewModel.FolderSettings.GridViewSize + Constants.Browser.GridViewBrowser.GridViewIncrement; // Make Larger

if (e != null)
{
e.Handled = true;
}
}

public virtual async void DragEnter(DragEventArgs e)
{
var deferral = e.GetDeferral();

SlimContentPage.ClearSelection();
if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
e.Handled = true;
e.DragUIOverride.IsCaptionVisible = true;
IEnumerable<IStorageItem> draggedItems = new List<IStorageItem>();
try
{
draggedItems = await e.DataView.GetStorageItemsAsync();
}
catch (Exception dropEx) when ((uint)dropEx.HResult == 0x80040064)
{
if (associatedInstance.ServiceConnection != null)
{
await associatedInstance.ServiceConnection.SendMessageAsync(new ValueSet() {
{ "Arguments", "FileOperation" },
{ "fileop", "DragDrop" },
{ "droptext", "DragDropWindowText".GetLocalized() },
{ "droppath", associatedInstance.FilesystemViewModel.WorkingDirectory } });
}
}
catch (Exception ex)
{
NLog.LogManager.GetCurrentClassLogger().Warn(ex, ex.Message);
}
if (!draggedItems.Any())
{
e.AcceptedOperation = DataPackageOperation.None;
deferral.Complete();
return;
}

var folderName = System.IO.Path.GetFileName(associatedInstance.FilesystemViewModel.WorkingDirectory);
// As long as one file doesn't already belong to this folder
if (associatedInstance.InstanceViewModel.IsPageTypeSearchResults || draggedItems.AreItemsAlreadyInFolder(associatedInstance.FilesystemViewModel.WorkingDirectory))
{
e.AcceptedOperation = DataPackageOperation.None;
}
else if (draggedItems.AreItemsInSameDrive(associatedInstance.FilesystemViewModel.WorkingDirectory))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), folderName);
e.AcceptedOperation = DataPackageOperation.Move;
}
else
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
}
}

deferral.Complete();
}

public virtual async void Drop(DragEventArgs e)
{
var deferral = e.GetDeferral();

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

deferral.Complete();
}

public virtual void RefreshItems(RoutedEventArgs e)
{
SlimContentPage.RefreshItems();
Expand Down
22 changes: 22 additions & 0 deletions Files/Interacts/BaseLayoutCommandsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ private void InitializeCommands()
ShareItemCommand = new RelayCommand<RoutedEventArgs>(commandsModel.ShareItem);
PinDirectoryToSidebarCommand = new RelayCommand<RoutedEventArgs>(commandsModel.PinDirectoryToSidebar);
ItemPointerPressedCommand = new RelayCommand<PointerRoutedEventArgs>(commandsModel.ItemPointerPressed);
UnpinItemFromStartCommand = new RelayCommand<RoutedEventArgs>(commandsModel.UnpinItemFromStart);
PinItemToStartCommand = new RelayCommand<RoutedEventArgs>(commandsModel.PinItemToStart);
PointerWheelChangedCommand = new RelayCommand<PointerRoutedEventArgs>(commandsModel.PointerWheelChanged);
GridViewSizeDecreaseCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(commandsModel.GridViewSizeDecrease);
GridViewSizeIncreaseCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(commandsModel.GridViewSizeIncrease);
DragEnterCommand = new RelayCommand<DragEventArgs>(commandsModel.DragEnter);
DropCommand = new RelayCommand<DragEventArgs>(commandsModel.Drop);
RefreshCommand = new RelayCommand<RoutedEventArgs>(commandsModel.RefreshItems);
}

Expand Down Expand Up @@ -129,6 +136,21 @@ private void InitializeCommands()
public ICommand PinDirectoryToSidebarCommand { get; private set; }

public ICommand ItemPointerPressedCommand { get; private set; }

public ICommand UnpinItemFromStartCommand { get; private set; }

public ICommand PinItemToStartCommand { get; private set; }

public ICommand PointerWheelChangedCommand { get; private set; }

public ICommand GridViewSizeDecreaseCommand { get; private set; }

public ICommand GridViewSizeIncreaseCommand { get; private set; }

public ICommand DragEnterCommand { get; private set; }

public ICommand DropCommand { get; private set; }

public ICommand RefreshCommand { get; private set; }

#endregion Commands
Expand Down
15 changes: 15 additions & 0 deletions Files/Interacts/IBaseLayoutCommandImplementationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable
void PinDirectoryToSidebar(RoutedEventArgs e);

void ItemPointerPressed(PointerRoutedEventArgs e);

void UnpinItemFromStart(RoutedEventArgs e);

void PinItemToStart(RoutedEventArgs e);

void PointerWheelChanged(PointerRoutedEventArgs e);

void GridViewSizeDecrease(KeyboardAcceleratorInvokedEventArgs e);

void GridViewSizeIncrease(KeyboardAcceleratorInvokedEventArgs e);

void DragEnter(DragEventArgs e);

void Drop(DragEventArgs e);

void RefreshItems(RoutedEventArgs e);
}
}
Loading

0 comments on commit 8f7c27b

Please sign in to comment.