]> granicus.if.org Git - handbrake/commitdiff
WinGui: Cancel Scan menu option now greyed out when not scan running.
authorsr55 <sr55.hb@outlook.com>
Sun, 30 Sep 2012 14:18:23 +0000 (14:18 +0000)
committersr55 <sr55.hb@outlook.com>
Sun, 30 Sep 2012 14:18:23 +0000 (14:18 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4998 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrakeWPF/Commands/CancelScanCommand.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/Views/MainView.xaml

diff --git a/win/CS/HandBrakeWPF/Commands/CancelScanCommand.cs b/win/CS/HandBrakeWPF/Commands/CancelScanCommand.cs
new file mode 100644 (file)
index 0000000..617778b
--- /dev/null
@@ -0,0 +1,105 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="CancelScanCommand.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   Command to cancel a scan that is in progress\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrakeWPF.Commands\r
+{\r
+    using System;\r
+    using System.Windows.Input;\r
+\r
+    using HandBrake.ApplicationServices.Services.Interfaces;\r
+\r
+    /// <summary>\r
+    /// Command to cancel a scan that is in progress\r
+    /// </summary>\r
+    public class CancelScanCommand : ICommand\r
+    {\r
+        /// <summary>\r
+        /// The scan service wrapper.\r
+        /// </summary>\r
+        private readonly IScanServiceWrapper scanServiceWrapper;\r
+\r
+        /// <summary>\r
+        /// Initializes a new instance of the <see cref="CancelScanCommand"/> class.\r
+        /// </summary>\r
+        /// <param name="ssw">\r
+        /// The scan service wrapper.\r
+        /// </param>\r
+        public CancelScanCommand(IScanServiceWrapper ssw)\r
+        {\r
+            this.scanServiceWrapper = ssw;\r
+            this.scanServiceWrapper.ScanStared += this.ScanServiceWrapperScanStared;\r
+            this.scanServiceWrapper.ScanCompleted += this.ScanServiceWrapperScanCompleted;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The scan service Scan Completed Event Handler.\r
+        /// Fires CanExecuteChanged\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The ScanCompletedEventArgs.\r
+        /// </param>\r
+        private void ScanServiceWrapperScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e)\r
+        {\r
+            Caliburn.Micro.Execute.OnUIThread(() => this.CanExecuteChanged(sender, EventArgs.Empty));    \r
+        }\r
+\r
+        /// <summary>\r
+        /// The scan service scan started event handler.\r
+        /// Fires CanExecuteChanged\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The EventArgs.\r
+        /// </param>\r
+        private void ScanServiceWrapperScanStared(object sender, EventArgs e)\r
+        {\r
+            Caliburn.Micro.Execute.OnUIThread(() => this.CanExecuteChanged(sender, EventArgs.Empty));    \r
+        }\r
+\r
+        #region Implementation of ICommand\r
+\r
+        /// <summary>\r
+        /// Defines the method to be called when the command is invoked.\r
+        /// </summary>\r
+        /// <param name="parameter">Data used by the command.  If the command does not require data to be passed, this object can be set to null.</param>\r
+        public void Execute(object parameter)\r
+        {\r
+            this.scanServiceWrapper.Stop();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Defines the method that determines whether the command can execute in its current state.\r
+        /// </summary>\r
+        /// <returns>\r
+        /// true if this command can be executed; otherwise, false.\r
+        /// </returns>\r
+        /// <param name="parameter">Data used by the command.  If the command does not require data to be passed, this object can be set to null.</param>\r
+        public bool CanExecute(object parameter)\r
+        {\r
+            if (this.scanServiceWrapper != null)\r
+            {\r
+                return this.scanServiceWrapper.IsScanning;\r
+            }\r
+\r
+            return false;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The can execute changed.\r
+        /// </summary>\r
+        public event EventHandler CanExecuteChanged;\r
+\r
+        #endregion\r
+    }\r
+}\r
index bae0eff7a0e6aaffccfd6d09b01e97b17950824c..3597bb0299786b18b1e5f85e75126324ed517872 100644 (file)
       <SubType>Designer</SubType>\r
     </ApplicationDefinition>\r
     <Compile Include="AttachedProperties\MenuItemExtensions.cs" />\r
+    <Compile Include="Commands\CancelScanCommand.cs" />\r
     <Compile Include="Commands\ProcessShortcutCommand.cs" />\r
     <Compile Include="Commands\SourceMenuCommand.cs" />\r
     <Compile Include="Controls\Loading.xaml.cs">\r
index c2aef69edaf4c760159c4c162387137637020777..b68237883b83b4f7dcdbea365719998994ca7703 100644 (file)
@@ -219,6 +219,7 @@ namespace HandBrakeWPF.ViewModels
             this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;\r
 \r
             this.Presets = this.presetService.Presets;\r
+            this.CancelScanCommand = new CancelScanCommand(this.scanService);\r
         }\r
 \r
         #region View Model Properties\r
@@ -609,6 +610,11 @@ namespace HandBrakeWPF.ViewModels
            }\r
         }\r
 \r
+        /// <summary>\r
+        /// Gets or sets the cancel scan command.\r
+        /// </summary>\r
+        public CancelScanCommand CancelScanCommand { get; set; }\r
+\r
         #endregion\r
 \r
         #region Properties for Settings\r
index 0ab5e87b9101a8695cd3317c4a597993b0f978bc..ac40851464889fe5b7b2f3023928242ccb4d15e9 100644 (file)
@@ -95,7 +95,7 @@
                   VerticalAlignment="Top"\r
                   >\r
                 <MenuItem Header="File">\r
-                    <MenuItem Header="Cancel Scan" Micro:Message.Attach="[Event Click] = [Action CancelScan]" />\r
+                    <MenuItem Header="Cancel Scan" Command="{Binding CancelScanCommand}" />\r
                     <Separator />\r
                     <MenuItem Header="Exit" Micro:Message.Attach="[Event Click] = [Action ExitApplication]" />\r
                 </MenuItem>\r