From 5637aa1f74bfc67b5cec29c4aa10decd23c04173 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Thu, 6 Dec 2018 18:39:35 +0100 Subject: [PATCH] Replace DelegateCommand by RelayCommand from MVVC framework --- .../FileConverter/Commands/DelegateCommand.cs | 46 ------------------- .../FileConverter/FileConverter.csproj | 1 - .../FileConverter/ViewModels/HelpViewModel.cs | 5 +- .../FileConverter/ViewModels/MainViewModel.cs | 12 +++-- .../ViewModels/SettingsViewModel.cs | 4 +- .../ViewModels/UpgradeViewModel.cs | 9 ++-- 6 files changed, 17 insertions(+), 60 deletions(-) delete mode 100644 Application/FileConverter/Commands/DelegateCommand.cs diff --git a/Application/FileConverter/Commands/DelegateCommand.cs b/Application/FileConverter/Commands/DelegateCommand.cs deleted file mode 100644 index 31569ca..0000000 --- a/Application/FileConverter/Commands/DelegateCommand.cs +++ /dev/null @@ -1,46 +0,0 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. - -namespace FileConverter.Commands -{ - using System; - using System.Windows.Input; - - public class DelegateCommand : ICommand - { - private Action executeMethod; - private Func canExecuteMethod; - - public DelegateCommand(Action executeMethod) - { - if (executeMethod == null) - { - throw new ArgumentNullException(nameof(executeMethod)); - } - - this.executeMethod = executeMethod; - } - - public DelegateCommand(Action executeMethod, Func canExecuteMethod) - { - this.executeMethod = executeMethod; - this.canExecuteMethod = canExecuteMethod; - } - - public event EventHandler CanExecuteChanged; - - public bool CanExecute(object parameter) - { - if (this.canExecuteMethod != null) - { - return this.canExecuteMethod.Invoke(); - } - - return true; - } - - public void Execute(object parameter) - { - this.executeMethod.Invoke(); - } - } -} \ No newline at end of file diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 62c485e..1bdb67d 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -136,7 +136,6 @@ Designer - ConversionJobControl.xaml diff --git a/Application/FileConverter/ViewModels/HelpViewModel.cs b/Application/FileConverter/ViewModels/HelpViewModel.cs index e45440f..eb1445c 100644 --- a/Application/FileConverter/ViewModels/HelpViewModel.cs +++ b/Application/FileConverter/ViewModels/HelpViewModel.cs @@ -11,6 +11,7 @@ namespace FileConverter.ViewModels using FileConverter.Services; using GalaSoft.MvvmLight; + using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; /// @@ -27,7 +28,7 @@ namespace FileConverter.ViewModels /// public class HelpViewModel : ViewModelBase { - private DelegateCommand quitCommand; + private RelayCommand quitCommand; /// /// Initializes a new instance of the HelpViewModel class. @@ -49,7 +50,7 @@ namespace FileConverter.ViewModels { if (this.quitCommand == null) { - this.quitCommand = new DelegateCommand(() => System.Windows.Application.Current.Shutdown()); + this.quitCommand = new RelayCommand(() => System.Windows.Application.Current.Shutdown()); } return this.quitCommand; diff --git a/Application/FileConverter/ViewModels/MainViewModel.cs b/Application/FileConverter/ViewModels/MainViewModel.cs index 5d766bd..7b7b0e3 100644 --- a/Application/FileConverter/ViewModels/MainViewModel.cs +++ b/Application/FileConverter/ViewModels/MainViewModel.cs @@ -10,6 +10,7 @@ namespace FileConverter.ViewModels using FileConverter.Services; using GalaSoft.MvvmLight; + using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; /// @@ -29,7 +30,8 @@ namespace FileConverter.ViewModels private string informationMessage; private ObservableCollection conversionJobs; - private DelegateCommand showSettingsCommand; + private RelayCommand showSettingsCommand; + private RelayCommand showDiagnosticsCommand; /// /// Initializes a new instance of the MainViewModel class. @@ -90,7 +92,7 @@ namespace FileConverter.ViewModels { if (this.showSettingsCommand == null) { - this.showSettingsCommand = new DelegateCommand(() => SimpleIoc.Default.GetInstance().NavigateTo(Pages.Settings)); + this.showSettingsCommand = new RelayCommand(() => SimpleIoc.Default.GetInstance().NavigateTo(Pages.Settings)); } return this.showSettingsCommand; @@ -101,12 +103,12 @@ namespace FileConverter.ViewModels { get { - if (this.showSettingsCommand == null) + if (this.showDiagnosticsCommand == null) { - this.showSettingsCommand = new DelegateCommand(() => SimpleIoc.Default.GetInstance().NavigateTo(Pages.Diagnostics)); + this.showDiagnosticsCommand = new RelayCommand(() => SimpleIoc.Default.GetInstance().NavigateTo(Pages.Diagnostics)); } - return this.showSettingsCommand; + return this.showDiagnosticsCommand; } } diff --git a/Application/FileConverter/ViewModels/SettingsViewModel.cs b/Application/FileConverter/ViewModels/SettingsViewModel.cs index 4b0a4c7..570534f 100644 --- a/Application/FileConverter/ViewModels/SettingsViewModel.cs +++ b/Application/FileConverter/ViewModels/SettingsViewModel.cs @@ -45,7 +45,7 @@ namespace FileConverter.ViewModels private bool displaySeeChangeLogLink = true; private OpenUrlCommand openUrlCommand; - private DelegateCommand getChangeLogContentCommand; + private RelayCommand getChangeLogContentCommand; private RelayCommand movePresetUpCommand; private RelayCommand movePresetDownCommand; private RelayCommand addNewPresetCommand; @@ -223,7 +223,7 @@ namespace FileConverter.ViewModels { if (this.getChangeLogContentCommand == null) { - this.getChangeLogContentCommand = new DelegateCommand(this.DownloadChangeLogAction); + this.getChangeLogContentCommand = new RelayCommand(this.DownloadChangeLogAction); } return this.getChangeLogContentCommand; diff --git a/Application/FileConverter/ViewModels/UpgradeViewModel.cs b/Application/FileConverter/ViewModels/UpgradeViewModel.cs index 394db32..faa833d 100644 --- a/Application/FileConverter/ViewModels/UpgradeViewModel.cs +++ b/Application/FileConverter/ViewModels/UpgradeViewModel.cs @@ -11,6 +11,7 @@ namespace FileConverter.ViewModels using FileConverter.Services; using GalaSoft.MvvmLight; + using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; /// @@ -30,8 +31,8 @@ namespace FileConverter.ViewModels private UpgradeVersionDescription upgradeVersionDescription; private string releaseNoteContent; - private DelegateCommand downloadInstallerCommand; - private DelegateCommand launchInstallerCommand; + private RelayCommand downloadInstallerCommand; + private RelayCommand launchInstallerCommand; /// /// Initializes a new instance of the UpgradeViewModel class. @@ -59,7 +60,7 @@ namespace FileConverter.ViewModels { if (this.downloadInstallerCommand == null) { - this.downloadInstallerCommand = new DelegateCommand(this.ExecuteDownloadInstallerCommand); + this.downloadInstallerCommand = new RelayCommand(this.ExecuteDownloadInstallerCommand); } return this.downloadInstallerCommand; @@ -72,7 +73,7 @@ namespace FileConverter.ViewModels { if (this.launchInstallerCommand == null) { - this.launchInstallerCommand = new DelegateCommand(this.ExecuteLaunchInstallerCommand); + this.launchInstallerCommand = new RelayCommand(this.ExecuteLaunchInstallerCommand); } return this.launchInstallerCommand;