mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-03-26 19:03:32 -04:00
Merge pull request #1676 from rmcrackan/rmcrackan/1625-mac-key-bindings
Bug fix #1625 -- fix mac key bindings
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using System;
|
||||
@@ -105,7 +105,7 @@ public class DataGridCellContextMenu<TContext> where TContext : class
|
||||
private static KeyEventArgs GetCopyEventArgs() => new()
|
||||
{
|
||||
Key = Key.C,
|
||||
KeyModifiers = KeyModifiers.Control,
|
||||
KeyModifiers = KeyGestureHelper.CommandModifier,
|
||||
Route = Avalonia.Interactivity.RoutingStrategies.Bubble,
|
||||
PhysicalKey = PhysicalKey.C,
|
||||
KeySymbol = "c",
|
||||
|
||||
14
Source/LibationAvalonia/KeyGestureHelper.cs
Normal file
14
Source/LibationAvalonia/KeyGestureHelper.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Avalonia.Input;
|
||||
using LibationFileManager;
|
||||
|
||||
namespace LibationAvalonia;
|
||||
|
||||
/// <summary>Cross-platform keyboard modifier helpers. Use these instead of hardcoding Control/Alt/Meta per OS.</summary>
|
||||
public static class KeyGestureHelper
|
||||
{
|
||||
/// <summary>Primary "command" modifier: Control on Windows/Linux, Meta (Command) on macOS.</summary>
|
||||
public static KeyModifiers CommandModifier => Configuration.IsMacOs ? KeyModifiers.Meta : KeyModifiers.Control;
|
||||
|
||||
/// <summary>Menu accelerator modifier that works on all platforms: Alt on Windows/Linux, Meta on macOS. Use (Alt|Meta) so one binding accepts either.</summary>
|
||||
public static KeyModifiers MenuModifier => KeyModifiers.Alt | KeyModifiers.Meta;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Avalonia;
|
||||
using Avalonia;
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data;
|
||||
@@ -114,7 +114,7 @@ partial class MainVM
|
||||
{
|
||||
//Register hotkeys Command + 1 - 0 for quick filters
|
||||
var key = index == 10 ? Key.D0 : Key.D0 + index;
|
||||
nativeMenuItem.Gesture = new KeyGesture(key, KeyModifiers.Meta);
|
||||
nativeMenuItem.Gesture = new KeyGesture(key, KeyGestureHelper.CommandModifier);
|
||||
}
|
||||
else if (!Configuration.IsMacOs && index <= 12)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using ApplicationServices;
|
||||
using ApplicationServices;
|
||||
using AudibleUtilities;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
@@ -252,17 +252,17 @@ public partial class MainVM
|
||||
}
|
||||
else if (AccountsCount == 1)
|
||||
{
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Scan Library", Command = ReactiveCommand.Create(ScanAccountAsync), Gesture = new KeyGesture(Key.S, KeyModifiers.Alt | KeyModifiers.Meta) });
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Scan Library", Command = ReactiveCommand.Create(ScanAccountAsync), Gesture = new KeyGesture(Key.S, KeyGestureHelper.MenuModifier) });
|
||||
importMenuItem.Items.Add(new NativeMenuItemSeparator());
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Remove Library Books", Command = ReactiveCommand.Create(RemoveBooksAsync), Gesture = new KeyGesture(Key.R, KeyModifiers.Alt | KeyModifiers.Meta) });
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Remove Library Books", Command = ReactiveCommand.Create(RemoveBooksAsync), Gesture = new KeyGesture(Key.R, KeyGestureHelper.MenuModifier) });
|
||||
}
|
||||
else
|
||||
{
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Scan Library of All Accounts", Command = ReactiveCommand.Create(ScanAllAccountsAsync), Gesture = new KeyGesture(Key.S, KeyModifiers.Alt | KeyModifiers.Meta) });
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Scan Library of Some Accounts", Command = ReactiveCommand.Create(ScanSomeAccountsAsync), Gesture = new KeyGesture(Key.S, KeyModifiers.Alt | KeyModifiers.Meta | KeyModifiers.Shift) });
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Scan Library of All Accounts", Command = ReactiveCommand.Create(ScanAllAccountsAsync), Gesture = new KeyGesture(Key.S, KeyGestureHelper.MenuModifier) });
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Scan Library of Some Accounts", Command = ReactiveCommand.Create(ScanSomeAccountsAsync), Gesture = new KeyGesture(Key.S, KeyGestureHelper.MenuModifier | KeyModifiers.Shift) });
|
||||
importMenuItem.Items.Add(new NativeMenuItemSeparator());
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Remove Books from All Accounts", Command = ReactiveCommand.Create(RemoveBooksAllAsync), Gesture = new KeyGesture(Key.R, KeyModifiers.Alt | KeyModifiers.Meta) });
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Remove Books from Some Accounts", Command = ReactiveCommand.Create(RemoveBooksSomeAsync), Gesture = new KeyGesture(Key.R, KeyModifiers.Alt | KeyModifiers.Meta | KeyModifiers.Shift) });
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Remove Books from All Accounts", Command = ReactiveCommand.Create(RemoveBooksAllAsync), Gesture = new KeyGesture(Key.R, KeyGestureHelper.MenuModifier) });
|
||||
importMenuItem.Items.Add(new NativeMenuItem { Header = "Remove Books from Some Accounts", Command = ReactiveCommand.Create(RemoveBooksSomeAsync), Gesture = new KeyGesture(Key.R, KeyGestureHelper.MenuModifier | KeyModifiers.Shift) });
|
||||
}
|
||||
|
||||
importMenuItem.Items.Add(new NativeMenuItemSeparator());
|
||||
|
||||
@@ -35,13 +35,13 @@ public partial class MainWindow : ReactiveWindow<MainVM>
|
||||
Opened += MainWindow_Opened;
|
||||
Closing += MainWindow_Closing;
|
||||
|
||||
KeyBindings.Add(new KeyBinding { Command = ReactiveCommand.Create(selectAndFocusSearchBox), Gesture = new KeyGesture(Key.F, Configuration.IsMacOs ? KeyModifiers.Meta : KeyModifiers.Control) });
|
||||
KeyBindings.Add(new KeyBinding { Command = ReactiveCommand.Create(selectAndFocusSearchBox), Gesture = new KeyGesture(Key.F, KeyGestureHelper.CommandModifier) });
|
||||
|
||||
if (!Configuration.IsMacOs && ViewModel is MainVM vm)
|
||||
{
|
||||
KeyBindings.Add(new KeyBinding { Command = ReactiveCommand.Create(vm.ShowSettingsAsync), Gesture = new KeyGesture(Key.P, KeyModifiers.Control) });
|
||||
KeyBindings.Add(new KeyBinding { Command = ReactiveCommand.Create(vm.ShowAccountsAsync), Gesture = new KeyGesture(Key.A, KeyModifiers.Control | KeyModifiers.Shift) });
|
||||
KeyBindings.Add(new KeyBinding { Command = ReactiveCommand.Create(vm.ExportLibraryAsync), Gesture = new KeyGesture(Key.S, KeyModifiers.Control) });
|
||||
KeyBindings.Add(new KeyBinding { Command = ReactiveCommand.Create(vm.ShowSettingsAsync), Gesture = new KeyGesture(Key.P, KeyGestureHelper.CommandModifier) });
|
||||
KeyBindings.Add(new KeyBinding { Command = ReactiveCommand.Create(vm.ShowAccountsAsync), Gesture = new KeyGesture(Key.A, KeyGestureHelper.CommandModifier | KeyModifiers.Shift) });
|
||||
KeyBindings.Add(new KeyBinding { Command = ReactiveCommand.Create(vm.ExportLibraryAsync), Gesture = new KeyGesture(Key.S, KeyGestureHelper.CommandModifier) });
|
||||
}
|
||||
|
||||
Configuration.Instance.PropertyChanged += Settings_PropertyChanged;
|
||||
|
||||
Reference in New Issue
Block a user