public void HandleShortcut(KeyEventArgs e) { // Create shortcuts dictionary if not initialised. if (shortcuts == null) { shortcuts = new Dictionary <Shortcut, Func <bool> >() { /*{ new Shortcut(key: Keys.Left), () => { if (form.tagSearchTextBox.Focused && form.tagSearchTextBox.Text.Length == 0) DecrementFileIndex(); }}, * { new Shortcut(key: Keys.Right), () => { if (form.tagSearchTextBox.Focused && form.tagSearchTextBox.Text.Length == 0) IncrementFileIndex(); } },*/ { new Shortcut(key: Keys.Left), () => { return(LeftRightKeyShortcut(Keys.Left)); } }, { new Shortcut(key: Keys.Right), () => { return(LeftRightKeyShortcut(Keys.Right)); } }, { new Shortcut(key: Keys.Enter), () => { return(EnterPressed()); } }, //{ new Shortcut(key: Keys.Up), () => { form.SelectNextControl(form.ActiveControl, false, false, false, false); }}, //{ new Shortcut(key: Keys.Down), () => { form.SelectNextControl(form.ActiveControl, true, false, false, false); }}, { new Shortcut(key: Keys.Up), () => { SendKeys.Send("+{TAB}"); return(true); } }, { new Shortcut(key: Keys.Down), () => { SendKeys.Send("{TAB}"); return(true); } }, { new Shortcut(alt: true, key: Keys.Left), () => { form.mediaViewer.VideoPosition -= 0.1f; return(true); } }, { new Shortcut(alt: true, key: Keys.Right), () => { form.mediaViewer.VideoPosition += 0.1f; return(true); } }, { new Shortcut(ctrl: true, key: Keys.D), () => { Delete(); return(true); } }, { new Shortcut(ctrl: true, key: Keys.Z), () => { return(Undo()); } }, { new Shortcut(ctrl: true, key: Keys.Y), () => { return(Redo()); } }, { new Shortcut(ctrl: true, key: Keys.P), () => { return(LoadPreviousTags()); } }, { new Shortcut(ctrl: true, key: Keys.S), () => { Move(null); return(true); } }, //Same as Enter but without checking focus or length of tagSearchTextbox. // Shortcuts to move current file to a subfolder in list (up to 10). { new Shortcut(alt: true, key: Keys.D1), () => { return(MoveFolderShortcut(0)); } }, { new Shortcut(alt: true, key: Keys.D2), () => { return(MoveFolderShortcut(1)); } }, { new Shortcut(alt: true, key: Keys.D3), () => { return(MoveFolderShortcut(2)); } }, { new Shortcut(alt: true, key: Keys.D4), () => { return(MoveFolderShortcut(3)); } }, { new Shortcut(alt: true, key: Keys.D5), () => { return(MoveFolderShortcut(4)); } }, { new Shortcut(alt: true, key: Keys.D6), () => { return(MoveFolderShortcut(5)); } }, { new Shortcut(alt: true, key: Keys.D7), () => { return(MoveFolderShortcut(6)); } }, { new Shortcut(alt: true, key: Keys.D8), () => { return(MoveFolderShortcut(7)); } }, { new Shortcut(alt: true, key: Keys.D9), () => { return(MoveFolderShortcut(8)); } }, { new Shortcut(alt: true, key: Keys.D0), () => { return(MoveFolderShortcut(9)); } }, }; } Shortcut input = new Shortcut(e.Control, e.Alt, e.KeyCode); if (shortcuts.ContainsKey(input)) { bool ok = shortcuts[input].Invoke(); if (ok) { e.Handled = true; e.SuppressKeyPress = true; } else { System.Media.SystemSounds.Beep.Play(); } } bool LeftRightKeyShortcut(Keys key) { if (key != Keys.Left && key != Keys.Right) { throw new ArgumentException("Key must be Left or Right."); } TextBox focusedTextBox = new TextBox[] { form.notesTextBox, form.tagSearchTextBox, form.subfolderSearchTextBox }.Where(t => t.Focused).FirstOrDefault(); if (focusedTextBox != null && focusedTextBox.Text.Length == 0) { if (key == Keys.Left) { return(DecrementFileIndex()); } else { return(IncrementFileIndex()); } } else { return(false); } } bool MoveFolderShortcut(int index) { /*SubfolderButton button = form.subfolderPanel.Controls[0].Controls.OfType<SubfolderButton>().OrderBy(t => t.Location.Y).ElementAt(index); * * if (button != null) * { * form.subfolderPanel.subfolderButton_MouseUp(button, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0)); * }*/ return(form.subfolderPanel.PerformClickOnButton(index)); } /// Handle an enter key press (different depending on what control is focused). bool EnterPressed() { if (form.tagSearchTextBox.Focused) { if (form.tagSearchTextBox.Text.Length == 0) { form.saveButton.PerformClick(); } else if (form.tagSearchTextBox.Text.Length >= Settings.Default.TagSearchStart) { bool aTagWasToggled = form.tagPanel.ToggleFirst(form.tagSearchTextBox.Text); if (aTagWasToggled && Settings.Default.AutoResetTagSearchBox) { form.tagSearchTextBox.Text = ""; } return(aTagWasToggled); } } else if (form.tagCreationTextBox.Focused) { form.addTagButton.PerformClick(); return(true); } else if (form.notesTextBox.Focused) { form.saveButton.PerformClick(); return(true); } else if (form.subfolderSearchTextBox.Focused) { bool success = form.subfolderPanel.PerformClickOnButton(0); if (success) { if (Settings.Default.AutoResetSubfolderSearchBox) { form.subfolderSearchTextBox.Text = String.Empty; return(true); } else { return(false); } } } return(false); } }
public void HandleShortcut(KeyEventArgs e) { // Create shortcuts dictionary if not initialised. if (shortcuts == null) { shortcuts = new Dictionary <Shortcut, Func <bool> >() { //{ new Shortcut(key: Keys.Up), () => { return ChangeMatchesGridViewIndex(-1); }}, //{ new Shortcut(key: Keys.Down), () => { return ChangeMatchesGridViewIndex(+1); }}, { new Shortcut(key: Keys.L), () => { KeepSide(Side.Left); return(true); } }, { new Shortcut(key: Keys.R), () => { KeepSide(Side.Right); return(true); } }, { new Shortcut(key: Keys.B), () => { return(KeepBoth()); } }, { new Shortcut(key: Keys.N), () => { KeepNeither(); return(true); } }, { new Shortcut(ctrl: true, key: Keys.Z), () => { return(Undo()); } }, { new Shortcut(ctrl: true, key: Keys.Y), () => { return(Redo()); } }, }; } Shortcut input = new Shortcut(e.Control, e.Alt, e.KeyCode); if (shortcuts.ContainsKey(input)) { bool ok = shortcuts[input].Invoke(); if (ok) { e.Handled = true; e.SuppressKeyPress = true; } else { System.Media.SystemSounds.Beep.Play(); } } bool KeepBoth() { if (form.matchesDataGridView.Focused) { this.Skip(); return(true); } else { return(false); } } bool ChangeMatchesGridViewIndex(int changeAmount) { int newIndex = form.matchesDataGridView.CurrentCell.RowIndex; if (newIndex >= 0 && newIndex < form.matchesDataGridView.RowCount) { form.matchesDataGridView.CurrentCell = form.matchesDataGridView.Rows[newIndex].Cells[0]; MatchSelectionChanged(); return(true); } else { return(false); } } }