diff --git a/OpenUtau.Core/Util/Preferences.cs b/OpenUtau.Core/Util/Preferences.cs index f14fe185d..03ab1e1cc 100644 --- a/OpenUtau.Core/Util/Preferences.cs +++ b/OpenUtau.Core/Util/Preferences.cs @@ -16,7 +16,15 @@ public static class Preferences { static Preferences() { Load(); } + public class ShortcutBinding { + public string ActionId { get; set; } + public string[] Shortcuts { get; set; } + public ShortcutBinding(string actionId, string[] shortcuts) { + ActionId = actionId; + Shortcuts = shortcuts; + } + } public static void Save() { try { File.WriteAllText(PathManager.Inst.PrefsFilePath, @@ -216,6 +224,8 @@ public class SerializablePreferences { public bool LockUnselectedNotesPitch = true; public bool LockUnselectedNotesVibrato = true; public bool LockUnselectedNotesExpressions = true; + public ShortcutBinding[] Shortcuts = []; + public ShortcutBinding[] PluginShortcuts = []; public bool LyricLivePreview = true; public bool LyricApplySelectionOnly = true; public bool VoicebankPublishUseIgnore = true; diff --git a/OpenUtau/Controls/PianoRoll.axaml b/OpenUtau/Controls/PianoRoll.axaml index 647d22145..757f7f792 100644 --- a/OpenUtau/Controls/PianoRoll.axaml +++ b/OpenUtau/Controls/PianoRoll.axaml @@ -117,7 +117,6 @@ Fill="{DynamicResource NeutralAccentBrushSemi}" Data="M -6.5 0 L 6.5 0 L 6.5 3 L 0 9 L -6.5 3 Z"/> - - - - @@ -248,17 +244,17 @@ - - + + - - - - - + + + + + - - + + @@ -301,7 +297,7 @@ - + @@ -359,7 +355,7 @@ - + @@ -368,17 +364,22 @@ - + - + - + + + + + + + @@ -392,31 +393,121 @@ - - + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + @@ -430,8 +521,13 @@ - + + + + + + + @@ -440,22 +536,37 @@ - + + + + + + + - + + + + + + + - + + + + + + + @@ -467,14 +578,24 @@ - + + + + + + + - + + + + + + + @@ -497,8 +618,13 @@ - + + + + + + + @@ -510,14 +636,24 @@ - + + + + + + + - - - + - + - + - + - + - + - + - + @@ -286,7 +291,7 @@ + + + + + + + diff --git a/OpenUtau/Views/PreferencesDialog.axaml.cs b/OpenUtau/Views/PreferencesDialog.axaml.cs index 0f3d0a0f0..a4a0556e1 100644 --- a/OpenUtau/Views/PreferencesDialog.axaml.cs +++ b/OpenUtau/Views/PreferencesDialog.axaml.cs @@ -8,15 +8,52 @@ using OpenUtau.App.ViewModels; using OpenUtau.Colors; using OpenUtau.Core; +using Avalonia.Input; namespace OpenUtau.App.Views { public partial class PreferencesDialog : Window { - private PreferencesViewModel? viewModel => this.DataContext as PreferencesViewModel; + private PreferencesViewModel? viewModel => this.DataContext as PreferencesViewModel; public PreferencesDialog() { InitializeComponent(); } + void OnKeyDown(object sender, KeyEventArgs e) { + if (DataContext is PreferencesViewModel vm && vm.ActiveShortcut != null) { + // If they hit escape without modifiers, cancel listening + if (e.Key == Key.Escape && e.KeyModifiers == KeyModifiers.None) { + vm.ActiveShortcut.IsAdding = false; + vm.ActiveShortcut.IsListening = false; + vm.ActiveShortcut.RefreshDisplay(); + vm.ActiveShortcut = null; + e.Handled = true; + return; + } + + vm.AssignShortcut(e.Key, e.KeyModifiers); + e.Handled = true; + return; + } + } + + public void OnShortcutRightClick(object sender, PointerReleasedEventArgs e) { + if (e.InitialPressMouseButton == MouseButton.Right && + sender is Button btn && + btn.DataContext is ShortcutItemViewModel item) { + item.Reset(); + e.Handled = true; + } + } + + void OnShortcutMiscClick(object? sender, RoutedEventArgs e) { + if (sender is Button btn && + btn.DataContext is ShortcutItemViewModel item) { + item.CreateMenuItem(); + btn.ContextMenu?.Open(); + e.Handled = true; + } + } + void OpenSingersFolder(object sender, RoutedEventArgs e) { try { Directory.CreateDirectory(viewModel!.SingerPath); @@ -132,7 +169,7 @@ void OnCustomThemeCreate(object sender, RoutedEventArgs e) { dialog.SetPrompt(ThemeManager.GetString("prefs.appearance.customtheme.create.prompt")); dialog.onFinish = s => { if (string.IsNullOrEmpty(s)) { - MessageBox.ShowModal(this, + MessageBox.ShowModal(this, ThemeManager.GetString("prefs.appearance.customtheme.create.empty"), ThemeManager.GetString("prefs.appearance.customtheme.create.title")); return;