Skip to content

Commit

Permalink
Add clear detected items button
Browse files Browse the repository at this point in the history
  • Loading branch information
Neakita committed Sep 12, 2023
1 parent 70ce9ad commit e3ab271
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public AutoAnnotationViewModel(Detector detector, SelectedScreenshotViewModel se
_selectedScreenshotViewModel = selectedScreenshotViewModel;
_selectedDataSetViewModel = selectedDataSetViewModel;
selectedScreenshotViewModel.NotifyCanExecuteChanged(AnnotateCommand);
selectedScreenshotViewModel.NotifyCanExecuteChanged(ClearCommand);
}

private readonly Detector _detector;
Expand All @@ -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)
{
Expand Down
8 changes: 6 additions & 2 deletions SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
<StackPanel>
<ComboBox ItemsSource="{Binding Weights}"
SelectedItem="{Binding SelectedWeights}"/>
<Button Content="{icons:MaterialIconExt AutoFix}"
Command="{Binding AnnotateCommand}"/>
<WrapPanel>
<Button Content="{icons:MaterialIconExt AutoFix}"
Command="{Binding AnnotateCommand}"/>
<Button Content="{icons:MaterialIconExt Eraser}"
Command="{Binding ClearCommand}"/>
</WrapPanel>
<CheckBox Content="Auto detect"
IsChecked="{Binding AutoAnnotatingEnabled}"
IsEnabled="{Binding !!SelectedWeights}"/>
Expand Down

0 comments on commit e3ab271

Please sign in to comment.