From e3ab271a621409f05c922e2a5dbf738b8e898e3f Mon Sep 17 00:00:00 2001 From: KatterMaw Date: Tue, 12 Sep 2023 18:42:16 +0500 Subject: [PATCH] Add clear detected items button --- .../ViewModels/Annotating/AutoAnnotationViewModel.cs | 10 ++++++++++ .../Views/Annotating/AutoAnnotation.axaml | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotationViewModel.cs b/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotationViewModel.cs index f40bc1f3..40be2b63 100644 --- a/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotationViewModel.cs +++ b/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotationViewModel.cs @@ -55,6 +55,7 @@ public AutoAnnotationViewModel(Detector detector, SelectedScreenshotViewModel se _selectedScreenshotViewModel = selectedScreenshotViewModel; _selectedDataSetViewModel = selectedDataSetViewModel; selectedScreenshotViewModel.NotifyCanExecuteChanged(AnnotateCommand); + selectedScreenshotViewModel.NotifyCanExecuteChanged(ClearCommand); } private readonly Detector _detector; @@ -70,8 +71,17 @@ private async Task Annotate(CancellationToken cancellationToken) var items = await _detector.Detect(content, cancellationToken); _selectedScreenshotViewModel.DetectedItems.Clear(); _selectedScreenshotViewModel.DetectedItems.AddRange(items.Select(CreateDetectedItemViewModel)); + ClearCommand.NotifyCanExecuteChanged(); } private bool CanAnnotate() => SelectedWeights != null && _selectedScreenshotViewModel.Value != null && !AutoAnnotatingEnabled; + + [RelayCommand(CanExecute = nameof(CanClear))] + private void Clear() + { + _selectedScreenshotViewModel.DetectedItems.Clear(); + ClearCommand.NotifyCanExecuteChanged(); + } + private bool CanClear() => _selectedScreenshotViewModel.DetectedItems.Count > 0; private static DetectedItemViewModel CreateDetectedItemViewModel(DetectionItem detectionItem) { diff --git a/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml b/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml index c3597105..3cdb89dc 100644 --- a/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml +++ b/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml @@ -10,8 +10,12 @@ -