From da44aa82136fb9423f041b200b3e40632b8287e7 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 8 Jul 2012 11:25:45 +0000 Subject: [PATCH] WinGui: Add support for keyboard shortcuts. These are slightly different to the old UI. See Below. // Start Encode (Ctrl+S) // Stop Encode (Ctrl+K) // Open Log Window (Ctrl+L) // Open Queue Window (Ctrl+Q) // Add to Queue (Ctrl+A) // Scan a File (Ctrl+F) // Scan a Folder (Ctrl+R) git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4820 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Commands/ProcessShortcutCommand.cs | 111 ++++++++++++++++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 + .../ViewModels/Interfaces/IMainViewModel.cs | 35 ++++++ win/CS/HandBrakeWPF/Views/MainView.xaml.cs | 2 + win/CS/HandBrakeWPF/Views/ShellView.xaml.cs | 20 +++- 5 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 win/CS/HandBrakeWPF/Commands/ProcessShortcutCommand.cs diff --git a/win/CS/HandBrakeWPF/Commands/ProcessShortcutCommand.cs b/win/CS/HandBrakeWPF/Commands/ProcessShortcutCommand.cs new file mode 100644 index 000000000..cc5b546a2 --- /dev/null +++ b/win/CS/HandBrakeWPF/Commands/ProcessShortcutCommand.cs @@ -0,0 +1,111 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Keyboard Shortcut Processor +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Commands +{ + using System; + using System.Windows.Input; + + using Caliburn.Micro; + + using HandBrakeWPF.ViewModels.Interfaces; + + /// + /// Keyboard Shortcut Processor + /// + public class ProcessShortcutCommand : ICommand + { + /// + /// The Gesture + /// + private readonly KeyGesture gesture; + + /// + /// Initializes a new instance of the class. + /// + /// + /// The gesture. + /// + public ProcessShortcutCommand(KeyGesture gesture) + { + this.gesture = gesture; + } + + /// + /// Defines the method to be called when the command is invoked. + /// + /// Data used by the command. If the command does not require data to be passed, this object can be set to null. + public void Execute(object parameter) + { + if (gesture != null) + { + IMainViewModel mainViewModel = IoC.Get(); + + // Start Encode (Ctrl+S) + if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.S) + { + mainViewModel.StartEncode(); + } + + // Stop Encode (Ctrl+K) + if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.K) + { + mainViewModel.StopEncode(); + } + + // Open Log Window (Ctrl+L) + if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.L) + { + mainViewModel.OpenLogWindow(); + } + + // Open Queue Window (Ctrl+Q) + if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.Q) + { + mainViewModel.OpenQueueWindow(); + } + + // Add to Queue (Ctrl+A) + if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.A) + { + mainViewModel.AddToQueue(); + } + + // Scan a File (Ctrl+F) + if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.F) + { + mainViewModel.FileScan(); + } + + // Scan a Folder (Ctrl+R) + if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.R) + { + mainViewModel.FolderScan(); + } + } + } + + /// + /// Defines the method that determines whether the command can execute in its current state. + /// + /// + /// true if this command can be executed; otherwise, false. + /// + /// Data used by the command. If the command does not require data to be passed, this object can be set to null. + public bool CanExecute(object parameter) + { + return true; + } + + /// + /// Can Execute Changed + /// + public event EventHandler CanExecuteChanged; + } +} diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index e8e57eb23..7ef57cd74 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -111,6 +111,7 @@ Designer + Loading.xaml diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs index e9e2c4901..8f1f6e5a6 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs @@ -25,5 +25,40 @@ namespace HandBrakeWPF.ViewModels.Interfaces /// Shutdown the Application /// void ExitApplication(); + + /// + /// Open the Log Window + /// + void OpenLogWindow(); + + /// + /// Open the Queue Window. + /// + void OpenQueueWindow(); + + /// + /// Add the current task to the queue. + /// + void AddToQueue(); + + /// + /// File Scan + /// + void FileScan(); + + /// + /// Folder Scan + /// + void FolderScan(); + + /// + /// Stop an Encode. + /// + void StopEncode(); + + /// + /// Start an Encode + /// + void StartEncode(); } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml.cs b/win/CS/HandBrakeWPF/Views/MainView.xaml.cs index 8b21e2d40..c6bb63568 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml.cs @@ -9,8 +9,10 @@ namespace HandBrakeWPF.Views { + using System; using System.Windows; using System.Windows.Controls; + using System.Windows.Input; /// /// Interaction logic for MainView.xaml diff --git a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs index 6b291702d..9a24120e1 100644 --- a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs @@ -4,13 +4,15 @@ // // // Interaction logic for ShellView.xaml -// +// // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Views { using System.Windows; + using System.Windows.Input; + using HandBrakeWPF.Commands; using HandBrakeWPF.ViewModels.Interfaces; /// @@ -24,6 +26,22 @@ namespace HandBrakeWPF.Views public ShellView() { this.InitializeComponent(); + + // Start Encode (Ctrl+S) + // Stop Encode (Ctrl+K) + // Open Log Window (Ctrl+L) + // Open Queue Window (Ctrl+Q) + // Add to Queue (Ctrl+A) + // Scan a File (Ctrl+F) + // Scan a Folder (Ctrl+R) + + this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.S, ModifierKeys.Control)), new KeyGesture(Key.S, ModifierKeys.Control))); + this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.K, ModifierKeys.Control)), new KeyGesture(Key.K, ModifierKeys.Control))); + this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.L, ModifierKeys.Control)), new KeyGesture(Key.L, ModifierKeys.Control))); + this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.Q, ModifierKeys.Control)), new KeyGesture(Key.Q, ModifierKeys.Control))); + this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.A, ModifierKeys.Control)), new KeyGesture(Key.A, ModifierKeys.Control))); + this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.F, ModifierKeys.Control)), new KeyGesture(Key.F, ModifierKeys.Control))); + this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.R, ModifierKeys.Control)), new KeyGesture(Key.R, ModifierKeys.Control))); } /// -- 2.40.0