Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix-icon-codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay-o-Way committed Mar 28, 2023
2 parents 7c54ea4 + 5ed2483 commit b0955cf
Show file tree
Hide file tree
Showing 128 changed files with 3,181 additions and 2,638 deletions.
47 changes: 47 additions & 0 deletions src/Files.App/Actions/Content/RefreshItemsAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.System;

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

public string Label { get; } = "Refresh".GetLocalizedResource();
public string Description { get; } = "TODO";

public RichGlyph Glyph { get; } = new("\uE72C");

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

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

public bool IsExecutable => context.CanRefresh;

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

public async Task ExecuteAsync()
{
context.ShellPage?.Refresh_Click();
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.CanRefresh):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
4 changes: 0 additions & 4 deletions src/Files.App/Actions/Content/Run/RunAsAdminAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
using Files.App.Extensions;
using Files.App.Shell;
using Files.Backend.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Files.App.Actions
Expand Down
33 changes: 33 additions & 0 deletions src/Files.App/Actions/Content/Selection/ToggleSelectAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Files.App.Commands;
using Files.App.Extensions;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class ToggleSelectAction : IAction
{
public string Label { get; } = "ToggleSelect".GetLocalizedResource();
public string Description => "TODO: Need to be described.";

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

public bool IsExecutable => GetFocusedElement() is not null;

public Task ExecuteAsync()
{
if (GetFocusedElement() is SelectorItem item)
{
item.IsSelected = !item.IsSelected;
}
return Task.CompletedTask;
}

private static SelectorItem? GetFocusedElement()
{
return FocusManager.GetFocusedElement(App.Window.Content.XamlRoot) as SelectorItem;
}
}
}
3 changes: 1 addition & 2 deletions src/Files.App/Actions/FileSystem/CopyPathAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
Expand Down
6 changes: 5 additions & 1 deletion src/Files.App/Actions/FileSystem/OpenItemAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.System;

namespace Files.App.Actions
{
Expand All @@ -23,9 +24,12 @@ internal class OpenItemAction : ObservableObject, IAction

public RichGlyph Glyph => new(opacityStyle: "ColorIconOpenFile");

public HotKey HotKey => new(VirtualKey.Enter);

private const int MaxOpenCount = 10;

public bool IsExecutable => context.HasSelection && context.SelectedItems.Count <= MaxOpenCount;
public bool IsExecutable => context.HasSelection && context.SelectedItems.Count <= MaxOpenCount &&
!(context.ShellPage is ColumnShellPage && context.SelectedItem?.PrimaryItemAttribute == StorageItemTypes.Folder);

public OpenItemAction()
{
Expand Down
67 changes: 67 additions & 0 deletions src/Files.App/Actions/FileSystem/RenameAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using System.Threading.Tasks;
using Windows.System;

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

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

public string Description { get; } = "TODO";

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

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

public bool IsExecutable =>
context.ShellPage is not null &&
IsPageTypeValid() &&
context.ShellPage.SlimContentPage is not null &&
IsSelectionValid();

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

public Task ExecuteAsync()
{
context.ShellPage?.SlimContentPage?.ItemManipulationModel.StartRenameItem();
return Task.CompletedTask;
}

private void Context_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.ShellPage):
case nameof(IContentPageContext.PageType):
case nameof(IContentPageContext.HasSelection):
case nameof(IContentPageContext.SelectedItems):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}

private bool IsSelectionValid()
{
return context.HasSelection && context.SelectedItems.Count == 1;
}

private bool IsPageTypeValid()
{
return context.PageType is
not ContentPageTypes.None and
not ContentPageTypes.Home and
not ContentPageTypes.RecycleBin and
not ContentPageTypes.ZipFolder;
}
}
}
49 changes: 49 additions & 0 deletions src/Files.App/Actions/Global/SearchAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.System;

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

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

public string Description { get; } = "TODO: Need to be described.";

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

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

public RichGlyph Glyph { get; } = new();

public bool IsExecutable => !context.IsSearchBoxVisible;

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

public Task ExecuteAsync()
{
context.ShellPage!.ToolbarViewModel.SwitchSearchBoxVisibility();
return Task.CompletedTask;
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.IsSearchBoxVisible):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
50 changes: 50 additions & 0 deletions src/Files.App/Actions/Navigation/NavigateBackAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.System;

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

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

public string Description { get; } = "NavigateBack".GetLocalizedResource();

public HotKey HotKey { get; } = new(VirtualKey.Left, VirtualKeyModifiers.Menu);
public HotKey SecondHotKey { get; } = new(VirtualKey.Back);
public HotKey ThirdHotKey { get; } = new(VirtualKey.XButton1);
public HotKey MediaHotKey { get; } = new(VirtualKey.GoBack);

public RichGlyph Glyph { get; } = new("\uE72B");

public bool IsExecutable => context.CanGoBack;

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

public Task ExecuteAsync()
{
context.ShellPage!.Back_Click();
return Task.CompletedTask;
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.CanGoBack):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
49 changes: 49 additions & 0 deletions src/Files.App/Actions/Navigation/NavigateForwardAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.System;

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

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

public string Description { get; } = "NavigateForward".GetLocalizedResource();

public HotKey HotKey { get; } = new(VirtualKey.Right, VirtualKeyModifiers.Menu);
public HotKey SecondHotKey { get; } = new(VirtualKey.XButton2);
public HotKey MediaHotKey { get; } = new(VirtualKey.GoForward);

public RichGlyph Glyph { get; } = new("\uE72A");

public bool IsExecutable => context.CanGoForward;

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

public Task ExecuteAsync()
{
context.ShellPage!.Forward_Click();
return Task.CompletedTask;
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.CanGoForward):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
48 changes: 48 additions & 0 deletions src/Files.App/Actions/Navigation/NavigateUpAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.System;

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

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

public string Description { get; } = "NavigateUp".GetLocalizedResource();

public HotKey HotKey { get; } = new(VirtualKey.Up, VirtualKeyModifiers.Menu);

public RichGlyph Glyph { get; } = new("\uE74A");

public bool IsExecutable => context.CanNavigateToParent;

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

public Task ExecuteAsync()
{
context.ShellPage!.Up_Click();
return Task.CompletedTask;
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.CanNavigateToParent):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
Loading

0 comments on commit b0955cf

Please sign in to comment.