using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Input; namespace QuikDawEditor.EDITING; public class ShorcutKeys { public static List DefaultShortCutKeyList = new List (new UserCommandKeyPair[] { new UserCommandKeyPair("Quantize=Ctrl+Q"), new UserCommandKeyPair("AddNewAudioTrack=Ctrl+Shift+A"), new UserCommandKeyPair("AddNewMidiTrack=Ctrl+Shift+M"), new UserCommandKeyPair("TransposeMidiUp=Ctrl+Add"), new UserCommandKeyPair("TransposeMidiDown=Ctrl+Subtract"), new UserCommandKeyPair("TogglePianoRollView=Ctrl+P"), new UserCommandKeyPair("ToggleMixerView=Ctrl+M"), new UserCommandKeyPair("ToggleShowSelectionRange=Ctrl+Shift+R"), new UserCommandKeyPair("ToggleLoopPlayOn=L"), new UserCommandKeyPair("SetBookmark=Ctrl+Shift+B"), new UserCommandKeyPair("GoToBookmark=Ctrl+Shift+F") }); public class UserCommandKeyPair { public string CommandName { get; set; } public Key shortcutKey { get; set; } public List modifierKeys = new List(); public bool modifierKeysMatch(ModifierKeys modKeys) { //MessageBox.Show(Keyboard.Modifiers.ToString()); if (modKeys == 0 && modifierKeys.Count == 0) return true; List pressedModKeyStrings = new List(modKeys.ToString().Replace("Control", "Ctrl").Split(",").ToList().ConvertAll(s => s.TrimStart(' '))); pressedModKeyStrings.Sort(); List modKeyStrings = new List(ModifierKeyString.TrimEnd('+').Split("+")); modKeyStrings.Sort(); return pressedModKeyStrings.SequenceEqual(modKeyStrings); } public string ModifierKeyString { get { ModifierKeysConverter mkc = new ModifierKeysConverter(); string modifierString = ""; foreach (ModifierKeys mkey in modifierKeys) modifierString += mkc.ConvertToString(mkey).ToString() + "+"; //MessageBox.Show("modifierString=" + modifierString); return modifierString; } } public string KeyGestureString { get { string returnString = shortcutKey.ToString(); return ModifierKeyString + returnString; } } public UserCommandKeyPair(string s) { string[] parts = s.Split("="); CommandName = parts[0]; List modParts = new List(parts[1].Split("+")); if (modParts.Contains("Ctrl")) modifierKeys.Add(ModifierKeys.Control); if (modParts.Contains("Alt")) modifierKeys.Add(ModifierKeys.Alt); if (modParts.Contains("Shift")) modifierKeys.Add(ModifierKeys.Shift); KeyConverter keyConverter = new KeyConverter(); shortcutKey = (Key)keyConverter.ConvertFromString(modParts[modParts.Count - 1]); } public string GetSettingString { get { return CommandName + "=" + KeyGestureString; } } } }