From ab78d646ad7feb94e534c50f9e6386ba87edd9cb Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 30 Sep 2012 14:18:23 +0000 Subject: 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 --- win/CS/HandBrakeWPF/Commands/CancelScanCommand.cs | 105 ++++++++++++++++++++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 + win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 6 ++ win/CS/HandBrakeWPF/Views/MainView.xaml | 2 +- 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 win/CS/HandBrakeWPF/Commands/CancelScanCommand.cs (limited to 'win') 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 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Command to cancel a scan that is in progress +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Commands +{ + using System; + using System.Windows.Input; + + using HandBrake.ApplicationServices.Services.Interfaces; + + /// + /// Command to cancel a scan that is in progress + /// + public class CancelScanCommand : ICommand + { + /// + /// The scan service wrapper. + /// + private readonly IScanServiceWrapper scanServiceWrapper; + + /// + /// Initializes a new instance of the class. + /// + /// + /// The scan service wrapper. + /// + public CancelScanCommand(IScanServiceWrapper ssw) + { + this.scanServiceWrapper = ssw; + this.scanServiceWrapper.ScanStared += this.ScanServiceWrapperScanStared; + this.scanServiceWrapper.ScanCompleted += this.ScanServiceWrapperScanCompleted; + } + + /// + /// The scan service Scan Completed Event Handler. + /// Fires CanExecuteChanged + /// + /// + /// The sender. + /// + /// + /// The ScanCompletedEventArgs. + /// + private void ScanServiceWrapperScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e) + { + Caliburn.Micro.Execute.OnUIThread(() => this.CanExecuteChanged(sender, EventArgs.Empty)); + } + + /// + /// The scan service scan started event handler. + /// Fires CanExecuteChanged + /// + /// + /// The sender. + /// + /// + /// The EventArgs. + /// + private void ScanServiceWrapperScanStared(object sender, EventArgs e) + { + Caliburn.Micro.Execute.OnUIThread(() => this.CanExecuteChanged(sender, EventArgs.Empty)); + } + + #region Implementation of ICommand + + /// + /// 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) + { + this.scanServiceWrapper.Stop(); + } + + /// + /// 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) + { + if (this.scanServiceWrapper != null) + { + return this.scanServiceWrapper.IsScanning; + } + + return false; + } + + /// + /// The can execute changed. + /// + 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 @@ Designer + 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 } } + /// + /// Gets or sets the cancel scan command. + /// + 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" > - + -- cgit v1.2.3