diff --git a/Azaion.Annotator/Controls/AnnotationControl.cs b/Azaion.Annotator/Controls/AnnotationControl.cs index 9c22da8..118e305 100644 --- a/Azaion.Annotator/Controls/AnnotationControl.cs +++ b/Azaion.Annotator/Controls/AnnotationControl.cs @@ -14,8 +14,8 @@ public class AnnotationControl : Border private readonly Grid _grid; private readonly TextBlock _classNameLabel; - - private AnnotationClass _annotationClass; + + private AnnotationClass _annotationClass = null!; public AnnotationClass AnnotationClass { get => _annotationClass; diff --git a/Azaion.Annotator/Controls/CanvasEditor.cs b/Azaion.Annotator/Controls/CanvasEditor.cs index c21dee3..4ab9184 100644 --- a/Azaion.Annotator/Controls/CanvasEditor.cs +++ b/Azaion.Annotator/Controls/CanvasEditor.cs @@ -22,15 +22,15 @@ public class CanvasEditor : Canvas private readonly Line _verticalLine; private readonly TextBlock _classNameHint; - private Rectangle _curRec; - private AnnotationControl _curAnn; + private Rectangle _curRec = new(); + private AnnotationControl _curAnn = null!; private const int MIN_SIZE = 20; - - public FormState FormState { get; set; } - public IMediator Mediator { get; set; } - private AnnotationClass _currentAnnClass; + public FormState FormState { get; set; } = null!; + public IMediator Mediator { get; set; } = null!; + + private AnnotationClass _currentAnnClass = null!; public AnnotationClass CurrentAnnClass { get => _currentAnnClass; diff --git a/Azaion.Annotator/Controls/UpdatableProgressBar.cs b/Azaion.Annotator/Controls/UpdatableProgressBar.cs index d017842..8171c3f 100644 --- a/Azaion.Annotator/Controls/UpdatableProgressBar.cs +++ b/Azaion.Annotator/Controls/UpdatableProgressBar.cs @@ -7,7 +7,7 @@ namespace Azaion.Annotator.Controls { public delegate void ValueChange(double oldValue, double newValue); - public event ValueChange? ValueChanged; + public new event ValueChange? ValueChanged; public UpdatableProgressBar() : base() { diff --git a/Azaion.Annotator/MainWindow.xaml.cs b/Azaion.Annotator/MainWindow.xaml.cs index 779f0aa..33a6be7 100644 --- a/Azaion.Annotator/MainWindow.xaml.cs +++ b/Azaion.Annotator/MainWindow.xaml.cs @@ -24,13 +24,11 @@ public partial class MainWindow private readonly HelpWindow _helpWindow; private readonly TimeSpan _annotationTime = TimeSpan.FromSeconds(1); - public ObservableCollection AnnotationClasses { get; set; } + public ObservableCollection AnnotationClasses { get; set; } = new(); private bool _suspendLayout; public Dictionary> Annotations { get; set; } = new(); - - public bool ShowHelpOnStart { get; set; } - + public MainWindow(LibVLC libVLC, MediaPlayer mediaPlayer, IMediator mediator, FormState formState, @@ -72,8 +70,7 @@ public partial class MainWindow if (LvFiles.Items.IsEmpty) BlinkHelp(HelpTexts.HelpTextsDict[HelpTextEnum.Initial]); - ShowHelpOnStart = _config.ShowHelpOnStart; - if (ShowHelpOnStart) + if (_config.ShowHelpOnStart) _helpWindow.Show(); } @@ -131,15 +128,17 @@ public partial class MainWindow }).ToList(); //remove annotations: either in 1 sec, either earlier if there is next annotation in a dictionary - var strs = curTime.Split("_"); - var timeStr = strs.LastOrDefault(); - var ts = TimeSpan.FromMilliseconds(int.Parse(timeStr)*100); - var timeSpanRemove = Enumerable.Range(1, ((int)_annotationTime.TotalMilliseconds / 100) - 1) + var timeStr = curTime.Split("_").LastOrDefault(); + if (!int.TryParse(timeStr, out var time)) + return; + + var ts = TimeSpan.FromMilliseconds(time * 100); + var timeSpanRemove = Enumerable.Range(1, (int)_annotationTime.TotalMilliseconds / 100 - 1) .Select(x => { - var time = TimeSpan.FromMilliseconds(x * 100); - var fName = _formState.GetTimeName(ts.Add(time)); - return Annotations.ContainsKey(fName) ? time : (TimeSpan?)null; + var timeNext = TimeSpan.FromMilliseconds(x * 100); + var fName = _formState.GetTimeName(ts.Add(timeNext)); + return Annotations.ContainsKey(fName) ? timeNext : (TimeSpan?)null; }).FirstOrDefault(x => x != null) ?? _annotationTime; _ = Task.Run(async () => @@ -240,8 +239,10 @@ public partial class MainWindow }; if (dlg.ShowDialog() != CommonFileDialogResult.Ok) return; + + if (!string.IsNullOrEmpty(dlg.FileName)) + _config.VideosDirectory = dlg.FileName; - _config.VideosDirectory = dlg.FileName; ReloadFiles(); } diff --git a/Azaion.Annotator/PlayerControlHandler.cs b/Azaion.Annotator/PlayerControlHandler.cs index 3b89fc6..efbd000 100644 --- a/Azaion.Annotator/PlayerControlHandler.cs +++ b/Azaion.Annotator/PlayerControlHandler.cs @@ -25,9 +25,13 @@ public class PlayerControlHandler(LibVLC libVLC, MediaPlayer mediaPlayer, MainWi { Key.Delete, PlaybackControlEnum.RemoveSelectedAnns }, { Key.X, PlaybackControlEnum.RemoveAllAnns } }; - - public async Task Handle(AnnClassSelectedEvent notification, CancellationToken cancellationToken) => + + public async Task Handle(AnnClassSelectedEvent notification, CancellationToken cancellationToken) + { SelectClass(notification.AnnotationClass); + await Task.CompletedTask; + } + private void SelectClass(AnnotationClass annClass) {