Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
heftymouse committed Mar 22, 2023
2 parents e9d1917 + 70bbb18 commit feb3663
Show file tree
Hide file tree
Showing 103 changed files with 1,711 additions and 857 deletions.
53 changes: 53 additions & 0 deletions src/Files.App/Actions/Content/QuickLook/LaunchQuickLookAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using Files.App.Shell;
using Files.Backend.Helpers;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class LaunchQuickLookAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public HotKey HotKey { get; } = new(VirtualKey.Space);

public bool IsExecutable => context.SelectedItems.Count == 1 &&
(!context.ShellPage?.ToolbarViewModel?.IsEditModeEnabled ?? false) &&
(!context.ShellPage?.SlimContentPage?.IsRenamingItem ?? false);

public string Label => "LaunchQuickLook".GetLocalizedResource();

public LaunchQuickLookAction()
{
context.PropertyChanged += Context_PropertyChanged;
}

public async Task ExecuteAsync()
{
await QuickLookHelpers.ToggleQuickLook(context.SelectedItem!.ItemPath);
}

public void Context_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.SelectedItems):
OnPropertyChanged(nameof(IsExecutable));
var _ = SwitchQuickLookPreview();
break;
}
}

private async Task SwitchQuickLookPreview()
{
if (IsExecutable)
await QuickLookHelpers.ToggleQuickLook(context.SelectedItem!.ItemPath, true);
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Actions/FileSystem/CopyItemAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task ExecuteAsync()
await UIFilesystemHelpers.CopyItem(context.ShellPage);
}

public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
OnPropertyChanged(nameof(IsExecutable));
Expand Down
43 changes: 43 additions & 0 deletions src/Files.App/Actions/FileSystem/CopyPathAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;
using Windows.System;

namespace Files.App.Actions
{
internal class CopyPathAction : IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "CopyLocation".GetLocalizedResource();

public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconCopyLocation");

public HotKey HotKey { get; } = new(VirtualKey.C, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift);

public async Task ExecuteAsync()
{
if (context.ShellPage?.SlimContentPage is not null)
{
var path = context.ShellPage.SlimContentPage.SelectedItem is not null
? context.ShellPage.SlimContentPage.SelectedItem.ItemPath
: context.ShellPage.FilesystemViewModel.WorkingDirectory;

if (FtpHelpers.IsFtpPath(path))
path = path.Replace("\\", "/", StringComparison.Ordinal);

DataPackage data = new();
data.SetText(path);

Clipboard.SetContent(data);
Clipboard.Flush();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Actions/FileSystem/CreateFolderAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Task ExecuteAsync()
return Task.CompletedTask;
}

public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
OnPropertyChanged(nameof(IsExecutable));
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Actions/FileSystem/CreateShortcutAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class CreateShortcutAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "BaseLayoutItemContextFlyoutShortcut/Text".GetLocalizedResource();
public string Label { get; } = "CreateShortcut".GetLocalizedResource();

public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconShortcut");

Expand Down Expand Up @@ -45,7 +45,7 @@ public async Task ExecuteAsync()
}
}

public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
OnPropertyChanged(nameof(IsExecutable));
Expand Down
14 changes: 0 additions & 14 deletions src/Files.App/Actions/FileSystem/CreateShortcutFromDialogAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using System.ComponentModel;
using System.Threading.Tasks;

namespace Files.App.Actions
Expand All @@ -17,23 +16,10 @@ internal class CreateShortcutFromDialogAction : ObservableObject, IAction

public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconShortcut");

public bool IsExecutable => context.HasSelection;

public CreateShortcutFromDialogAction()
{
context.PropertyChanged += Context_PropertyChanged;
}

public async Task ExecuteAsync()
{
if (context.ShellPage is not null)
await UIFilesystemHelpers.CreateShortcutFromDialogAsync(context.ShellPage);
}

