public SettingsViewModel(MainViewModel mvm) { KeyDisplayStrings = new Dictionary<HotkeyAction, Common.Notifiable<string>>(); KeyDisplayStrings[HotkeyAction.Split] = new Common.Notifiable<string>(Settings.Default.SplitKey == null ? "Unset" : Settings.Default.SplitKey.ToString()); KeyDisplayStrings[HotkeyAction.Unsplit] = new Common.Notifiable<string>(Settings.Default.UnsplitKey == null ? "Unset" : Settings.Default.UnsplitKey.ToString()); KeyDisplayStrings[HotkeyAction.Reset] = new Common.Notifiable<string>(Settings.Default.ResetKey == null ? "Unset" : Settings.Default.ResetKey.ToString()); KeyDisplayStrings[HotkeyAction.Skip] = new Common.Notifiable<string>(Settings.Default.SkipKey == null ? "Unset" : Settings.Default.SkipKey.ToString()); KeyDisplayStrings[HotkeyAction.Pause] = new Common.Notifiable<string>(Settings.Default.PauseKey == null ? "Unset" : Settings.Default.PauseKey.ToString()); var keyPressedObs = Observable.FromEventPattern<KeyboardHookEventHandler, KeyboardHookEventArgs>( h => mvm.HotKeyManager.KeyBoardKeyEvent += h, h => mvm.HotKeyManager.KeyBoardKeyEvent -= h); ChangeHotkey = Command.Create<HotkeyAction>(_ => true, ha => { IsPendingHotkeyChange = true; KeyDisplayStrings[ha].Value = "<< Press Key To Set Hotkey >>"; keyPressedObs.Take(1).LastAsync().SubscribeSafeLog(key => { selectedKeyStorage[ha] = key.EventArgs.Key; KeyDisplayStrings[ha].Value = key.EventArgs.Key.ToString(); IsPendingHotkeyChange = false; }); }); ClearHotkey = Command.Create<HotkeyAction>(_ => true, ha => { KeyDisplayStrings[ha].Value = "Unset"; selectedKeyStorage[ha] = null; }); }
public DisplayTemplatesViewModel(MainViewModel mainViewModel) { this.mainViewModel = mainViewModel; AvailableFonts = Fonts.SystemFontFamilies.Select(ff => ff.ToString()).OrderBy(s => s).ToArray(); var conv = new BrushConverter(); AvailableColors = typeof(Colors).GetProperties().Select(p => new { Name = p.Name, Color = conv.ConvertFromString(p.Name) }) .Where(a => a.Color is SolidColorBrush).ToDictionary(a => a.Name, a => ((SolidColorBrush)a.Color).Color); UserTemplates = PersistenceManager.Instance.DisplayTemplates; DefaultDisplayTemplate = UserTemplates.FirstOrDefault(); SelectedDisplayTemplate = DefaultDisplayTemplate; CloneTemplate = Command.Create(() => true, () => { if (SelectedDisplayTemplate == null) return; var cloned = SelectedDisplayTemplate.Clone(); cloned.TemplateName = "(Copy) " + cloned.TemplateName; PersistenceManager.Instance.DisplayTemplates.Add(cloned); SelectedDisplayTemplate = cloned; }); RemoveTemplate = Command.Create(() => true, () => { if (SelectedDisplayTemplate == null) return; PersistenceManager.Instance.DisplayTemplates.Remove(SelectedDisplayTemplate); SelectedDisplayTemplate = DefaultDisplayTemplate; }); //Keep file template synchronized with selected template this.PropertyChanged += (sender, e) => { if (e.PropertyName == "SelectedDisplayTemplate") { if (mainViewModel.CurrentFile != null) mainViewModel.CurrentFile.DisplayTemplate = SelectedDisplayTemplate; } }; }