Skip to content

Commit

Permalink
Merge branch 'main' into prop_video_resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Feb 21, 2023
2 parents 5e5fc62 + 6f95b3f commit 6474b86
Show file tree
Hide file tree
Showing 51 changed files with 834 additions and 517 deletions.
21 changes: 21 additions & 0 deletions src/Files.App/Actions/Global/OpenHelpAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Files.App.Commands;
using Files.App.Extensions;
using System;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class OpenHelpAction : IAction
{
public string Label { get; } = "Help".GetLocalizedResource();

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

public async Task ExecuteAsync()
{
var url = new Uri(Constants.GitHub.DocumentationUrl);
await Launcher.LaunchUriAsync(url);
}
}
}
37 changes: 37 additions & 0 deletions src/Files.App/Actions/Global/ToggleFullScreenAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Files.App.Commands;
using Files.App.Extensions;
using Microsoft.UI.Windowing;
using System.Threading.Tasks;
using Windows.System;

namespace Files.App.Actions
{
internal class ToggleFullScreenAction : IToggleAction
{
public string Label { get; } = "FullScreen".GetLocalizedResource();

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

public bool IsOn
{
get
{
var window = App.GetAppWindow(App.Window);
return window.Presenter.Kind is AppWindowPresenterKind.FullScreen;
}
}

public Task ExecuteAsync()
{
var window = App.GetAppWindow(App.Window);

var newKind = window.Presenter.Kind is AppWindowPresenterKind.FullScreen
? AppWindowPresenterKind.Overlapped
: AppWindowPresenterKind.FullScreen;

window.SetPresenter(newKind);

return Task.CompletedTask;
}
}
}
5 changes: 4 additions & 1 deletion src/Files.App/Actions/IAction.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System.Threading.Tasks;
using Files.App.Commands;
using System.Threading.Tasks;

