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

Feature: Disabled keyboard shortcuts when renaming items #13118

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
52 changes: 0 additions & 52 deletions src/Files.App/Data/Commands/HotKey/HotKeyHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,13 @@
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Input;
using System.Collections.Generic;
using System.Collections.Immutable;
using Windows.System;
using Windows.UI.Core;

namespace Files.App.Data.Commands
{
internal static class HotKeyHelpers
{
private static readonly ImmutableArray<Keys> globalKeys = new List<Keys>
{
Keys.GoHome,
Keys.GoBack,
Keys.GoForward,
Keys.Application,
Keys.Favorites,
Keys.Search,
Keys.Refresh,
Keys.Pause,
Keys.Sleep,
Keys.Print,
Keys.F1,
Keys.F2,
Keys.F3,
Keys.F4,
Keys.F5,
Keys.F6,
Keys.F7,
Keys.F8,
Keys.F9,
Keys.F10,
Keys.F11,
Keys.F12,
Keys.F13,
Keys.F14,
Keys.F15,
Keys.F16,
Keys.F17,
Keys.F18,
Keys.F19,
Keys.F20,
Keys.F21,
Keys.F22,
Keys.F23,
Keys.F24,
}.ToImmutableArray();

private static readonly ImmutableArray<HotKey> textBoxHotKeys = new List<HotKey>
{
new HotKey(Keys.X, KeyModifiers.Ctrl), // Cut
new HotKey(Keys.C, KeyModifiers.Ctrl), // Copy
new HotKey(Keys.V, KeyModifiers.Ctrl), // Paste
new HotKey(Keys.A, KeyModifiers.Ctrl), // Select all
new HotKey(Keys.Z, KeyModifiers.Ctrl), // Cancel
}.ToImmutableArray();

public static bool IsGlobalKey(this Keys key) => globalKeys.Contains(key);
public static bool IsTextBoxHotKey(this HotKey hotKey) => textBoxHotKeys.Contains(hotKey);

public static KeyModifiers GetCurrentKeyModifiers()
{
var modifiers = VirtualKeyModifiers.None;
Expand Down
17 changes: 3 additions & 14 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
using CommunityToolkit.WinUI.Helpers;
using CommunityToolkit.WinUI.UI;
using CommunityToolkit.WinUI.UI.Controls;
using Files.App.Data.Items;
using Files.App.Data.Models;
using Files.App.UserControls;
using Files.App.UserControls.MultitaskingControl;
using Files.Core.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.ApplicationModel.Resources;
using System.Runtime.CompilerServices;
using Windows.ApplicationModel;
using Windows.Services.Store;
Expand Down Expand Up @@ -220,14 +215,8 @@ protected override async void OnPreviewKeyDown(KeyRoutedEventArgs e)
HotKey hotKey = new((Keys)e.Key, currentModifiers);

// A textbox takes precedence over certain hotkeys.
bool isTextBox = e.OriginalSource is DependencyObject source && source.FindAscendantOrSelf<TextBox>() is not null;
if (isTextBox)
{
if (hotKey.IsTextBoxHotKey())
break;
if (currentModifiers is KeyModifiers.None && !hotKey.Key.IsGlobalKey())
break;
}
if (e.OriginalSource is DependencyObject source && source.FindAscendantOrSelf<TextBox>() is not null)
break;

// Execute command for hotkey
var command = Commands[hotKey];
Expand Down Expand Up @@ -273,7 +262,7 @@ private async void SidebarControl_SidebarItemDropped(object sender, SidebarItemD
e.SignalEvent?.Set();
}

private async void SidebarControl_SidebarItemPropertiesInvoked(object sender, SidebarItemPropertiesInvokedEventArgs e)
private void SidebarControl_SidebarItemPropertiesInvoked(object sender, SidebarItemPropertiesInvokedEventArgs e)
{
if (e.InvokedItemDataContext is DriveItem)
FilePropertiesHelpers.OpenPropertiesWindow(e.InvokedItemDataContext, SidebarAdaptiveViewModel.PaneHolder.ActivePane);
Expand Down