From c72f7fc26591d62c8a15afa1d2e153ac061be257 Mon Sep 17 00:00:00 2001 From: Oleksandr Bezdieniezhnykh Date: Tue, 23 Jul 2024 14:58:35 +0300 Subject: [PATCH] save window position and left and right panel size --- Azaion.Annotator/DTO/Config.cs | 24 ++++++------- Azaion.Annotator/MainWindow.xaml | 8 +++-- Azaion.Annotator/MainWindow.xaml.cs | 46 ++++++++++++++---------- Azaion.Annotator/PlayerControlHandler.cs | 2 +- Azaion.Annotator/config.json | 6 +++- 5 files changed, 49 insertions(+), 37 deletions(-) diff --git a/Azaion.Annotator/DTO/Config.cs b/Azaion.Annotator/DTO/Config.cs index 7a19d51..e39a794 100644 --- a/Azaion.Annotator/DTO/Config.cs +++ b/Azaion.Annotator/DTO/Config.cs @@ -18,11 +18,16 @@ public class Config public List AnnotationClasses { get; set; } = []; private Dictionary? _annotationClassesDict; - public Dictionary AnnotationClassesDict => _annotationClassesDict ??= AnnotationClasses.ToDictionary(x => x.Id); + public Dictionary AnnotationClassesDict => _annotationClassesDict ??= AnnotationClasses.ToDictionary(x => x.Id); - public Size WindowSize { get; set; } - public Point WindowLocation { get; set; } - public bool ShowHelpOnStart { get; set; } + public Size WindowSize { get; set; } + public Point WindowLocation { get; set; } + public bool FullScreen { get; set; } + + public double LeftPanelWidth { get; set; } + public double RightPanelWidth { get; set; } + + public bool ShowHelpOnStart { get; set; } } public interface IConfigRepository @@ -63,15 +68,8 @@ public class FileConfigRepository(ILogger logger) : IConfi ShowHelpOnStart = true }; } - try - { - var str = File.ReadAllText(CONFIG_PATH); - return JsonConvert.DeserializeObject(str) ?? new Config(); - } - catch (Exception) - { - return new Config(); - } + var str = File.ReadAllText(CONFIG_PATH); + return JsonConvert.DeserializeObject(str) ?? new Config(); } public void Save(Config config) diff --git a/Azaion.Annotator/MainWindow.xaml b/Azaion.Annotator/MainWindow.xaml index 978ea3e..95b00b7 100644 --- a/Azaion.Annotator/MainWindow.xaml +++ b/Azaion.Annotator/MainWindow.xaml @@ -47,9 +47,11 @@ - + diff --git a/Azaion.Annotator/MainWindow.xaml.cs b/Azaion.Annotator/MainWindow.xaml.cs index 3317d8b..93bfdd7 100644 --- a/Azaion.Annotator/MainWindow.xaml.cs +++ b/Azaion.Annotator/MainWindow.xaml.cs @@ -64,10 +64,19 @@ public partial class MainWindow InitControls(); _suspendLayout = true; + Left = _config.WindowLocation.X; Top = _config.WindowLocation.Y; + Width = _config.WindowSize.Width; Height = _config.WindowSize.Height; + + MainGrid.ColumnDefinitions.FirstOrDefault()!.Width = new GridLength(_config.LeftPanelWidth); + MainGrid.ColumnDefinitions.LastOrDefault()!.Width = new GridLength(_config.RightPanelWidth); + + if (_config.FullScreen) + WindowState = WindowState.Maximized; + _suspendLayout = false; ReloadFiles(); @@ -132,31 +141,30 @@ public partial class MainWindow VideoSlider.KeyDown += (sender, args) => _mediator.Publish(new KeyEvent(sender, args)); Volume.ValueChanged += (_, newValue) => _mediator.Publish(new VolumeChangedEvent((int)newValue)); - - SizeChanged += (sender, args) => - { - if (!_suspendLayout) - { - _config.WindowSize = args.NewSize; - var saveConfigFn = () => _configRepository.Save(_config); - saveConfigFn.Debounce(TimeSpan.FromSeconds(7)).Invoke(); - } - }; - LocationChanged += (_, _) => - { - if (!_suspendLayout) - { - _config.WindowLocation = new Point(Left, Top); - var saveConfigFn = () => _configRepository.Save(_config); - saveConfigFn.Debounce(TimeSpan.FromSeconds(7)).Invoke(); - } - }; + + SizeChanged += (_, _) => SaveUserSettings(); + LocationChanged += (_, _) => SaveUserSettings(); + StateChanged += (_, _) => SaveUserSettings(); Editor.FormState = _formState; Editor.Mediator = _mediator; DgAnnotations.ItemsSource = _formState.AnnotationResults; } + private void SaveUserSettings() + { + if (_suspendLayout) + return; + + _config.LeftPanelWidth = MainGrid.ColumnDefinitions.FirstOrDefault()!.Width.Value; + _config.RightPanelWidth = MainGrid.ColumnDefinitions.LastOrDefault()!.Width.Value; + _config.WindowSize = new Size(Width, Height); + _config.WindowLocation = new Point(Left, Top); + _config.FullScreen = WindowState == WindowState.Maximized; + var saveConfigFn = () => _configRepository.Save(_config); + saveConfigFn.Debounce(TimeSpan.FromSeconds(5)).Invoke(); + } + private void ShowTimeAnnotations(TimeSpan time) { Dispatcher.Invoke(() => VideoSlider.Value = _mediaPlayer.Position * VideoSlider.Maximum); diff --git a/Azaion.Annotator/PlayerControlHandler.cs b/Azaion.Annotator/PlayerControlHandler.cs index e15f137..c09ab33 100644 --- a/Azaion.Annotator/PlayerControlHandler.cs +++ b/Azaion.Annotator/PlayerControlHandler.cs @@ -17,7 +17,7 @@ public class PlayerControlHandler(LibVLC libVLC, MediaPlayer mediaPlayer, MainWi private const int LARGE_STEP = 5000; private const int RESULT_WIDTH = 1280; - private static readonly string[] CatchSenders = ["ForegroundWindow", "ScrollViewer", "VideoView"]; + private static readonly string[] CatchSenders = ["ForegroundWindow", "ScrollViewer", "VideoView", "GridSplitter"]; private readonly Dictionary KeysControlEnumDict = new() { diff --git a/Azaion.Annotator/config.json b/Azaion.Annotator/config.json index 22b6c0c..186ed04 100644 --- a/Azaion.Annotator/config.json +++ b/Azaion.Annotator/config.json @@ -66,5 +66,9 @@ } ], "WindowSize": "1920,1080", - "WindowLocation": "200,121" + "WindowLocation": "200,121", + "FullScreen": true, + "LeftPanelWidth": 30, + "RightPanelWidth": 30, + "ShowHelpOnStart": false } \ No newline at end of file