public void Merge(InputKeyBindings updates)
 {
     foreach (var property in GetType().GetProperties())
     {
         var updatedProperty = updates.GetType().GetProperty(property.Name);
         if (updatedProperty != null)
         {
             property.SetValue(this, updatedProperty.GetValue(updates, null), null);
         }
     }
 }
Example #2
0
        public static void Update()
        {
            var mergedBindings = new InputKeyBindings();

            try
            {
                mergedBindings.Merge(Load());
            }
            catch (Exception ex)
            {
                Utility.ShowParseError(ex, KeyBindingFile);
                return;
            }

            var collection = Application.Current.MainWindow.InputBindings;

            collection.Clear();

            Action <ICommand, string> keyBinding = (command, gesture) =>
                                                   collection.Add(new KeyBinding(command, (KeyGesture) new KeyGestureConverter().ConvertFromString(gesture)));

            Action <ICommand, string, object> keyBindingPar = (command, gesture, parameter) =>
                                                              collection.Add(new KeyBinding(command, (KeyGesture) new KeyGestureConverter().ConvertFromString(gesture))
            {
                CommandParameter = parameter
            });

            keyBinding(EditingCommands.ToggleBold, mergedBindings.ToggleBold);
            keyBinding(EditingCommands.ToggleItalic, mergedBindings.ToggleItalic);
            keyBinding(MainWindow.ToggleCodeCommand, mergedBindings.ToggleCode);
            keyBinding(ApplicationCommands.SaveAs, mergedBindings.SaveAs);
            keyBinding(MainWindow.ToggleWordWrapCommand, mergedBindings.ToggleWordWrap);
            keyBinding(MainWindow.FindNextCommand, mergedBindings.FindNext);
            keyBinding(MainWindow.FindPreviousCommand, mergedBindings.FindPrevious);
            keyBindingPar(MainWindow.InsertHeaderCommand, mergedBindings.InsertHeader1, "1");
            keyBindingPar(MainWindow.InsertHeaderCommand, mergedBindings.InsertHeader2, "2");
            keyBindingPar(MainWindow.InsertHeaderCommand, mergedBindings.InsertHeader3, "3");
            keyBindingPar(MainWindow.InsertHeaderCommand, mergedBindings.InsertHeader4, "4");
            keyBindingPar(MainWindow.InsertHeaderCommand, mergedBindings.InsertHeader5, "5");
            keyBindingPar(MainWindow.InsertHeaderCommand, mergedBindings.InsertHeader6, "6");
            keyBinding(EditingCommands.IncreaseFontSize, mergedBindings.IncreaseFontSize);
            keyBinding(EditingCommands.DecreaseFontSize, mergedBindings.DecreaseFontSize);
            keyBinding(MainWindow.RestoreFontSizeCommand, mergedBindings.RestoreFontSize);
            keyBinding(MainWindow.OpenUserSnippetsCommand, mergedBindings.OpenUserSnippets);
            keyBinding(MainWindow.OpenUserDictionaryCommand, mergedBindings.OpenUserDictionary);
            keyBinding(MainWindow.ToggleSpellCheckCommand, mergedBindings.ToggleSpellCheck);
            keyBinding(MainWindow.OpenUserTemplateCommand, mergedBindings.OpenUserTemplate);
            keyBinding(MainWindow.OpenUserSettingsCommand, mergedBindings.OpenUserSettings);
            keyBinding(MainWindow.OpenKeybindingSettingsCommand, mergedBindings.OpenKeyBindingSettings);
            keyBinding(MainWindow.ToggleFullScreenCommand, mergedBindings.ToggleFullScreen);
            keyBinding(MainWindow.TogglePreviewCommand, mergedBindings.TogglePreview);
            keyBinding(MainWindow.RecentFilesCommand, mergedBindings.RecentFiles);
            keyBinding(MainWindow.PasteSpecialCommand, mergedBindings.PasteSpecial);
            keyBinding(MainWindow.ShowThemeDialogCommand, mergedBindings.ShowThemeDialog);
            keyBinding(MainWindow.ExportHtmlCommand, mergedBindings.ExportHtml);
            keyBinding(MainWindow.ExportHtmlTemplateCommand, mergedBindings.ExportHtmlTemplate);
            keyBinding(MainWindow.ShowGotoLineDialogCommand, mergedBindings.ShowGotoLineDialog);
            keyBinding(MainWindow.ToggleAutoSaveCommand, mergedBindings.ToggleAutoSave);
            keyBinding(MainWindow.SelectPreviousHeaderCommand, mergedBindings.SelectPreviousHeader);
            keyBinding(MainWindow.SelectNextHeaderCommand, mergedBindings.SelectNextHeader);
            keyBinding(MainWindow.OpenNewInstanceCommand, mergedBindings.OpenNewInstance);
            keyBinding(MainWindow.InsertFileCommand, mergedBindings.InsertFile);
        }
Example #3
0
 private static void Save(InputKeyBindings keyBindings)
 {
     File.WriteAllText(KeyBindingFile, JsonConvert.SerializeObject(keyBindings, Formatting.Indented));
 }