save window position and left and right panel size

This commit is contained in:
Oleksandr Bezdieniezhnykh
2024-07-23 14:58:35 +03:00
parent d130e6fdcf
commit c72f7fc265
5 changed files with 49 additions and 37 deletions
+11 -13
View File
@@ -18,11 +18,16 @@ public class Config
public List<AnnotationClass> AnnotationClasses { get; set; } = []; public List<AnnotationClass> AnnotationClasses { get; set; } = [];
private Dictionary<int, AnnotationClass>? _annotationClassesDict; private Dictionary<int, AnnotationClass>? _annotationClassesDict;
public Dictionary<int, AnnotationClass> AnnotationClassesDict => _annotationClassesDict ??= AnnotationClasses.ToDictionary(x => x.Id); public Dictionary<int, AnnotationClass> AnnotationClassesDict => _annotationClassesDict ??= AnnotationClasses.ToDictionary(x => x.Id);
public Size WindowSize { get; set; } public Size WindowSize { get; set; }
public Point WindowLocation { get; set; } public Point WindowLocation { get; set; }
public bool ShowHelpOnStart { 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 public interface IConfigRepository
@@ -63,15 +68,8 @@ public class FileConfigRepository(ILogger<FileConfigRepository> logger) : IConfi
ShowHelpOnStart = true ShowHelpOnStart = true
}; };
} }
try var str = File.ReadAllText(CONFIG_PATH);
{ return JsonConvert.DeserializeObject<Config>(str) ?? new Config();
var str = File.ReadAllText(CONFIG_PATH);
return JsonConvert.DeserializeObject<Config>(str) ?? new Config();
}
catch (Exception)
{
return new Config();
}
} }
public void Save(Config config) public void Save(Config config)
+5 -3
View File
@@ -47,9 +47,11 @@
</Style> </Style>
</Window.Resources> </Window.Resources>
<Grid ShowGridLines="False" <Grid
Background="Black" Name="MainGrid"
HorizontalAlignment="Stretch"> ShowGridLines="False"
Background="Black"
HorizontalAlignment="Stretch">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="28"></RowDefinition> <RowDefinition Height="28"></RowDefinition>
<RowDefinition Height="28"></RowDefinition> <RowDefinition Height="28"></RowDefinition>
+27 -19
View File
@@ -64,10 +64,19 @@ public partial class MainWindow
InitControls(); InitControls();
_suspendLayout = true; _suspendLayout = true;
Left = _config.WindowLocation.X; Left = _config.WindowLocation.X;
Top = _config.WindowLocation.Y; Top = _config.WindowLocation.Y;
Width = _config.WindowSize.Width; Width = _config.WindowSize.Width;
Height = _config.WindowSize.Height; 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; _suspendLayout = false;
ReloadFiles(); ReloadFiles();
@@ -132,31 +141,30 @@ public partial class MainWindow
VideoSlider.KeyDown += (sender, args) => _mediator.Publish(new KeyEvent(sender, args)); VideoSlider.KeyDown += (sender, args) => _mediator.Publish(new KeyEvent(sender, args));
Volume.ValueChanged += (_, newValue) => _mediator.Publish(new VolumeChangedEvent((int)newValue)); Volume.ValueChanged += (_, newValue) => _mediator.Publish(new VolumeChangedEvent((int)newValue));
SizeChanged += (sender, args) => SizeChanged += (_, _) => SaveUserSettings();
{ LocationChanged += (_, _) => SaveUserSettings();
if (!_suspendLayout) StateChanged += (_, _) => SaveUserSettings();
{
_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();
}
};
Editor.FormState = _formState; Editor.FormState = _formState;
Editor.Mediator = _mediator; Editor.Mediator = _mediator;
DgAnnotations.ItemsSource = _formState.AnnotationResults; 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) private void ShowTimeAnnotations(TimeSpan time)
{ {
Dispatcher.Invoke(() => VideoSlider.Value = _mediaPlayer.Position * VideoSlider.Maximum); Dispatcher.Invoke(() => VideoSlider.Value = _mediaPlayer.Position * VideoSlider.Maximum);
+1 -1
View File
@@ -17,7 +17,7 @@ public class PlayerControlHandler(LibVLC libVLC, MediaPlayer mediaPlayer, MainWi
private const int LARGE_STEP = 5000; private const int LARGE_STEP = 5000;
private const int RESULT_WIDTH = 1280; 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<Key, PlaybackControlEnum> KeysControlEnumDict = new() private readonly Dictionary<Key, PlaybackControlEnum> KeysControlEnumDict = new()
{ {
+5 -1
View File
@@ -66,5 +66,9 @@
} }
], ],
"WindowSize": "1920,1080", "WindowSize": "1920,1080",
"WindowLocation": "200,121" "WindowLocation": "200,121",
"FullScreen": true,
"LeftPanelWidth": 30,
"RightPanelWidth": 30,
"ShowHelpOnStart": false
} }