private void doSave() { if (string.IsNullOrWhiteSpace(CurrentEdit.FileName)) { DialogWin.Show("没有关联布局文件。", DialogWinImage.Warning); return; } if (!CurrentEdit.IsShortcutValid) { DialogWin.Show("无效的快捷键。", DialogWinImage.Warning); return; } if (_dictShortcuts.ContainsKey(CurrentEdit.ShortcutString)) { if (!(bool)DialogWin.Show("已存在相同的快捷键设置,是否要覆盖旧的快捷键?", "覆盖确认", true, DialogWinImage.None)) { return; } } //判断快捷键是否可用。 try { KeyGesture kg = new KeyGesture(CurrentEdit.Key, CurrentEdit.Modifiers); } catch (NotSupportedException) { DialogWin.Show($"不支持当前快捷键组合:{CurrentEdit.ShortcutString}", DialogWinImage.Error); return; } _dictShortcuts[CurrentEdit.ShortcutString] = CurrentEdit; Shortcuts = new ObservableCollection <ShortcutItem>(_dictShortcuts.Values); CurrentEdit = new ShortcutItem(); }
public ShortcutItem(ShortcutItem si) : this() { if (si != null) { Name = si.Name; FileName = si.FileName; Key = si.Key; Modifiers = si.Modifiers; } }
private void this_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(CurrentSelected): if (CurrentSelected != null) { CurrentEdit = new ShortcutItem(CurrentSelected); } break; } }
public ShortcutWinModel() { _dictShortcuts = new Dictionary <string, ShortcutItem>(); loadShortcuts(); CurrentEdit = new ShortcutItem(); SelectFileCmd = new DelegateCommand(x => doSelectFile()); SaveCmd = new DelegateCommand(x => doSave()); DeleteCmd = new DelegateCommand(x => doDelete()); ClearCmd = new DelegateCommand(x => doClear()); CloseCmd = new DelegateCommand(x => doClose()); this.PropertyChanged += this_PropertyChanged; }