mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 17:53:32 +00:00
UI - Store window size and position
This commit is contained in:
parent
dbad6744f3
commit
9b09942bda
@ -1,10 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using Artemis.Core.Plugins.Models;
|
using Artemis.Core.Plugins.Models;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
public static class Constants
|
public static class Constants
|
||||||
{
|
{
|
||||||
|
public static readonly string ApplicationFolder = Path.GetDirectoryName(typeof(Constants).Assembly.Location);
|
||||||
public static readonly string DataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Artemis\\";
|
public static readonly string DataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Artemis\\";
|
||||||
public static readonly string ConnectionString = $"FileName={DataFolder}\\database.db";
|
public static readonly string ConnectionString = $"FileName={DataFolder}\\database.db";
|
||||||
public static readonly PluginInfo CorePluginInfo = new PluginInfo {Guid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"), Name = "Artemis Core"};
|
public static readonly PluginInfo CorePluginInfo = new PluginInfo {Guid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"), Name = "Artemis Core"};
|
||||||
|
|||||||
@ -12,6 +12,7 @@ using Artemis.UI.Screens.Settings;
|
|||||||
using Artemis.UI.Screens.Sidebar;
|
using Artemis.UI.Screens.Sidebar;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services.Interfaces;
|
||||||
using Artemis.UI.Utilities;
|
using Artemis.UI.Utilities;
|
||||||
|
using MaterialDesignExtensions.Controls;
|
||||||
using MaterialDesignThemes.Wpf;
|
using MaterialDesignThemes.Wpf;
|
||||||
using Stylet;
|
using Stylet;
|
||||||
|
|
||||||
@ -23,8 +24,10 @@ namespace Artemis.UI.Screens
|
|||||||
private readonly ICoreService _coreService;
|
private readonly ICoreService _coreService;
|
||||||
private readonly IDebugService _debugService;
|
private readonly IDebugService _debugService;
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
|
private readonly ISettingsService _settingsService;
|
||||||
private readonly ThemeWatcher _themeWatcher;
|
private readonly ThemeWatcher _themeWatcher;
|
||||||
private readonly Timer _titleUpdateTimer;
|
private readonly Timer _titleUpdateTimer;
|
||||||
|
private readonly PluginSetting<WindowSize> _windowSize;
|
||||||
private bool _lostFocus;
|
private bool _lostFocus;
|
||||||
|
|
||||||
public RootViewModel(IEventAggregator eventAggregator, SidebarViewModel sidebarViewModel, ISettingsService settingsService, ICoreService coreService,
|
public RootViewModel(IEventAggregator eventAggregator, SidebarViewModel sidebarViewModel, ISettingsService settingsService, ICoreService coreService,
|
||||||
@ -33,12 +36,14 @@ namespace Artemis.UI.Screens
|
|||||||
SidebarViewModel = sidebarViewModel;
|
SidebarViewModel = sidebarViewModel;
|
||||||
MainMessageQueue = snackbarMessageQueue;
|
MainMessageQueue = snackbarMessageQueue;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
|
_settingsService = settingsService;
|
||||||
_coreService = coreService;
|
_coreService = coreService;
|
||||||
_debugService = debugService;
|
_debugService = debugService;
|
||||||
|
|
||||||
_titleUpdateTimer = new Timer(500);
|
_titleUpdateTimer = new Timer(500);
|
||||||
_titleUpdateTimer.Elapsed += (sender, args) => UpdateWindowTitle();
|
_titleUpdateTimer.Elapsed += (sender, args) => UpdateWindowTitle();
|
||||||
_colorScheme = settingsService.GetSetting("UI.ColorScheme", ApplicationColorScheme.Automatic);
|
_colorScheme = settingsService.GetSetting("UI.ColorScheme", ApplicationColorScheme.Automatic);
|
||||||
|
_windowSize = settingsService.GetSetting<WindowSize>("UI.RootWindowSize");
|
||||||
_colorScheme.SettingChanged += (sender, args) => ApplyColorSchemeSetting();
|
_colorScheme.SettingChanged += (sender, args) => ApplyColorSchemeSetting();
|
||||||
_themeWatcher = new ThemeWatcher();
|
_themeWatcher = new ThemeWatcher();
|
||||||
_themeWatcher.ThemeChanged += (sender, args) => ApplyWindowsTheme(args.Theme);
|
_themeWatcher.ThemeChanged += (sender, args) => ApplyWindowsTheme(args.Theme);
|
||||||
@ -54,7 +59,7 @@ namespace Artemis.UI.Screens
|
|||||||
public bool IsSidebarVisible { get; set; }
|
public bool IsSidebarVisible { get; set; }
|
||||||
public bool ActiveItemReady { get; set; }
|
public bool ActiveItemReady { get; set; }
|
||||||
public string WindowTitle { get; set; }
|
public string WindowTitle { get; set; }
|
||||||
|
|
||||||
public void WindowDeactivated()
|
public void WindowDeactivated()
|
||||||
{
|
{
|
||||||
var windowState = ((Window) View).WindowState;
|
var windowState = ((Window) View).WindowState;
|
||||||
@ -89,16 +94,6 @@ namespace Artemis.UI.Screens
|
|||||||
_eventAggregator.Publish(new MainWindowKeyEvent(false, e));
|
_eventAggregator.Publish(new MainWindowKeyEvent(false, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnActivate()
|
|
||||||
{
|
|
||||||
UpdateWindowTitle();
|
|
||||||
_titleUpdateTimer.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnDeactivate()
|
|
||||||
{
|
|
||||||
_titleUpdateTimer.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateWindowTitle()
|
private void UpdateWindowTitle()
|
||||||
{
|
{
|
||||||
@ -152,5 +147,39 @@ namespace Artemis.UI.Screens
|
|||||||
var extensionsPaletteHelper = new MaterialDesignExtensions.Themes.PaletteHelper();
|
var extensionsPaletteHelper = new MaterialDesignExtensions.Themes.PaletteHelper();
|
||||||
extensionsPaletteHelper.SetLightDark(colorScheme == ApplicationColorScheme.Dark);
|
extensionsPaletteHelper.SetLightDark(colorScheme == ApplicationColorScheme.Dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Overrides of Screen
|
||||||
|
|
||||||
|
protected override void OnViewLoaded()
|
||||||
|
{
|
||||||
|
var window = (MaterialWindow) View;
|
||||||
|
if (_windowSize.Value != null)
|
||||||
|
_windowSize.Value.ApplyToWindow(window);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_windowSize.Value = new WindowSize();
|
||||||
|
_windowSize.Value.ApplyFromWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnViewLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnActivate()
|
||||||
|
{
|
||||||
|
UpdateWindowTitle();
|
||||||
|
_titleUpdateTimer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDeactivate()
|
||||||
|
{
|
||||||
|
_titleUpdateTimer.Stop();
|
||||||
|
|
||||||
|
var window = (MaterialWindow) View;
|
||||||
|
_windowSize.Value ??= new WindowSize();
|
||||||
|
_windowSize.Value.ApplyFromWindow(window);
|
||||||
|
_windowSize.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
32
src/Artemis.UI/Utilities/WindowState.cs
Normal file
32
src/Artemis.UI/Utilities/WindowState.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using System.Windows;
|
||||||
|
using MaterialDesignExtensions.Controls;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Utilities
|
||||||
|
{
|
||||||
|
public class WindowSize
|
||||||
|
{
|
||||||
|
public double Top { get; set; }
|
||||||
|
public double Left { get; set; }
|
||||||
|
public double Width { get; set; }
|
||||||
|
public double Height { get; set; }
|
||||||
|
public bool IsMaximized { get; set; }
|
||||||
|
|
||||||
|
public void ApplyFromWindow(MaterialWindow window)
|
||||||
|
{
|
||||||
|
Top = window.Top;
|
||||||
|
Left = window.Left;
|
||||||
|
Height = window.Height;
|
||||||
|
Width = window.Width;
|
||||||
|
IsMaximized = window.WindowState == WindowState.Maximized;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ApplyToWindow(MaterialWindow window)
|
||||||
|
{
|
||||||
|
window.Top = Top;
|
||||||
|
window.Left = Left;
|
||||||
|
window.Height = Height;
|
||||||
|
window.Width = Width;
|
||||||
|
window.WindowState = IsMaximized ? WindowState.Maximized : WindowState.Normal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user