diff --git a/src/Commands/ActionCommand.cs b/src/Commands/ActionCommand.cs deleted file mode 100644 index a32436d4..00000000 --- a/src/Commands/ActionCommand.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Windows.Input; - -namespace COMPASS.Commands -{ - /// - /// Command for methods without arguments - /// - public class ActionCommand : ICommand - { - readonly Action _execute; - private readonly Func? _canExecute; - - public event EventHandler? CanExecuteChanged - { - add => CommandManager.RequerySuggested += value; - remove => CommandManager.RequerySuggested -= value; - } - - public ActionCommand(Action execute, Func? canExecute = null) - { - _execute = execute; - _canExecute = canExecute; - } - - public bool CanExecute(object? parameter) => _canExecute == null || _canExecute(); - - public void Execute(object? parameter) => _execute.Invoke(); - } -} diff --git a/src/Commands/RelayCommand.cs b/src/Commands/RelayCommand.cs deleted file mode 100644 index 7e4b66f1..00000000 --- a/src/Commands/RelayCommand.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Windows.Input; - -namespace COMPASS.Commands -{ - /// - /// Command for methods that take one argument - /// - /// Type of function argument - public class RelayCommand : ICommand - { - private readonly Action _execute; - private readonly Func? _canExecute; - - public event EventHandler? CanExecuteChanged - { - add => CommandManager.RequerySuggested += value; - remove => CommandManager.RequerySuggested -= value; - } - - public RelayCommand(Action execute, Func? canExecute = null) - { - _execute = execute; - _canExecute = canExecute; - } - - public bool CanExecute(object? parameter) => _canExecute == null || _canExecute((T?)parameter); - - public void Execute(object? parameter) => _execute.Invoke((T?)parameter); - } -} diff --git a/src/Commands/ReturningRelayCommand.cs b/src/Commands/ReturningRelayCommand.cs deleted file mode 100644 index 7feefa73..00000000 --- a/src/Commands/ReturningRelayCommand.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Windows.Input; - -namespace COMPASS.Commands -{ - //Relay command that works with functions that return bool - //to for example indicate success of execution - /// - /// Command for methods that take one argument and return bool that indicates success - /// - /// Type of function argument - /// Type of return value - public class ReturningRelayCommand : ICommand - { - private readonly Func _execute; - private readonly Func? _canExecute; - - public event EventHandler? CanExecuteChanged - { - add => CommandManager.RequerySuggested += value; - remove => CommandManager.RequerySuggested -= value; - } - - public ReturningRelayCommand(Func execute, Func? canExecute = null) - { - _execute = execute; - _canExecute = canExecute; - } - - public bool CanExecute(object? parameter) => _canExecute == null || _canExecute((T?)parameter); - - public void Execute(object? parameter) => _execute((T?)parameter); - } -} diff --git a/src/ViewModels/CodexBulkEditViewModel.cs b/src/ViewModels/CodexBulkEditViewModel.cs index 0fef97f0..d8416c9a 100644 --- a/src/ViewModels/CodexBulkEditViewModel.cs +++ b/src/ViewModels/CodexBulkEditViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Resources.Controls.MultiSelectCombobox; using COMPASS.Tools; @@ -107,8 +107,8 @@ private void RemoveTagFromItemsControl(Tag? t) public Action CloseAction { get; set; } = () => { }; - private ActionCommand? _okCommand; - public ActionCommand OKCommand => _okCommand ??= new(OKBtn); + private RelayCommand? _okCommand; + public RelayCommand OKCommand => _okCommand ??= new(OKBtn); public void OKBtn() { //Copy changes into each Codex @@ -184,8 +184,8 @@ public void OKBtn() CloseAction(); } - private ActionCommand? _cancelCommand; - public ActionCommand CancelCommand => _cancelCommand ??= new(Cancel); + private RelayCommand? _cancelCommand; + public RelayCommand CancelCommand => _cancelCommand ??= new(Cancel); public void Cancel() => CloseAction(); #endregion diff --git a/src/ViewModels/CodexEditViewModel.cs b/src/ViewModels/CodexEditViewModel.cs index ecf6bdbf..003a8812 100644 --- a/src/ViewModels/CodexEditViewModel.cs +++ b/src/ViewModels/CodexEditViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Resources.Controls.MultiSelectCombobox; using COMPASS.Services; @@ -66,8 +66,8 @@ public bool ShowLoading #region Methods and Commands - private ActionCommand? _browsePathCommand; - public ActionCommand BrowsePathCommand => _browsePathCommand ??= new(BrowsePath); + private RelayCommand? _browsePathCommand; + public RelayCommand BrowsePathCommand => _browsePathCommand ??= new(BrowsePath); private void BrowsePath() { OpenFileDialog openFileDialog = new() @@ -81,8 +81,8 @@ private void BrowsePath() } } - private ActionCommand? _browseURLCommand; - public ActionCommand BrowseURLCommand => _browseURLCommand ??= new(BrowseURL); + private RelayCommand? _browseURLCommand; + public RelayCommand BrowseURLCommand => _browseURLCommand ??= new(BrowseURL); private void BrowseURL() { if (CodexViewModel.CanOpenCodexOnline(TempCodex)) @@ -91,16 +91,16 @@ private void BrowseURL() } } - private ActionCommand? _browseISBNCommand; - public ActionCommand BrowseISBNCommand => _browseISBNCommand ??= new(BrowseISBN); + private RelayCommand? _browseISBNCommand; + public RelayCommand BrowseISBNCommand => _browseISBNCommand ??= new(BrowseISBN); private void BrowseISBN() { string url = $"https://openlibrary.org/search?q={TempCodex.ISBN}&mode=everything"; Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); } - private ActionCommand? _tagCheckCommand; - public ActionCommand TagCheckCommand => _tagCheckCommand ??= new(UpdateTagList); + private RelayCommand? _tagCheckCommand; + public RelayCommand TagCheckCommand => _tagCheckCommand ??= new(UpdateTagList); private void UpdateTagList() { TempCodex.Tags.Clear(); @@ -113,8 +113,8 @@ private void UpdateTagList() } } - private ActionCommand? _quickCreateTagCommand; - public ActionCommand QuickCreateTagCommand => _quickCreateTagCommand ??= new(QuickCreateTag); + private RelayCommand? _quickCreateTagCommand; + public RelayCommand QuickCreateTagCommand => _quickCreateTagCommand ??= new(QuickCreateTag); public void QuickCreateTag() { //keep track of count to check of tags were created @@ -148,8 +148,8 @@ public void QuickCreateTag() } } - private ActionCommand? _deleteCodexCommand; - public ActionCommand DeleteCodexCommand => _deleteCodexCommand ??= new(DeleteCodex); + private RelayCommand? _deleteCodexCommand; + public RelayCommand DeleteCodexCommand => _deleteCodexCommand ??= new(DeleteCodex); private void DeleteCodex() { if (!CreateNewCodex) @@ -159,8 +159,8 @@ private void DeleteCodex() CloseAction(); } - private ActionCommand? _fetchCoverCommand; - public ActionCommand FetchCoverCommand => _fetchCoverCommand ??= new(async () => await FetchCoverAsync()); + private AsyncRelayCommand? _fetchCoverCommand; + public AsyncRelayCommand FetchCoverCommand => _fetchCoverCommand ??= new(FetchCoverAsync); private async Task FetchCoverAsync() { ShowLoading = true; @@ -177,8 +177,8 @@ private async Task FetchCoverAsync() RefreshCover(); } - private ActionCommand? _chooseCoverCommand; - public ActionCommand ChooseCoverCommand => _chooseCoverCommand ??= new(ChooseCover); + private RelayCommand? _chooseCoverCommand; + public RelayCommand ChooseCoverCommand => _chooseCoverCommand ??= new(ChooseCover); private void ChooseCover() { OpenFileDialog openFileDialog = new() @@ -207,8 +207,8 @@ private void RefreshCover() public Action CloseAction { get; set; } = () => { }; - private ActionCommand? _oKCommand; - public ActionCommand OKCommand => _oKCommand ??= new(OKBtn); + private RelayCommand? _oKCommand; + public RelayCommand OKCommand => _oKCommand ??= new(OKBtn); public void OKBtn() { //Copy changes into Codex @@ -231,8 +231,8 @@ public void OKBtn() CloseAction(); } - private ActionCommand? _cancelCommand; - public ActionCommand CancelCommand => _cancelCommand ??= new(Cancel); + private RelayCommand? _cancelCommand; + public RelayCommand CancelCommand => _cancelCommand ??= new(Cancel); public void Cancel() => CloseAction(); diff --git a/src/ViewModels/CodexInfoViewModel.cs b/src/ViewModels/CodexInfoViewModel.cs index 225a538c..1ed5d3b4 100644 --- a/src/ViewModels/CodexInfoViewModel.cs +++ b/src/ViewModels/CodexInfoViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; namespace COMPASS.ViewModels @@ -38,8 +38,8 @@ public bool AutoHide } } - private ActionCommand? _toggleCodexInfoCommand; - public ActionCommand ToggleCodexInfoCommand => _toggleCodexInfoCommand ??= new(() => ShowCodexInfo = !ShowCodexInfo); + private RelayCommand? _toggleCodexInfoCommand; + public RelayCommand ToggleCodexInfoCommand => _toggleCodexInfoCommand ??= new(() => ShowCodexInfo = !ShowCodexInfo); private RelayCommand? _addAuthorFilterCommand; public RelayCommand AddAuthorFilterCommand => _addAuthorFilterCommand ??= new(AddAuthorFilter); diff --git a/src/ViewModels/CodexViewModel.cs b/src/ViewModels/CodexViewModel.cs index b52d1d8a..5f795126 100644 --- a/src/ViewModels/CodexViewModel.cs +++ b/src/ViewModels/CodexViewModel.cs @@ -1,5 +1,5 @@ using Autofac; -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Services; using COMPASS.Tools; @@ -36,8 +36,8 @@ public static bool OpenCodex(Codex codex) } //Open codex Offline - private ReturningRelayCommand? _openCodexLocallyCommand; - public ReturningRelayCommand OpenCodexLocallyCommand => _openCodexLocallyCommand ??= new(OpenCodexLocally, CanOpenCodexLocally); + private RelayCommand? _openCodexLocallyCommand; + public RelayCommand OpenCodexLocallyCommand => _openCodexLocallyCommand ??= new(codex => OpenCodexLocally(codex), CanOpenCodexLocally); public static bool OpenCodexLocally(Codex? toOpen) { if (toOpen is null) return false; @@ -69,8 +69,8 @@ public static bool CanOpenCodexLocally(Codex? toOpen) } //Open codex Online - private ReturningRelayCommand? _openCodexOnlineCommand; - public ReturningRelayCommand OpenCodexOnlineCommand => _openCodexOnlineCommand ??= new(OpenCodexOnline, CanOpenCodexOnline); + private RelayCommand? _openCodexOnlineCommand; + public RelayCommand OpenCodexOnlineCommand => _openCodexOnlineCommand ??= new(codex => OpenCodexOnline(codex), CanOpenCodexOnline); public static bool OpenCodexOnline(Codex? toOpen) { if (!CanOpenCodexOnline(toOpen)) return false; @@ -99,8 +99,8 @@ public static bool CanOpenCodexOnline(Codex? toOpen) } //Open Multiple Files - private ReturningRelayCommand? _openSelectedCodicesCommand; - public ReturningRelayCommand OpenSelectedCodicesCommand => _openSelectedCodicesCommand ??= new(l => OpenSelectedCodices(l?.Cast().ToList())); + private RelayCommand? _openSelectedCodicesCommand; + public RelayCommand OpenSelectedCodicesCommand => _openSelectedCodicesCommand ??= new(l => OpenSelectedCodices(l?.Cast().ToList())); public static bool OpenSelectedCodices(IList? toOpen) { if (toOpen is null) return false; @@ -342,26 +342,8 @@ public static void BanishCodices(IList? toBanish) DeleteCodices(toBanish); } - private ReturningRelayCommand? _getMetaDataCommand; - public ReturningRelayCommand GetMetaDataCommand => _getMetaDataCommand ??= new(StartGetMetaDataProcess); - - - private ReturningRelayCommand? _getMetaDataBulkCommand; - public ReturningRelayCommand GetMetaDataBulkCommand => _getMetaDataBulkCommand ??= new( - async codices => - { - try - { - await StartGetMetaDataProcess(codices?.Cast().ToList() ?? new()); - } - catch (OperationCanceledException ex) - { - Logger.Warn("Renewing metadata has been cancelled", ex); - await Task.Run(() => ProgressViewModel.GetInstance().ConfirmCancellation()); - } - } - ); - + private AsyncRelayCommand? _getMetaDataCommand; + public AsyncRelayCommand GetMetaDataCommand => _getMetaDataCommand ??= new(StartGetMetaDataProcess); public static async Task StartGetMetaDataProcess(Codex? codex) { try @@ -375,7 +357,6 @@ public static async Task StartGetMetaDataProcess(Codex? codex) await Task.Run(() => ProgressViewModel.GetInstance().ConfirmCancellation()); } } - public static async Task StartGetMetaDataProcess(IList codices) { var progressVM = ProgressViewModel.GetInstance(); @@ -402,7 +383,6 @@ public static async Task StartGetMetaDataProcess(IList codices) MainViewModel.CollectionVM.CurrentCollection.Save(); MainViewModel.CollectionVM.FilterVM.ReFilter(); } - private static async Task GetMetaData(Codex codex, ChooseMetaDataViewModel chooseMetaDataVM) { // Lazy load metadata from all the sources, use dict to store @@ -499,17 +479,34 @@ private static async Task GetMetaData(Codex codex, ChooseMetaDataViewModel choos ProgressViewModel.GetInstance().IncrementCounter(); } - private ReturningRelayCommand? _getCoverCommand; - public ReturningRelayCommand GetCoverCommand => _getCoverCommand ??= - new(async codex => + private AsyncRelayCommand? _getMetaDataBulkCommand; + public AsyncRelayCommand GetMetaDataBulkCommand => _getMetaDataBulkCommand ??= new(GetMetaDataBulk); + + private static async Task GetMetaDataBulk(IList? codices) + { + try + { + await StartGetMetaDataProcess(codices?.Cast().ToList() ?? new()); + } + catch (OperationCanceledException ex) { - if (codex is null) return; - await CoverService.GetCover(new List() { codex }); - }); + Logger.Warn("Renewing metadata has been cancelled", ex); + await Task.Run(() => ProgressViewModel.GetInstance().ConfirmCancellation()); + } + } + + private AsyncRelayCommand? _getCoverCommand; + public AsyncRelayCommand GetCoverCommand => _getCoverCommand ??= new(GetCover); + private static async Task GetCover(Codex? codex) + { + if (codex is null) return; + await CoverService.GetCover(new List() { codex }); + } - private ReturningRelayCommand? _getCoverBulkCommand; - public ReturningRelayCommand GetCoverBulkCommand => _getCoverBulkCommand ??= - new(async codices => await CoverService.GetCover(codices?.Cast().ToList() ?? new())); + private AsyncRelayCommand? _getCoverBulkCommand; + public AsyncRelayCommand GetCoverBulkCommand => _getCoverBulkCommand ??= new(GetCoverBulk); + private static async Task GetCoverBulk(IList? codices) => + await CoverService.GetCover(codices?.Cast().ToList() ?? new()); public static void DataGridHandleKeyDown(object sender, KeyEventArgs e) => HandleKeyDownOnCodex(((DataGrid)sender).SelectedItems, e); diff --git a/src/ViewModels/CollectionContentSelectorViewModel.cs b/src/ViewModels/CollectionContentSelectorViewModel.cs index b1f5f16d..7c924838 100644 --- a/src/ViewModels/CollectionContentSelectorViewModel.cs +++ b/src/ViewModels/CollectionContentSelectorViewModel.cs @@ -1,5 +1,5 @@ using CommunityToolkit.Mvvm.ComponentModel; -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Tools; using System.Collections; diff --git a/src/ViewModels/CollectionViewModel.cs b/src/ViewModels/CollectionViewModel.cs index b12ee1e0..2f346502 100644 --- a/src/ViewModels/CollectionViewModel.cs +++ b/src/ViewModels/CollectionViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Properties; using COMPASS.Services; @@ -229,18 +229,18 @@ public async Task Refresh() await AutoImport(); } - private ActionCommand? _toggleCreateCollectionCommand; - public ActionCommand ToggleCreateCollectionCommand => _toggleCreateCollectionCommand ??= new(ToggleCreateCollection); + private RelayCommand? _toggleCreateCollectionCommand; + public RelayCommand ToggleCreateCollectionCommand => _toggleCreateCollectionCommand ??= new(ToggleCreateCollection); private void ToggleCreateCollection() => CreateCollectionVisibility = !CreateCollectionVisibility; - private ActionCommand? _toggleEditCollectionCommand; - public ActionCommand ToggleEditCollectionCommand => _toggleEditCollectionCommand ??= new(ToggleEditCollection); + private RelayCommand? _toggleEditCollectionCommand; + public RelayCommand ToggleEditCollectionCommand => _toggleEditCollectionCommand ??= new(ToggleEditCollection); private void ToggleEditCollection() => EditCollectionVisibility = !EditCollectionVisibility; // Create CodexCollection - private ReturningRelayCommand? _createCollectionCommand; - public ReturningRelayCommand CreateCollectionCommand => - _createCollectionCommand ??= new(CreateAndLoadCollection, IsLegalCollectionName); + private RelayCommand? _createCollectionCommand; + public RelayCommand CreateCollectionCommand => + _createCollectionCommand ??= new(name => CreateAndLoadCollection(name), IsLegalCollectionName); public CodexCollection? CreateAndLoadCollection(string? dirName) { if (dirName == null) @@ -305,8 +305,8 @@ public void EditCollectionName(string? newName) } // Delete Collection - private ActionCommand? _deleteCollectionCommand; - public ActionCommand DeleteCollectionCommand => _deleteCollectionCommand ??= new(RaiseDeleteCollectionWarning); + private RelayCommand? _deleteCollectionCommand; + public RelayCommand DeleteCollectionCommand => _deleteCollectionCommand ??= new(RaiseDeleteCollectionWarning); public void RaiseDeleteCollectionWarning() { if (CurrentCollection.AllCodices.Count > 0) @@ -351,8 +351,8 @@ public void DeleteCollection(CodexCollection toDelete) } //Export Collection - private ActionCommand? _exportCommand; - public ActionCommand ExportCommand => _exportCommand ??= new(Export); + private RelayCommand? _exportCommand; + public RelayCommand ExportCommand => _exportCommand ??= new(Export); public void Export() { //open wizard @@ -361,8 +361,8 @@ public void Export() wizard.Show(); } - private ActionCommand? _exportTagsCommand; - public ActionCommand ExportTagsCommand => _exportTagsCommand ??= new(ExportTags); + private RelayCommand? _exportTagsCommand; + public RelayCommand ExportTagsCommand => _exportTagsCommand ??= new(ExportTags); public void ExportTags() { SaveFileDialog saveFileDialog = new() @@ -387,11 +387,11 @@ public void ExportTags() } //Import Collection - private ActionCommand? _importCommand; - public ActionCommand ImportCommand => _importCommand ??= new(async () => await ImportSatchelAsync()); + private AsyncRelayCommand? _importCommand; + public AsyncRelayCommand ImportCommand => _importCommand ??= new(ImportSatchelAsync); - - public async Task ImportSatchelAsync(string? path = null) + public async Task ImportSatchelAsync() => await ImportSatchelAsync(null); + public async Task ImportSatchelAsync(string? path) { var collectionToImport = await IOService.OpenSatchel(path); @@ -408,8 +408,8 @@ public async Task ImportSatchelAsync(string? path = null) } //Merge Collection into another - private RelayCommand? _mergeCollectionIntoCommand; - public RelayCommand MergeCollectionIntoCommand => _mergeCollectionIntoCommand ??= new(async s => await MergeIntoCollection(s)); + private AsyncRelayCommand? _mergeCollectionIntoCommand; + public AsyncRelayCommand MergeCollectionIntoCommand => _mergeCollectionIntoCommand ??= new(MergeIntoCollection); public async Task MergeIntoCollection(string? collectionToMergeInto) { if (String.IsNullOrEmpty(collectionToMergeInto) || !AllCodexCollections.Select(coll => coll.DirectoryName).Contains(collectionToMergeInto)) diff --git a/src/ViewModels/ExportCollectionViewModel.cs b/src/ViewModels/ExportCollectionViewModel.cs index c7aca2c9..f10cf861 100644 --- a/src/ViewModels/ExportCollectionViewModel.cs +++ b/src/ViewModels/ExportCollectionViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Services; using COMPASS.Tools; @@ -47,8 +47,8 @@ public bool AdvancedExport } } - private ActionCommand? _applyActiveFiltesCommand; - public ActionCommand ApplyActiveFiltersCommand => _applyActiveFiltesCommand ??= + private RelayCommand? _applyActiveFiltesCommand; + public RelayCommand ApplyActiveFiltersCommand => _applyActiveFiltesCommand ??= new(ApplyActiveFilters, () => MainViewModel.CollectionVM.FilterVM.HasActiveFilters); private void ApplyActiveFilters() { diff --git a/src/ViewModels/FileNotFoundViewModel.cs b/src/ViewModels/FileNotFoundViewModel.cs index 7762637c..edf663ac 100644 --- a/src/ViewModels/FileNotFoundViewModel.cs +++ b/src/ViewModels/FileNotFoundViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Services; using COMPASS.Tools; @@ -20,8 +20,8 @@ public FileNotFoundViewModel(Codex codex) private Codex _codex; - private ActionCommand? _findFileCommand; - public ActionCommand FindFileCommand => _findFileCommand ??= new(FindFile); + private RelayCommand? _findFileCommand; + public RelayCommand FindFileCommand => _findFileCommand ??= new(FindFile); public void FindFile() { OpenFileDialog openFileDialog = new() @@ -65,16 +65,16 @@ public void FindFile() } } - private ActionCommand? _removePathCommand; - public ActionCommand RemovePathCommand => _removePathCommand ??= new(RemovePath); + private RelayCommand? _removePathCommand; + public RelayCommand RemovePathCommand => _removePathCommand ??= new(RemovePath); private void RemovePath() { _codex.Path = ""; CloseAction?.Invoke(); } - private ActionCommand? _deleteCodexCommand; - public ActionCommand DeleteCodexCommand => _deleteCodexCommand ??= new(DeleteCodex); + private RelayCommand? _deleteCodexCommand; + public RelayCommand DeleteCodexCommand => _deleteCodexCommand ??= new(DeleteCodex); private void DeleteCodex() { CodexViewModel.DeleteCodex(_codex); diff --git a/src/ViewModels/FilterViewModel.cs b/src/ViewModels/FilterViewModel.cs index e7ce09f1..c3301efc 100644 --- a/src/ViewModels/FilterViewModel.cs +++ b/src/ViewModels/FilterViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Properties; using COMPASS.Tools; @@ -357,8 +357,8 @@ private void SearchCommandHelper(string? searchTerm) } //Clear Filters - private ActionCommand? _clearFiltersCommand; - public ActionCommand ClearFiltersCommand => _clearFiltersCommand ??= new(ClearFilters); + private RelayCommand? _clearFiltersCommand; + public RelayCommand ClearFiltersCommand => _clearFiltersCommand ??= new(ClearFilters); public void ClearFilters() { StartReleaseDate = null; diff --git a/src/ViewModels/IEditViewModel.cs b/src/ViewModels/IEditViewModel.cs index 6218afbd..3f1194e7 100644 --- a/src/ViewModels/IEditViewModel.cs +++ b/src/ViewModels/IEditViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using System; namespace COMPASS.ViewModels @@ -10,10 +10,10 @@ public interface IEditViewModel { public Action CloseAction { get; set; } - public ActionCommand CancelCommand { get; } + public RelayCommand CancelCommand { get; } public void Cancel(); - public ActionCommand OKCommand { get; } + public RelayCommand OKCommand { get; } public void OKBtn(); } } diff --git a/src/ViewModels/Import/ImportTagsViewModel.cs b/src/ViewModels/Import/ImportTagsViewModel.cs index f5c41f5c..3c542497 100644 --- a/src/ViewModels/Import/ImportTagsViewModel.cs +++ b/src/ViewModels/Import/ImportTagsViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using System; using System.Collections.Generic; @@ -17,8 +17,8 @@ public ImportTagsViewModel(List collections) public TagsSelectorViewModel TagsSelectorVM { get; set; } - private ActionCommand? _importTagsCommand; - public ActionCommand ImportTagsCommand => _importTagsCommand ??= new(ImportTags); + private RelayCommand? _importTagsCommand; + public RelayCommand ImportTagsCommand => _importTagsCommand ??= new(ImportTags); public void ImportTags() { foreach (var template in TagsSelectorVM.TagCollections) diff --git a/src/ViewModels/Import/ImportURLViewModel.cs b/src/ViewModels/Import/ImportURLViewModel.cs index b9facbad..72ae67a1 100644 --- a/src/ViewModels/Import/ImportURLViewModel.cs +++ b/src/ViewModels/Import/ImportURLViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Services; using COMPASS.Tools; @@ -70,8 +70,8 @@ public string ImportError set => SetProperty(ref _importError, value); } - private ActionCommand? _submitUrlCommand; - public ActionCommand SubmitURLCommand => _submitUrlCommand ??= new(async () => await SubmitURL()); + private AsyncRelayCommand? _submitUrlCommand; + public AsyncRelayCommand SubmitURLCommand => _submitUrlCommand ??= new(SubmitURL); public async Task SubmitURL() { if (!InputURL.Contains(ExampleURL) && ValidateURL) @@ -110,8 +110,8 @@ public async Task SubmitURL() } } - private ActionCommand? _openBarcodeScannerCommand; - public ActionCommand OpenBarcodeScannerCommand => _openBarcodeScannerCommand ??= new(OpenBarcodeScanner); + private RelayCommand? _openBarcodeScannerCommand; + public RelayCommand OpenBarcodeScannerCommand => _openBarcodeScannerCommand ??= new(OpenBarcodeScanner); private void OpenBarcodeScanner() { BarcodeScanWindow bcScanWindow = new(); diff --git a/src/ViewModels/LeftDockViewModel.cs b/src/ViewModels/LeftDockViewModel.cs index 34a3bd0a..56f52415 100644 --- a/src/ViewModels/LeftDockViewModel.cs +++ b/src/ViewModels/LeftDockViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Services; using COMPASS.Tools; @@ -45,11 +45,11 @@ public bool Collapsed } #region Add Books Tab - private RelayCommand? _importCommand; - public RelayCommand ImportCommand => _importCommand ??= new(async source => await ImportViewModel.Import(source)); + private AsyncRelayCommand? _importCommand; + public AsyncRelayCommand ImportCommand => _importCommand ??= new(ImportViewModel.Import); - private ActionCommand? _importBooksFromSatchelCommand; - public ActionCommand ImportBooksFromSatchelCommand => _importBooksFromSatchelCommand ??= new(async () => await ImportBooksFromSatchel()); + private AsyncRelayCommand? _importBooksFromSatchelCommand; + public AsyncRelayCommand ImportBooksFromSatchelCommand => _importBooksFromSatchelCommand ??= new(ImportBooksFromSatchel); public async Task ImportBooksFromSatchel() { var collectionToImport = await IOService.OpenSatchel(); diff --git a/src/ViewModels/MainViewModel.cs b/src/ViewModels/MainViewModel.cs index 37b06a51..dd97ac44 100644 --- a/src/ViewModels/MainViewModel.cs +++ b/src/ViewModels/MainViewModel.cs @@ -1,6 +1,6 @@ using AutoUpdaterDotNET; using CommunityToolkit.Mvvm.ComponentModel; -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Services; using COMPASS.Tools; @@ -149,10 +149,10 @@ public void OpenSettings(string? tab = "") } //check updates - public ActionCommand CheckForUpdatesCommand => SettingsViewModel.GetInstance().CheckForUpdatesCommand; + public RelayCommand CheckForUpdatesCommand => SettingsViewModel.GetInstance().CheckForUpdatesCommand; - private ActionCommand? _navigateToLinkTree; - public ActionCommand NavigateToLinkTree => _navigateToLinkTree ??= new(() + private RelayCommand? _navigateToLinkTree; + public RelayCommand NavigateToLinkTree => _navigateToLinkTree ??= new(() => Process.Start(new ProcessStartInfo(@"https://linktr.ee/compassapp") { UseShellExecute = true })); //Change Layout diff --git a/src/ViewModels/ProgressViewModel.cs b/src/ViewModels/ProgressViewModel.cs index c82bcbac..e75d6589 100644 --- a/src/ViewModels/ProgressViewModel.cs +++ b/src/ViewModels/ProgressViewModel.cs @@ -1,5 +1,5 @@ using CommunityToolkit.Mvvm.ComponentModel; -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using System.Collections.ObjectModel; using System.Threading; @@ -130,8 +130,8 @@ public void ConfirmCancellation() Cancelling = false; } - private ActionCommand? _cancelTasksCommand; - public ActionCommand CancelTasksCommand => _cancelTasksCommand ??= new(CancelBackgroundTask); + private RelayCommand? _cancelTasksCommand; + public RelayCommand CancelTasksCommand => _cancelTasksCommand ??= new(CancelBackgroundTask); public void CancelBackgroundTask() { GlobalCancellationTokenSource.Cancel(); diff --git a/src/ViewModels/SettingsViewModel.cs b/src/ViewModels/SettingsViewModel.cs index 18713d78..e53a8f13 100644 --- a/src/ViewModels/SettingsViewModel.cs +++ b/src/ViewModels/SettingsViewModel.cs @@ -1,6 +1,6 @@ using AutoUpdaterDotNET; using CommunityToolkit.Mvvm.ComponentModel; -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Services; using COMPASS.Tools; @@ -241,17 +241,18 @@ public CollectionViewSource AutoImportFoldersViewSource MainViewModel.CollectionVM.CurrentCollection.Info.AutoImportFolders.Remove(folder!)); //Remove a folder from auto import - private RelayCommand? _editAutoImportDirectoryCommand; - public RelayCommand EditAutoImportDirectoryCommand => _editAutoImportDirectoryCommand ??= new(async folder => await EditAutoImportFolder(folder)); + private AsyncRelayCommand? _editAutoImportDirectoryCommand; + public AsyncRelayCommand EditAutoImportDirectoryCommand => _editAutoImportDirectoryCommand ??= new(EditAutoImportFolder); //Add a directory from auto import - private RelayCommand? _addAutoImportDirectoryCommand; - public RelayCommand AddAutoImportDirectoryCommand => _addAutoImportDirectoryCommand ??= new(async dir => await AddAutoImportDirectory(dir)); + private AsyncRelayCommand? _addAutoImportDirectoryCommand; + public AsyncRelayCommand AddAutoImportDirectoryCommand => _addAutoImportDirectoryCommand ??= new(AddAutoImportDirectory); //Add a directory from auto import - private ActionCommand? _pickAutoImportDirectoryCommand; - public ActionCommand PickAutoImportDirectoryCommand => _pickAutoImportDirectoryCommand ??= new(async () => await AddAutoImportDirectory(IOService.PickFolder())); + private AsyncRelayCommand? _pickAutoImportDirectoryCommand; + public AsyncRelayCommand PickAutoImportDirectoryCommand => _pickAutoImportDirectoryCommand ??= new(PickAutoImportDirectory); + private async Task PickAutoImportDirectory() => await AddAutoImportDirectory(IOService.PickFolder()); private async Task AddAutoImportDirectory(string? dir) { if (!String.IsNullOrWhiteSpace(dir) && Directory.Exists(dir)) @@ -332,8 +333,8 @@ private void AddFolderTagPair(FolderTagPair? pair) MainViewModel.CollectionVM.CurrentCollection.Info.FolderTagPairs.AddIfMissing(pair); } - private ActionCommand? _detectFolderTagPairsCommand; - public ActionCommand DetectFolderTagPairsCommand => _detectFolderTagPairsCommand ??= new(DetectFolderTagPairs); + private RelayCommand? _detectFolderTagPairsCommand; + public RelayCommand DetectFolderTagPairsCommand => _detectFolderTagPairsCommand ??= new(DetectFolderTagPairs); private void DetectFolderTagPairs() { var splitFolders = MainViewModel.CollectionVM.CurrentCollection.AllCodices @@ -408,8 +409,8 @@ private void BrokenCodicesChanged() OnPropertyChanged(nameof(BrokenCodicesMessage)); } - private ActionCommand? _showBrokenCodicesCommand; - public ActionCommand ShowBrokenCodicesCommand => _showBrokenCodicesCommand ??= new(ShowBrokenCodices); + private RelayCommand? _showBrokenCodicesCommand; + public RelayCommand ShowBrokenCodicesCommand => _showBrokenCodicesCommand ??= new(ShowBrokenCodices); private void ShowBrokenCodices() { MainViewModel.CollectionVM.FilterVM.AddFilter(new(Filter.FilterType.HasBrokenPath)); @@ -462,8 +463,8 @@ private void RenameFolderReferences(string? oldpath, string? newpath) } //remove refs from codices - private ActionCommand? _removeBrokenRefsCommand; - public ActionCommand RemoveBrokenRefsCommand => _removeBrokenRefsCommand ??= new(RemoveBrokenReferences); + private RelayCommand? _removeBrokenRefsCommand; + public RelayCommand RemoveBrokenRefsCommand => _removeBrokenRefsCommand ??= new(RemoveBrokenReferences); public void RemoveBrokenReferences() { foreach (Codex codex in BrokenCodices) @@ -475,8 +476,8 @@ public void RemoveBrokenReferences() } //Remove Codices with broken refs - private ActionCommand? _deleteCodicesWithBrokenRefsCommand; - public ActionCommand DeleteCodicesWithBrokenRefsCommand => _deleteCodicesWithBrokenRefsCommand ??= new(RemoveCodicesWithBrokenRefs); + private RelayCommand? _deleteCodicesWithBrokenRefsCommand; + public RelayCommand DeleteCodicesWithBrokenRefsCommand => _deleteCodicesWithBrokenRefsCommand ??= new(RemoveCodicesWithBrokenRefs); public void RemoveCodicesWithBrokenRefs() { MainViewModel.CollectionVM.CurrentCollection.DeleteCodices(BrokenCodices.ToList()); @@ -511,8 +512,8 @@ public static string CompassDataPath public string NewDataPath { get; set; } = ""; - private ActionCommand? _changeDataPathCommand; - public ActionCommand ChangeDataPathCommand => _changeDataPathCommand ??= new(ChooseNewDataPath); + private RelayCommand? _changeDataPathCommand; + public RelayCommand ChangeDataPathCommand => _changeDataPathCommand ??= new(ChooseNewDataPath); private void ChooseNewDataPath() { Ookii.Dialogs.Wpf.VistaFolderBrowserDialog folderBrowserDialog = new() @@ -527,8 +528,8 @@ private void ChooseNewDataPath() } } - private ActionCommand? _resetDataPathCommand; - public ActionCommand ResetDataPathCommand => _resetDataPathCommand ??= new(() => SetNewDataPath(_defaultDataPath)); + private RelayCommand? _resetDataPathCommand; + public RelayCommand ResetDataPathCommand => _resetDataPathCommand ??= new(() => SetNewDataPath(_defaultDataPath)); private void SetNewDataPath(string newPath) { @@ -551,8 +552,8 @@ private void SetNewDataPath(string newPath) window.ShowDialog(); } - private ActionCommand? _moveToNewDataPathCommand; - public ActionCommand MoveToNewDataPathCommand => _moveToNewDataPathCommand ??= new(async () => await MoveToNewDataPath()); + private AsyncRelayCommand? _moveToNewDataPathCommand; + public AsyncRelayCommand MoveToNewDataPathCommand => _moveToNewDataPathCommand ??= new(MoveToNewDataPath); public async Task MoveToNewDataPath() { bool success; @@ -572,26 +573,26 @@ public async Task MoveToNewDataPath() } } - private ActionCommand? _copyToNewDataPathCommand; - public ActionCommand CopyToNewDataPathCommand => _copyToNewDataPathCommand ??= - new(async () => + private AsyncRelayCommand? _copyToNewDataPathCommand; + public AsyncRelayCommand CopyToNewDataPathCommand => _copyToNewDataPathCommand ??= new(CopyToNewDataPath); + private async Task CopyToNewDataPath() + { + try { - try - { - await CopyDataAsync(CompassDataPath, NewDataPath); - } - catch (OperationCanceledException ex) - { - Logger.Warn("File copy has been cancelled", ex); - await Task.Run(() => ProgressViewModel.GetInstance().ConfirmCancellation()); - return; - } + await CopyDataAsync(CompassDataPath, NewDataPath); + } + catch (OperationCanceledException ex) + { + Logger.Warn("File copy has been cancelled", ex); + await Task.Run(() => ProgressViewModel.GetInstance().ConfirmCancellation()); + return; + } - ChangeToNewDataPath(); - }); + ChangeToNewDataPath(); + } - private ActionCommand? _changeToNewDataPathCommand; - public ActionCommand ChangeToNewDataPathCommand => _changeToNewDataPathCommand ??= new(ChangeToNewDataPath); + private RelayCommand? _changeToNewDataPathCommand; + public RelayCommand ChangeToNewDataPathCommand => _changeToNewDataPathCommand ??= new(ChangeToNewDataPath); /// /// Sets the data path to and restarts the app @@ -609,8 +610,8 @@ public void ChangeToNewDataPath() Application.Current.Shutdown(); } - private ActionCommand? _deleteDataCommand; - public ActionCommand DeleteDataCommand => _deleteDataCommand ??= new(DeleteDataLocation); + private RelayCommand? _deleteDataCommand; + public RelayCommand DeleteDataCommand => _deleteDataCommand ??= new(DeleteDataLocation); public void DeleteDataLocation() { @@ -676,8 +677,8 @@ await Task.Run(() => } #endregion - private ActionCommand? _browseLocalFilesCommand; - public ActionCommand BrowseLocalFilesCommand => _browseLocalFilesCommand ??= new(BrowseLocalFiles); + private RelayCommand? _browseLocalFilesCommand; + public RelayCommand BrowseLocalFilesCommand => _browseLocalFilesCommand ??= new(BrowseLocalFiles); public void BrowseLocalFiles() { ProcessStartInfo startInfo = new() @@ -692,8 +693,8 @@ public void BrowseLocalFiles() private readonly BackgroundWorker _extractZipWorker = new(); private LoadingWindow? _lw; - private ActionCommand? _backupLocalFilesCommand; - public ActionCommand BackupLocalFilesCommand => _backupLocalFilesCommand ??= new(BackupLocalFiles); + private RelayCommand? _backupLocalFilesCommand; + public RelayCommand BackupLocalFilesCommand => _backupLocalFilesCommand ??= new(BackupLocalFiles); public void BackupLocalFiles() { SaveFileDialog saveFileDialog = new() @@ -718,8 +719,8 @@ public void BackupLocalFiles() } } - private ActionCommand? _restoreBackupCommand; - public ActionCommand RestoreBackupCommand => _restoreBackupCommand ??= new(RestoreBackup); + private RelayCommand? _restoreBackupCommand; + public RelayCommand RestoreBackupCommand => _restoreBackupCommand ??= new(RestoreBackup); public void RestoreBackup() { OpenFileDialog openFileDialog = new() @@ -795,8 +796,8 @@ public void RegenAllThumbnails() #region Tab: About public string Version => "Version: " + Assembly.GetExecutingAssembly().GetName().Version?.ToString()[0..5]; - private ActionCommand? _checkForUpdatesCommand; - public ActionCommand CheckForUpdatesCommand => _checkForUpdatesCommand ??= new(CheckForUpdates); + private RelayCommand? _checkForUpdatesCommand; + public RelayCommand CheckForUpdatesCommand => _checkForUpdatesCommand ??= new(CheckForUpdates); private void CheckForUpdates() { AutoUpdater.Mandatory = true; diff --git a/src/ViewModels/TagEditViewModel.cs b/src/ViewModels/TagEditViewModel.cs index ff734fec..fbeebd21 100644 --- a/src/ViewModels/TagEditViewModel.cs +++ b/src/ViewModels/TagEditViewModel.cs @@ -1,5 +1,5 @@ using CommunityToolkit.Mvvm.ComponentModel; -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Tools; using System; @@ -47,8 +47,8 @@ public bool ShowColorSelection #region Functions and Commands - private ActionCommand? _oKCommand; - public ActionCommand OKCommand => _oKCommand ??= new(OKBtn, CanOkBtn); + private RelayCommand? _oKCommand; + public RelayCommand OKCommand => _oKCommand ??= new(OKBtn, CanOkBtn); public void OKBtn() { //Apply changes @@ -80,8 +80,8 @@ public void OKBtn() } public bool CanOkBtn() => !String.IsNullOrWhiteSpace(TempTag.Content); - private ActionCommand? _cancelCommand; - public ActionCommand CancelCommand => _cancelCommand ??= new(Cancel); + private RelayCommand? _cancelCommand; + public RelayCommand CancelCommand => _cancelCommand ??= new(Cancel); public void Cancel() { if (CreateNewTag) @@ -92,11 +92,11 @@ public void Cancel() CloseAction(); } - private ActionCommand? _closeColorSelectionCommand; - public ActionCommand CloseColorSelectionCommand => _closeColorSelectionCommand ??= new(CloseColorSelection); + private RelayCommand? _closeColorSelectionCommand; + public RelayCommand CloseColorSelectionCommand => _closeColorSelectionCommand ??= new(CloseColorSelection); - private ActionCommand? _colorSameAsParentCommand; - public ActionCommand ColorSameAsParentCommand => _colorSameAsParentCommand ??= new(SetColorSameAsParent); + private RelayCommand? _colorSameAsParentCommand; + public RelayCommand ColorSameAsParentCommand => _colorSameAsParentCommand ??= new(SetColorSameAsParent); private void SetColorSameAsParent() { TempTag.SerializableBackgroundColor = null; diff --git a/src/ViewModels/TagsViewModel.cs b/src/ViewModels/TagsViewModel.cs index 47e7925d..6829a0ab 100644 --- a/src/ViewModels/TagsViewModel.cs +++ b/src/ViewModels/TagsViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using COMPASS.Models; using COMPASS.Services; using COMPASS.Tools; @@ -101,13 +101,13 @@ public IEditViewModel? AddGroupViewModel //Add Tag Buttons - private ActionCommand? _addTagCommand; - public ActionCommand AddTagCommand => _addTagCommand ??= new(AddTag); + private RelayCommand? _addTagCommand; + public RelayCommand AddTagCommand => _addTagCommand ??= new(AddTag); public void AddTag() => AddTagViewModel = new TagEditViewModel(null, true); - private ActionCommand? _addGroupCommand; - public ActionCommand AddGroupCommand => _addGroupCommand ??= new(AddGroup); + private RelayCommand? _addGroupCommand; + public RelayCommand AddGroupCommand => _addGroupCommand ??= new(AddGroup); public void AddGroup() { Tag newTag = new() @@ -128,8 +128,8 @@ public void AddTagFilterHelper(object[]? par) _filterVM.AddFilter(new(Filter.FilterType.Tag, tag), include); } - private ActionCommand? _importTagsFromOtherCollectionsCommand; - public ActionCommand ImportTagsFromOtherCollectionsCommand => _importTagsFromOtherCollectionsCommand ??= new(ImportTagsFromOtherCollections); + private RelayCommand? _importTagsFromOtherCollectionsCommand; + public RelayCommand ImportTagsFromOtherCollectionsCommand => _importTagsFromOtherCollectionsCommand ??= new(ImportTagsFromOtherCollections); public void ImportTagsFromOtherCollections() { var importVM = new ImportTagsViewModel(MainViewModel.CollectionVM.AllCodexCollections.ToList()); @@ -137,8 +137,8 @@ public void ImportTagsFromOtherCollections() w.Show(); } - private ActionCommand? _importTagsFromSatchelCommand; - public ActionCommand ImportTagsFromSatchelCommand => _importTagsFromSatchelCommand ??= new(async () => await ImportTagsFromSatchel()); + private AsyncRelayCommand? _importTagsFromSatchelCommand; + public AsyncRelayCommand ImportTagsFromSatchelCommand => _importTagsFromSatchelCommand ??= new(ImportTagsFromSatchel); public async Task ImportTagsFromSatchel() { var collectionToImport = await IOService.OpenSatchel(); @@ -161,8 +161,8 @@ public async Task ImportTagsFromSatchel() w.Show(); } - private ActionCommand? _exportTagsCommand; - public ActionCommand ExportTagsCommand => _exportTagsCommand ??= new(ExportTags, _codexCollection.RootTags.Any); + private RelayCommand? _exportTagsCommand; + public RelayCommand ExportTagsCommand => _exportTagsCommand ??= new(ExportTags, _codexCollection.RootTags.Any); public void ExportTags() { var vm = new ExportCollectionViewModel @@ -204,8 +204,8 @@ void IDropTarget.Drop(IDropInfo dropInfo) #endregion #region Tag Context Menu - private ActionCommand? _createChildCommand; - public ActionCommand CreateChildCommand => _createChildCommand ??= new(CreateChildTag); + private RelayCommand? _createChildCommand; + public RelayCommand CreateChildCommand => _createChildCommand ??= new(CreateChildTag); private void CreateChildTag() { if (ContextTag is not null) @@ -221,8 +221,8 @@ private void CreateChildTag() } } - private ActionCommand? _sortChildrenCommand; - public ActionCommand SortChildrenCommand => _sortChildrenCommand ??= new(SortChildren, CanSortChildren); + private RelayCommand? _sortChildrenCommand; + public RelayCommand SortChildrenCommand => _sortChildrenCommand ??= new(SortChildren, CanSortChildren); public void SortChildren() { SortChildren(ContextTag); @@ -240,8 +240,8 @@ public void SortChildren(Tag? tag) public bool CanSortChildren() => CanSortChildren(ContextTag); public bool CanSortChildren(Tag? tag) => tag?.Children.Any() == true; - private ActionCommand? _sortAllTagsCommand; - public ActionCommand SortAllTagsCommand => _sortAllTagsCommand ??= new(SortAllTags); + private RelayCommand? _sortAllTagsCommand; + public RelayCommand SortAllTagsCommand => _sortAllTagsCommand ??= new(SortAllTags); public void SortAllTags() { Tag t = new() @@ -253,8 +253,8 @@ public void SortAllTags() BuildTagTreeView(); } - private ActionCommand? _editTagCommand; - public ActionCommand EditTagCommand => _editTagCommand ??= new(EditTag); + private RelayCommand? _editTagCommand; + public RelayCommand EditTagCommand => _editTagCommand ??= new(EditTag); public void EditTag() { if (ContextTag is not null) @@ -265,8 +265,8 @@ public void EditTag() } } - private ActionCommand? _deleteTagCommand; - public ActionCommand DeleteTagCommand => _deleteTagCommand ??= new(DeleteTag); + private RelayCommand? _deleteTagCommand; + public RelayCommand DeleteTagCommand => _deleteTagCommand ??= new(DeleteTag); public void DeleteTag() { //tag to delete is context, because DeleteTag is called from context menu diff --git a/src/ViewModels/WizardViewModel.cs b/src/ViewModels/WizardViewModel.cs index e261328f..e62dbac8 100644 --- a/src/ViewModels/WizardViewModel.cs +++ b/src/ViewModels/WizardViewModel.cs @@ -1,4 +1,4 @@ -using COMPASS.Commands; +using CommunityToolkit.Mvvm.Input; using System; using System.Collections.ObjectModel; using System.Threading.Tasks; @@ -24,34 +24,40 @@ public int StepCounter get => _stepCounter; set { - if (value <= 0) value = 0; + if (value <= 0) + { + value = 0; + } else if (value >= Steps.Count) + { Finish(); + } + SetProperty(ref _stepCounter, value); OnPropertyChanged(nameof(CurrentStep)); - OnPropertyChanged(nameof(ShowBackButton)); - OnPropertyChanged(nameof(ShowNextButton)); - OnPropertyChanged(nameof(ShowFinishButton)); + PrevStepCommand.NotifyCanExecuteChanged(); + NextStepCommand.NotifyCanExecuteChanged(); + FinishCommand.NotifyCanExecuteChanged(); } } public string CurrentStep => Steps[StepCounter]; - private ActionCommand? _cancelCommand; - public virtual ActionCommand CancelCommand => _cancelCommand ??= new((CancelAction ?? CloseAction) ?? new Action(() => { })); + private RelayCommand? _cancelCommand; + public virtual RelayCommand CancelCommand => _cancelCommand ??= new((CancelAction ?? CloseAction) ?? new Action(() => { })); - private ActionCommand? _nextStepCommand; - public ActionCommand NextStepCommand => _nextStepCommand ??= new(NextStep, ShowNextButton); + private RelayCommand? _nextStepCommand; + public RelayCommand NextStepCommand => _nextStepCommand ??= new(NextStep, ShowNextButton); protected virtual void NextStep() => StepCounter++; public virtual bool ShowNextButton() => StepCounter < Steps.Count - 1; - private ActionCommand? _prevStepCommand; - public ActionCommand PrevStepCommand => _prevStepCommand ??= new(PrevStep, ShowBackButton); + private RelayCommand? _prevStepCommand; + public RelayCommand PrevStepCommand => _prevStepCommand ??= new(PrevStep, ShowBackButton); protected virtual void PrevStep() => StepCounter--; public virtual bool ShowBackButton() => StepCounter > 0; - private ActionCommand? _finishCommand; - public ActionCommand FinishCommand => _finishCommand ??= new(async () => await Finish(), ShowFinishButton); + private AsyncRelayCommand? _finishCommand; + public AsyncRelayCommand FinishCommand => _finishCommand ??= new(Finish, ShowFinishButton); public abstract Task Finish(); public virtual bool ShowFinishButton() => StepCounter == Steps.Count - 1;