/// <summary> /// A KeyHandler method used by SearchView, increments decrements and executes based on input. /// </summary> /// <param name="sender">Originating object for the KeyHandler </param> /// <param name="e">Parameters describing the key push</param> public void KeyHandler(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Escape: { ClearSearchBox(); e.Handled = true; break; } case Key.Enter: { e.Handled = true; if (IsAnySearchResult()) { viewModel.ExecuteSelectedItem(); Keyboard.Focus(SearchTextBox); } break; } case Key.Down: { e.Handled = true; if (IsAnySearchResult()) { viewModel.MoveSelection(SearchViewModel.Direction.Down); } break; } case Key.Up: { e.Handled = true; if (IsAnySearchResult()) { viewModel.MoveSelection(SearchViewModel.Direction.Up); } break; } } }
/// <summary> /// A KeyHandler method used by SearchView, increments decrements and executes based on input. /// </summary> /// <param name="sender">Originating object for the KeyHandler </param> /// <param name="e">Parameters describing the key push</param> public void KeyHandler(object sender, KeyEventArgs e) { // ignore the key command if modifiers are present if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl) || e.KeyboardDevice.IsKeyDown(Key.LeftAlt) || e.KeyboardDevice.IsKeyDown(Key.RightAlt)) { return; } switch (e.Key) { case Key.Delete: if (DynamoSelection.Instance.Selection.Count > 0) { e.Handled = true; dynamoViewModel.DeleteCommand.Execute(null); } //if there are no nodes being selected, the delete key should //delete the text in the search box of library preview else { //if there is no text, then jump out of the switch if (String.IsNullOrEmpty(SearchTextBox.Text)) { break; } else { int cursorPosition = SearchTextBox.SelectionStart; string searchBoxText = SearchTextBox.Text; //if some piece of text is seleceted by users. //delete this piece of text if (SearchTextBox.SelectedText != "") { searchBoxText = searchBoxText.Remove(cursorPosition, SearchTextBox.SelectionLength); } //if there is no text selected, delete the character after the cursor else { //the cursor is at the end of this text string if (cursorPosition == searchBoxText.Length) { break; } else { searchBoxText = searchBoxText.Remove(cursorPosition, 1); } } //update the SearchTextBox's text and the cursor position SearchTextBox.Text = searchBoxText; SearchTextBox.SelectionStart = cursorPosition; } } break; case Key.Enter: { if (viewModel.CurrentMode != SearchViewModel.ViewMode.LibrarySearchView || !viewModel.IsAnySearchResult) { break; } viewModel.ExecuteSelectedItem(); break; } case Key.Down: { if (viewModel.CurrentMode != SearchViewModel.ViewMode.LibrarySearchView || !viewModel.IsAnySearchResult) { break; } viewModel.MoveSelection(SearchViewModel.Direction.Down); break; } case Key.Up: { if (viewModel.CurrentMode != SearchViewModel.ViewMode.LibrarySearchView || !viewModel.IsAnySearchResult) { break; } viewModel.MoveSelection(SearchViewModel.Direction.Up); break; } } }