mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:16: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; } = [];
|
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)
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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();
|
||||||
@@ -133,30 +142,29 @@ public partial class MainWindow
|
|||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -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()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -66,5 +66,9 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"WindowSize": "1920,1080",
|
"WindowSize": "1920,1080",
|
||||||
"WindowLocation": "200,121"
|
"WindowLocation": "200,121",
|
||||||
|
"FullScreen": true,
|
||||||
|
"LeftPanelWidth": 30,
|
||||||
|
"RightPanelWidth": 30,
|
||||||
|
"ShowHelpOnStart": false
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user