From b0e4b467c1f096e5cbdd99a9278d7139de3e80d1 Mon Sep 17 00:00:00 2001 From: Oleksandr Bezdieniezhnykh Date: Sat, 6 Sep 2025 01:27:49 +0300 Subject: [PATCH] add media removal --- Azaion.Annotator/Annotator.xaml | 1 + Azaion.Annotator/Annotator.xaml.cs | 22 ++++++++++++++++++++++ Azaion.Annotator/AnnotatorEventHandler.cs | 12 ++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Azaion.Annotator/Annotator.xaml b/Azaion.Annotator/Annotator.xaml index ac7c451..bff9f5f 100644 --- a/Azaion.Annotator/Annotator.xaml +++ b/Azaion.Annotator/Annotator.xaml @@ -177,6 +177,7 @@ + diff --git a/Azaion.Annotator/Annotator.xaml.cs b/Azaion.Annotator/Annotator.xaml.cs index afdb69c..f625ad3 100644 --- a/Azaion.Annotator/Annotator.xaml.cs +++ b/Azaion.Annotator/Annotator.xaml.cs @@ -549,6 +549,28 @@ public partial class Annotator } #endregion + + private void DeleteMedia(object sender, RoutedEventArgs e) + { + var mediaFileInfo = (sender as MenuItem)?.DataContext as MediaFileInfo; + if (mediaFileInfo == null) + return; + DeleteMedia(mediaFileInfo); + } + + public void DeleteMedia(MediaFileInfo mediaFileInfo) + { + var obj = mediaFileInfo.MediaType == MediaTypes.Image + ? "цю картинку " + : "це відео "; + var result = MessageBox.Show($"Видалити {obj}?", + "Підтвердження видалення", MessageBoxButton.YesNo, MessageBoxImage.Warning); + if (result != MessageBoxResult.Yes) + return; + + File.Delete(mediaFileInfo.Path); + AllMediaFiles.Remove(mediaFileInfo); + } } public class GradientStyleSelector : StyleSelector diff --git a/Azaion.Annotator/AnnotatorEventHandler.cs b/Azaion.Annotator/AnnotatorEventHandler.cs index eea520a..357acdb 100644 --- a/Azaion.Annotator/AnnotatorEventHandler.cs +++ b/Azaion.Annotator/AnnotatorEventHandler.cs @@ -1,5 +1,6 @@ using System.IO; using System.Windows; +using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -174,8 +175,15 @@ public class AnnotatorEventHandler( await SaveAnnotation(cancellationToken); break; case PlaybackControlEnum.RemoveSelectedAnns: - - mainWindow.Editor.RemoveSelectedAnns(); + var focusedElement = FocusManager.GetFocusedElement(mainWindow); + if (focusedElement is ListViewItem item) + { + if (item.DataContext is not MediaFileInfo mediaFileInfo) + return; + mainWindow.DeleteMedia(mediaFileInfo); + } + else + mainWindow.Editor.RemoveSelectedAnns(); break; case PlaybackControlEnum.RemoveAllAnns: mainWindow.Editor.RemoveAllAnns();