Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] button status is not updated when complete SearchCommand #66

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions DicomGrep/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,21 @@ public ICommand SearchCommand
{
get
{
return _searchCommand ?? (_searchCommand = new RelayCommand<object>(_ => DoSearch(false), _ => this.MainStatus != MainStatusEnum.Working));
return _searchCommand ?? (_searchCommand = new RelayCommand<object>(_ => DoSearch(false), CanExecuteSearchCommand));
}
}

public bool CanExecuteSearchCommand(object obj)
{
return this.MainStatus != MainStatusEnum.Working;
}

private ICommand _searchInResultsCommand;
public ICommand SearchInResultsCommand
{
get
{
return _searchInResultsCommand ?? (_searchInResultsCommand = new RelayCommand<object>(_ => DoSearch(true), _ => this.MainStatus != MainStatusEnum.Working));
return _searchInResultsCommand ?? (_searchInResultsCommand = new RelayCommand<object>(_ => DoSearch(true), CanExecuteSearchCommand));
}
}

Expand All @@ -204,10 +209,15 @@ public ICommand CancelCommand
{
get
{
return _cancelCommand ?? (_cancelCommand = new RelayCommand<object>(_ => DoCancel(), _ => this.MainStatus == MainStatusEnum.Working));
return _cancelCommand ?? (_cancelCommand = new RelayCommand<object>(_ => DoCancel(), CanExecuteCancelCommand));
}
}

public bool CanExecuteCancelCommand(object obj)
{
return this.MainStatus == MainStatusEnum.Working;
}

private ICommand _fileOperationCommand;
public ICommand FileOperationCommand
{
Expand Down Expand Up @@ -370,6 +380,7 @@ private void SearchService_OnCompletDicomFile(object sender, DicomGrepCore.Servi
private void SearchService_OnSearchComplete(object sender, DicomGrepCore.Services.EventArgs.OnSearchCompleteEventArgs e)
{
this.MainStatus = MainStatusEnum.Complete;
InvalidateRequerySuggested();
}

private void DoSearch(bool searchInResults = false)
Expand Down
7 changes: 7 additions & 0 deletions DicomGrep/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows;
using System.Windows.Input;

namespace DicomGrep.ViewModels
{
Expand All @@ -25,5 +27,10 @@ protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName]
this.OnPropertyChanged(propertyName);
return true;
}

protected virtual void InvalidateRequerySuggested()
{
Application.Current?.Dispatcher.BeginInvoke((Action)CommandManager.InvalidateRequerySuggested);
}
}
}
Loading