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
+5 -7
View File
@@ -22,6 +22,11 @@ public class Config
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; }
}
@@ -63,16 +68,9 @@ public class FileConfigRepository(ILogger<FileConfigRepository> logger) : IConfi
ShowHelpOnStart = true
};
}
try
{
var str = File.ReadAllText(CONFIG_PATH);
return JsonConvert.DeserializeObject<Config>(str) ?? new Config();
}
catch (Exception)
{
return new Config();
}
}
public void Save(Config config)
{
+3 -1
View File
@@ -47,7 +47,9 @@
</Style>
</Window.Resources>
<Grid ShowGridLines="False"
<Grid
Name="MainGrid"
ShowGridLines="False"
Background="Black"
HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
+26 -18
View File
@@ -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();
@@ -133,30 +142,29 @@ public partial class MainWindow
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);
+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 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()
{
+5 -1
View File
@@ -66,5 +66,9 @@
}
],
"WindowSize": "1920,1080",
"WindowLocation": "200,121"
"WindowLocation": "200,121",
"FullScreen": true,
"LeftPanelWidth": 30,
"RightPanelWidth": 30,
"ShowHelpOnStart": false
}