summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-09-30 14:18:23 +0000
committersr55 <[email protected]>2012-09-30 14:18:23 +0000
commitab78d646ad7feb94e534c50f9e6386ba87edd9cb (patch)
tree73dd766b174a49465042284f8032f022e7e32fe2 /win/CS/HandBrakeWPF
parent6b70a7fb55f7b21e3c153c92c5c9186d3b92e3ab (diff)
WinGui: Cancel Scan menu option now greyed out when not scan running.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4998 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r--win/CS/HandBrakeWPF/Commands/CancelScanCommand.cs105
-rw-r--r--win/CS/HandBrakeWPF/HandBrakeWPF.csproj1
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs6
-rw-r--r--win/CS/HandBrakeWPF/Views/MainView.xaml2
4 files changed, 113 insertions, 1 deletions
diff --git a/win/CS/HandBrakeWPF/Commands/CancelScanCommand.cs b/win/CS/HandBrakeWPF/Commands/CancelScanCommand.cs
new file mode 100644
index 000000000..617778b08
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Commands/CancelScanCommand.cs
@@ -0,0 +1,105 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="CancelScanCommand.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Command to cancel a scan that is in progress
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Commands
+{
+ using System;
+ using System.Windows.Input;
+
+ using HandBrake.ApplicationServices.Services.Interfaces;
+
+ /// <summary>
+ /// Command to cancel a scan that is in progress
+ /// </summary>
+ public class CancelScanCommand : ICommand
+ {
+ /// <summary>
+ /// The scan service wrapper.
+ /// </summary>
+ private readonly IScanServiceWrapper scanServiceWrapper;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CancelScanCommand"/> class.
+ /// </summary>
+ /// <param name="ssw">
+ /// The scan service wrapper.
+ /// </param>
+ public CancelScanCommand(IScanServiceWrapper ssw)
+ {
+ this.scanServiceWrapper = ssw;
+ this.scanServiceWrapper.ScanStared += this.ScanServiceWrapperScanStared;
+ this.scanServiceWrapper.ScanCompleted += this.ScanServiceWrapperScanCompleted;
+ }
+
+ /// <summary>
+ /// The scan service Scan Completed Event Handler.
+ /// Fires CanExecuteChanged
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The ScanCompletedEventArgs.
+ /// </param>
+ private void ScanServiceWrapperScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e)
+ {
+ Caliburn.Micro.Execute.OnUIThread(() => this.CanExecuteChanged(sender, EventArgs.Empty));
+ }
+
+ /// <summary>
+ /// The scan service scan started event handler.
+ /// Fires CanExecuteChanged
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs.
+ /// </param>
+ private void ScanServiceWrapperScanStared(object sender, EventArgs e)
+ {
+ Caliburn.Micro.Execute.OnUIThread(() => this.CanExecuteChanged(sender, EventArgs.Empty));
+ }
+
+ #region Implementation of ICommand
+
+ /// <summary>
+ /// Defines the method to be called when the command is invoked.
+ /// </summary>
+ /// <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>
+ public void Execute(object parameter)
+ {
+ this.scanServiceWrapper.Stop();
+ }
+
+ /// <summary>
+ /// Defines the method that determines whether the command can execute in its current state.
+ /// </summary>
+ /// <returns>
+ /// true if this command can be executed; otherwise, false.
+ /// </returns>
+ /// <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>
+ public bool CanExecute(object parameter)
+ {
+ if (this.scanServiceWrapper != null)
+ {
+ return this.scanServiceWrapper.IsScanning;
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// The can execute changed.
+ /// </summary>
+ public event EventHandler CanExecuteChanged;
+
+ #endregion
+ }
+}
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
index bae0eff7a..3597bb029 100644
--- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
@@ -113,6 +113,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AttachedProperties\MenuItemExtensions.cs" />
+ <Compile Include="Commands\CancelScanCommand.cs" />
<Compile Include="Commands\ProcessShortcutCommand.cs" />
<Compile Include="Commands\SourceMenuCommand.cs" />
<Compile Include="Controls\Loading.xaml.cs">
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index c2aef69ed..b68237883 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -219,6 +219,7 @@ namespace HandBrakeWPF.ViewModels
this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;
this.Presets = this.presetService.Presets;
+ this.CancelScanCommand = new CancelScanCommand(this.scanService);
}
#region View Model Properties
@@ -609,6 +610,11 @@ namespace HandBrakeWPF.ViewModels
}
}
+ /// <summary>
+ /// Gets or sets the cancel scan command.
+ /// </summary>
+ public CancelScanCommand CancelScanCommand { get; set; }
+
#endregion
#region Properties for Settings
diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml
index 0ab5e87b9..ac4085146 100644
--- a/win/CS/HandBrakeWPF/Views/MainView.xaml
+++ b/win/CS/HandBrakeWPF/Views/MainView.xaml
@@ -95,7 +95,7 @@
VerticalAlignment="Top"
>
<MenuItem Header="File">
- <MenuItem Header="Cancel Scan" Micro:Message.Attach="[Event Click] = [Action CancelScan]" />
+ <MenuItem Header="Cancel Scan" Command="{Binding CancelScanCommand}" />
<Separator />
<MenuItem Header="Exit" Micro:Message.Attach="[Event Click] = [Action ExitApplication]" />
</MenuItem>