namespace Files.App.Actions
{
public interface IAction
{
string Label { get; }

HotKey HotKey => HotKey.None;

bool IsExecutable => true;

Task ExecuteAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@

namespace Files.App.Actions
{
internal class ShowFileExtensionsAction : ObservableObject, IToggleAction
internal class ToggleShowFileExtensionsAction : ObservableObject, IToggleAction
{
private readonly IFoldersSettingsService settings = Ioc.Default.GetRequiredService<IFoldersSettingsService>();

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

public bool IsOn => settings.ShowFileExtensions;

public ShowFileExtensionsAction() => settings.PropertyChanged += Settings_PropertyChanged;
public ToggleShowFileExtensionsAction() => settings.PropertyChanged += Settings_PropertyChanged;

public Task ExecuteAsync()
{
settings.ShowFileExtensions = !settings.ShowFileExtensions;
return Task.CompletedTask;
}

private void Settings_PropertyChanged(object? _, PropertyChangedEventArgs e)
private void Settings_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IFoldersSettingsService.ShowFileExtensions))
OnPropertyChanged(nameof(IsOn));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@

namespace Files.App.Actions
{
internal class ShowHiddenItemsAction : ObservableObject, IToggleAction
internal class ToggleShowHiddenItemsAction : ObservableObject, IToggleAction
{
private readonly IFoldersSettingsService settings = Ioc.Default.GetRequiredService<IFoldersSettingsService>();

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

public bool IsOn => settings.ShowHiddenItems;

public ShowHiddenItemsAction() => settings.PropertyChanged += Settings_PropertyChanged;
public ToggleShowHiddenItemsAction() => settings.PropertyChanged += Settings_PropertyChanged;

public Task ExecuteAsync()
{
settings.ShowHiddenItems = !settings.ShowHiddenItems;
return Task.CompletedTask;
}

private void Settings_PropertyChanged(object? _, PropertyChangedEventArgs e)
private void Settings_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IFoldersSettingsService.ShowHiddenItems))
OnPropertyChanged(nameof(IsOn));
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public async void BaseContextFlyout_Opening(object? sender, object e)
shellContextMenuItemCancellationToken = new CancellationTokenSource();

var shiftPressed = Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down);
var items = ContextFlyoutItemHelper.GetBaseContextCommandsWithoutShellItems(currentInstanceViewModel: InstanceViewModel!, itemViewModel: ParentShellPageInstance!.FilesystemViewModel, commandsViewModel: CommandsViewModel!, shiftPressed: shiftPressed);
var items = ContextFlyoutItemHelper.GetItemContextCommandsWithoutShellItems(currentInstanceViewModel: InstanceViewModel!, selectedItems: new List<ListedItem> { ParentShellPageInstance!.FilesystemViewModel.CurrentFolder }, commandsViewModel: CommandsViewModel!, shiftPressed: shiftPressed, itemViewModel: ParentShellPageInstance!.FilesystemViewModel, selectedItemsPropertiesViewModel: null);

BaseContextMenuFlyout.PrimaryCommands.Clear();
BaseContextMenuFlyout.SecondaryCommands.Clear();
Expand All @@ -605,7 +605,7 @@ public async void BaseContextFlyout_Opening(object? sender, object e)

if (!InstanceViewModel!.IsPageTypeSearchResults && !InstanceViewModel.IsPageTypeZipFolder)
{
var shellMenuItems = await ContextFlyoutItemHelper.GetBaseContextShellCommandsAsync(workingDir: ParentShellPageInstance.FilesystemViewModel.WorkingDirectory, shiftPressed: shiftPressed, showOpenMenu: false, shellContextMenuItemCancellationToken.Token);
var shellMenuItems = await ContextFlyoutItemHelper.GetItemContextShellCommandsAsync(workingDir: ParentShellPageInstance.FilesystemViewModel.WorkingDirectory, selectedItems: new List<ListedItem>(), shiftPressed: shiftPressed, showOpenMenu: false, shellContextMenuItemCancellationToken.Token);
if (shellMenuItems.Any())
AddShellItemsToMenu(shellMenuItems, BaseContextMenuFlyout, shiftPressed);
else
Expand Down Expand Up @@ -650,7 +650,7 @@ private async Task LoadMenuItemsAsync()
shellContextMenuItemCancellationToken = new CancellationTokenSource();
SelectedItemsPropertiesViewModel.CheckAllFileExtensions(SelectedItems!.Select(selectedItem => selectedItem?.FileExtension).ToList()!);
var shiftPressed = Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down);
var items = ContextFlyoutItemHelper.GetItemContextCommandsWithoutShellItems(currentInstanceViewModel: InstanceViewModel!, selectedItems: SelectedItems!, selectedItemsPropertiesViewModel: SelectedItemsPropertiesViewModel, commandsViewModel: CommandsViewModel!, shiftPressed: shiftPressed);
var items = ContextFlyoutItemHelper.GetItemContextCommandsWithoutShellItems(currentInstanceViewModel: InstanceViewModel!, selectedItems: SelectedItems!, selectedItemsPropertiesViewModel: SelectedItemsPropertiesViewModel, commandsViewModel: CommandsViewModel!, shiftPressed: shiftPressed, itemViewModel: null);
ItemContextMenuFlyout.PrimaryCommands.Clear();
ItemContextMenuFlyout.SecondaryCommands.Clear();
var (primaryElements, secondaryElements) = ItemModelListToContextFlyoutHelper.GetAppBarItemsFromModel(items);
Expand Down
8 changes: 6 additions & 2 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ public enum CommandCodes
{
None,

// global
OpenHelp,
ToggleFullScreen,

// show
ShowHiddenItems,
ShowFileExtensions,
ToggleShowHiddenItems,
ToggleShowFileExtensions,
}
}
157 changes: 157 additions & 0 deletions src/Files.App/Commands/HotKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
using System;
using System.Linq;
using System.Text;
using Windows.System;

