public async Task UpdateViewModel(ShortcutModel shortcut) { Console.WriteLine($"UpdateViewModel - {shortcut.ToString()}"); //AppState.IsSearching(!string.IsNullOrEmpty(shortcut.ToString())); this.Keyboard.ResetAvailable(); foreach (var v in this.Bindings.Scope.SelectMany(x => x.Bindings)) { //split up the shortcut string into parts if (v.DisplayName.ToLower() == "inserttab" || v.DisplayName.ToLower() == "insert tab") { Console.WriteLine(shortcut.ToString() + " | " + v.ShortcutKeys.ToString()); } var ctrlMatch = v.ShortcutKeys.Keys1.Control == shortcut.Keys1.Control; var altMatch = v.ShortcutKeys.Keys1.Alt == shortcut.Keys1.Alt; var shiftMatch = v.ShortcutKeys.Keys1.Shift == shortcut.Keys1.Shift; var keyMatch = v.ShortcutKeys.Keys1.Key == shortcut.Keys1.Key || string.IsNullOrEmpty(shortcut.Keys1.Key); v.IsMatch = ctrlMatch && altMatch && shiftMatch && keyMatch; //(string.IsNullOrEmpty(shortcut.ToString()) || v.ShortcutKeys.ToString().ToLower().StartsWith(shortcut.ToString().ToLower())); //if control is pressed //matches = anything with ctrl in it //available = shift, alt, anything thats a direct ctrl combo if (v.IsMatch) { var hey = v.ShortcutKeys.ToString().Substring(shortcut.ToString().Length); var you = hey.Split(','); var are = (you.FirstOrDefault().Length == 0) ? you.LastOrDefault() : you.FirstOrDefault(); var lazy = are.Trim().Split('+').FirstOrDefault().Trim(); if (!string.IsNullOrWhiteSpace(lazy)) { var keyEnum = GetKeyFromString(lazy); if (keyEnum.HasValue) { this.Keyboard.Keys[keyEnum.Value].IsAvailable = true; } } } } }
public Binding(string name, string displayName, string shortcut) { FullName = name; DisplayName = displayName; ShortcutKeys = new ShortcutModel(shortcut); }
public void Reset() { this.Bindings = new BindingModel(); this.Keyboard = new KeyboardModel(); this.Shortcut = new ShortcutModel(); }