mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 09:46:30 +00:00
save window position and left and right panel size
This commit is contained in:
@@ -18,11 +18,16 @@ public class Config
|
||||
public List<AnnotationClass> AnnotationClasses { get; set; } = [];
|
||||
|
||||
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 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<FileConfigRepository> logger) : IConfi
|
||||
ShowHelpOnStart = true
|
||||
};
|
||||
}
|
||||
try
|
||||
{
|
||||
var str = File.ReadAllText(CONFIG_PATH);
|
||||
return JsonConvert.DeserializeObject<Config>(str) ?? new Config();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new Config();
|
||||
}
|
||||
var str = File.ReadAllText(CONFIG_PATH);
|
||||
return JsonConvert.DeserializeObject<Config>(str) ?? new Config();
|
||||
}
|
||||
|
||||
public void Save(Config config)
|
||||
|
||||
@@ -47,9 +47,11 @@
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid ShowGridLines="False"
|
||||
Background="Black"
|
||||
HorizontalAlignment="Stretch">
|
||||
<Grid
|
||||
Name="MainGrid"
|
||||
ShowGridLines="False"
|
||||
Background="Black"
|
||||
HorizontalAlignment="Stretch">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="28"></RowDefinition>
|
||||
<RowDefinition Height="28"></RowDefinition>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -66,5 +66,9 @@
|
||||
}
|
||||
],
|
||||
"WindowSize": "1920,1080",
|
||||
"WindowLocation": "200,121"
|
||||
"WindowLocation": "200,121",
|
||||
"FullScreen": true,
|
||||
"LeftPanelWidth": 30,
|
||||
"RightPanelWidth": 30,
|
||||
"ShowHelpOnStart": false
|
||||
}
|
||||
Reference in New Issue
Block a user