namespace Files.App.Commands
{
public readonly struct HotKey : IEquatable<HotKey>
{
public static HotKey None { get; } = new(VirtualKey.None, VirtualKeyModifiers.None);

public bool IsNone => Key is VirtualKey.None;

public VirtualKey Key { get; } = VirtualKey.None;
public VirtualKeyModifiers Modifiers { get; } = VirtualKeyModifiers.None;

public HotKey(VirtualKey key) : this(key, VirtualKeyModifiers.None) { }
public HotKey(VirtualKey key, VirtualKeyModifiers modifiers)
{
if (key is VirtualKey.None)
return;

if (IsModifier(key))
throw new ArgumentException("The key cannot be a modifier.", nameof(key));

Key = key;
Modifiers = modifiers;

static bool IsModifier(VirtualKey key)
=> key is VirtualKey.Menu or VirtualKey.LeftMenu or VirtualKey.RightMenu
or VirtualKey.Control or VirtualKey.LeftControl or VirtualKey.RightControl
or VirtualKey.Shift or VirtualKey.LeftShift or VirtualKey.RightShift
or VirtualKey.LeftWindows or VirtualKey.RightWindows;
}

public void Deconstruct(out VirtualKey key, out VirtualKeyModifiers modifiers)
=> (key, modifiers) = (Key, Modifiers);

public static explicit operator HotKey(string hotKey) => Parse(hotKey);
public static implicit operator string(HotKey hotKey) => hotKey.ToString();

public static bool operator ==(HotKey a, HotKey b) => a.Equals(b);
public static bool operator !=(HotKey a, HotKey b) => !a.Equals(b);

public static HotKey Parse(string hotKey)
{
var key = VirtualKey.None;
var modifiers = VirtualKeyModifiers.None;

var parts = hotKey.Split('+').Select(item => item.Trim().ToLower());
foreach (string part in parts)
{
var m = ToModifiers(part);
if (m is not VirtualKeyModifiers.None)
{
modifiers |= m;
continue;
}

if (key is not VirtualKey.None)
{
var k = ToKey(part);
if (k is not VirtualKey.None)
{
key = k;
continue;
}
}

throw new FormatException($"{hotKey} is not a valid hot key");
}

return new(key, modifiers);

static VirtualKeyModifiers ToModifiers(string modifiers) => modifiers switch
{
"alt" or "menu " => VirtualKeyModifiers.Menu,
"ctrl" or "control" => VirtualKeyModifiers.Control,
"shift" => VirtualKeyModifiers.Shift,
_ => VirtualKeyModifiers.None,
};

static VirtualKey ToKey(string part) => part switch
{
"alt" or "menu" => VirtualKey.None,
"ctrl" or "control" => VirtualKey.None,
"shift" => VirtualKey.None,
"windows" => VirtualKey.None,
"0" => VirtualKey.Number0,
"1" => VirtualKey.Number1,
"2" => VirtualKey.Number2,
"3" => VirtualKey.Number3,
"4" => VirtualKey.Number4,
"5" => VirtualKey.Number5,
"6" => VirtualKey.Number6,
"7" => VirtualKey.Number7,
"8" => VirtualKey.Number8,
"9" => VirtualKey.Number9,
"Pad0" => VirtualKey.NumberPad0,
"Pad1" => VirtualKey.NumberPad1,
"Pad2" => VirtualKey.NumberPad2,
"Pad3" => VirtualKey.NumberPad3,
"Pad4" => VirtualKey.NumberPad4,
"Pad5" => VirtualKey.NumberPad5,
"Pad6" => VirtualKey.NumberPad6,
"Pad7" => VirtualKey.NumberPad7,
"Pad8" => VirtualKey.NumberPad8,
"Pad9" => VirtualKey.NumberPad9,
_ => Enum.TryParse(part, true, out VirtualKey key) ? key : VirtualKey.None,
};
}

public override string ToString()
{
StringBuilder builder = new();
if (Modifiers.HasFlag(VirtualKeyModifiers.Menu))
builder.Append("Alt+");
if (Modifiers.HasFlag(VirtualKeyModifiers.Control))
builder.Append("Ctrl+");
if (Modifiers.HasFlag(VirtualKeyModifiers.Shift))
builder.Append("Shift+");
if (Modifiers.HasFlag(VirtualKeyModifiers.Windows))
builder.Append("Win+");
builder.Append(ToString(Key));
return builder.ToString();

static string ToString(VirtualKey key) => key switch
{
VirtualKey.Number0 => "0",
VirtualKey.Number1 => "1",
VirtualKey.Number2 => "2",
VirtualKey.Number3 => "3",
VirtualKey.Number4 => "4",
VirtualKey.Number5 => "5",
VirtualKey.Number6 => "6",
VirtualKey.Number7 => "7",
VirtualKey.Number8 => "8",
VirtualKey.Number9 => "9",
VirtualKey.NumberPad0 => "Pad0",
VirtualKey.NumberPad1 => "Pad1",
VirtualKey.NumberPad2 => "Pad2",
VirtualKey.NumberPad3 => "Pad3",
VirtualKey.NumberPad4 => "Pad4",
VirtualKey.NumberPad5 => "Pad5",
VirtualKey.NumberPad6 => "Pad6",
VirtualKey.NumberPad7 => "Pad7",
VirtualKey.NumberPad8 => "Pad8",
VirtualKey.NumberPad9 => "Pad9",
_ => key.ToString(),
};
}

public override int GetHashCode() => (Key, Modifiers).GetHashCode();
public override bool Equals(object? other) => other is HotKey hotKey && Equals(hotKey);
public bool Equals(HotKey other) => (other.Key, other.Modifiers).Equals((Key, Modifiers));
}
}
6 changes: 5 additions & 1 deletion src/Files.App/Commands/IRichCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ public interface IRichCommand : ICommand, INotifyPropertyChanging, INotifyProper
CommandCodes Code { get; }

string Label { get; }
string LabelWithHotKey { get; }
string AutomationName { get; }

HotKey DefaultHotKey { get; }
HotKey CustomHotKey { get; set; }

bool IsToggle { get; }
bool IsOn { get; set; }
bool IsExecutable { get; }

Task ExecuteAsync();

void ExecuteTapped(object sender, TappedRoutedEventArgs e);
}
}
Loading

0 comments on commit 6474b86

Please sign in to comment.