public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
OnPropertyChanged(nameof(IsExecutable));
}
}
}
4 changes: 2 additions & 2 deletions src/Files.App/Actions/FileSystem/CutItemAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class CutItemAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "BaseLayoutItemContextFlyoutCut/Text".GetLocalizedResource();
public string Label { get; } = "Cut".GetLocalizedResource();

public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconCut");

Expand All @@ -34,7 +34,7 @@ public Task ExecuteAsync()
return Task.CompletedTask;
}

public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
OnPropertyChanged(nameof(IsExecutable));
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Actions/FileSystem/DeleteItemAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task ExecuteAsync()
await context.ShellPage.FilesystemViewModel.ApplyFilesAndFoldersChangesAsync();
}

public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.HasSelection))
OnPropertyChanged(nameof(IsExecutable));
Expand Down
61 changes: 61 additions & 0 deletions src/Files.App/Actions/FileSystem/PasteItemAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.DataModels;
using Files.App.Extensions;
using Files.App.Helpers;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class PasteItemAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "Paste".GetLocalizedResource();

public RichGlyph Glyph { get; } = new(opacityStyle: "ColorIconPaste");

public HotKey HotKey { get; } = new(VirtualKey.V, VirtualKeyModifiers.Control);

private bool isExecutable;
public bool IsExecutable => isExecutable;

public PasteItemAction()
{
isExecutable = GetIsExecutable();

context.PropertyChanged += Context_PropertyChanged;
App.AppModel.PropertyChanged += AppModel_PropertyChanged;
}

public async Task ExecuteAsync()
{
if (context.ShellPage is null)
return;

string path = context.ShellPage.FilesystemViewModel.WorkingDirectory;
await UIFilesystemHelpers.PasteItemAsync(path, context.ShellPage);
}

public bool GetIsExecutable()
{
return App.AppModel.IsPasteEnabled
&& context.PageType is not ContentPageTypes.Home and not ContentPageTypes.RecycleBin and not ContentPageTypes.SearchResults;
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.PageType))
SetProperty(ref isExecutable, GetIsExecutable(), nameof(IsExecutable));
}
private void AppModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(AppModel.IsPasteEnabled))
SetProperty(ref isExecutable, GetIsExecutable(), nameof(IsExecutable));
}
}
}
75 changes: 75 additions & 0 deletions src/Files.App/Actions/FileSystem/PasteItemToSelectionAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.DataModels;
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Helpers;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class PasteItemToSelectionAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label { get; } = "Paste".GetLocalizedResource();

public RichGlyph Glyph { get; } = new(opacityStyle: "ColorIconPaste");

public HotKey HotKey { get; } = new(VirtualKey.V, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift);

private bool isExecutable;
public bool IsExecutable => isExecutable;

public PasteItemToSelectionAction()
{
isExecutable = GetIsExecutable();

context.PropertyChanged += Context_PropertyChanged;
App.AppModel.PropertyChanged += AppModel_PropertyChanged;
}

public async Task ExecuteAsync()
{
if (context.ShellPage is null)
return;

string path = context.SelectedItem is ListedItem selectedItem
? selectedItem.ItemPath
: context.ShellPage.FilesystemViewModel.WorkingDirectory;

await UIFilesystemHelpers.PasteItemAsync(path, context.ShellPage);
}

public bool GetIsExecutable()
{
if (!App.AppModel.IsPasteEnabled)
return false;
if (context.PageType is ContentPageTypes.Home or ContentPageTypes.RecycleBin or ContentPageTypes.SearchResults)
return false;
if (!context.HasSelection)
return true;
return context.SelectedItem?.PrimaryItemAttribute is Windows.Storage.StorageItemTypes.Folder;
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.PageType):
case nameof(IContentPageContext.SelectedItem):
SetProperty(ref isExecutable, GetIsExecutable(), nameof(IsExecutable));
break;
}
}
private void AppModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(AppModel.IsPasteEnabled))
SetProperty(ref isExecutable, GetIsExecutable(), nameof(IsExecutable));
}
}
}
Loading

0 comments on commit feb3663

Please sign in to comment.