private void MoveCustomCaret() { var caretLocation = SearchKeywordBox.GetRectFromCharacterIndex(SearchKeywordBox.CaretIndex).Location; if (!double.IsInfinity(caretLocation.X)) { Canvas.SetLeft(Caret, caretLocation.X); } if (!double.IsInfinity(caretLocation.Y)) { Canvas.SetTop(Caret, caretLocation.Y); } }
// App-wise Short cut setup // http://stackoverflow.com/questions/4682915/defining-menuitem-shortcuts // http://stackoverflow.com/questions/3574405/c-wpf-implement-keyboard-shortcuts // https://social.msdn.microsoft.com/Forums/vstudio/en-US/2b2121f9-ef4e-4e38-8442-763f608e1837/how-to-create-keyboard-shortcuts-in-wpf?forum=wpf input bindings // Also see personal WPF notes private void HandleKeyDownEvent(object sender, KeyEventArgs e) { // Example: if (e.Key == Key.H && (Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift)) // Ctrl-H Open Home Folder (Application Home) if (e.Key == Key.H && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "\\" + App.UserHome); e.Handled = true; } // ESC: Hide Application (Minimize) if (e.Key == Key.Escape) { this.WindowState = WindowState.Minimized; e.Handled = true; } // Ctrl-O: Load JSON file shortcut: I know this is a bit not so professional but WHY I CANNOT FIND MY VS PROJECT for 墨迹笔记?! if (e.Key == Key.O && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { LoadJSONFile_MouseDown(null, null); e.Handled = true; } // Ctrl-F: Search if (e.Key == Key.F && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { Keyboard.Focus(SearchKeywordBox); SearchKeywordBox.SelectAll(); e.Handled = true; } // Ctrl/Shift/Alt-P: Open previously opened file if (e.Key == Key.P) { // If used SHIFT then open file location if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) { OpenFolderForInspection(PreviousOpenFile.Parent); e.Handled = true; } // If used Alt to open properties else if ((Keyboard.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt) { SystemInterpService.ShowFileProperties(App.GetParentFolderPath(PreviousOpenFile.Parent) + PreviousOpenFile.FileName); e.Handled = true; } // Otherwise just open file else if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { OpenFileForEditing(PreviousOpenFile); e.Handled = true; } } // F1: File Mode if (e.Key == Key.F1) { if (CurrentSearchMode == ContentSearchMode.SingleFile) { UpdateSearchMode(ContentSearchMode.MultiFile); } else { FolderCheckBox.IsChecked = false; // Notice when the state of check box changes it will trigger its checked/unchecked handler where we have already set the value UpdateSearchMode(ContentSearchMode.SingleFile); } e.Handled = true; } // F2: Folder Mode if (e.Key == Key.F2) { if (CurrentSearchMode == ContentSearchMode.SingleFolder) { UpdateSearchMode(ContentSearchMode.MultiFolder); } else { FolderCheckBox.IsChecked = true; UpdateSearchMode(ContentSearchMode.SingleFolder); } e.Handled = true; } // F3: Airi on/off if (e.Key == Key.F3) { if (CurrentAiriMode == AiriMode.Activated) { UpdateAiriMode(AiriMode.Disabled); voiceEngine.Deactivate(); } else { UpdateAiriMode(AiriMode.Activated); voiceEngine.Activate(); } e.Handled = true; } // F4: Dictionary Mode }