增加布局存储和还原
This commit is contained in:
23
SpineViewer/Models/MainWindowLayoutModel.cs
Normal file
23
SpineViewer/Models/MainWindowLayoutModel.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace SpineViewer.Models
|
||||
{
|
||||
public class MainWindowLayoutModel
|
||||
{
|
||||
public double WindowLeft { get; set; }
|
||||
public double WindowTop { get; set; }
|
||||
public double WindowWidth { get; set; }
|
||||
public double WindowHeight { get; set; }
|
||||
public WindowState WindowState { get; set; }
|
||||
|
||||
public double RootGridCol0Width { get; set; }
|
||||
public double ModelListRow0Height { get; set; }
|
||||
public double ExplorerGridRow0Height { get; set; }
|
||||
public double RightPanelGridRow0Height { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@
|
||||
</Border>
|
||||
|
||||
<Border Grid.Row="1">
|
||||
<Grid>
|
||||
<Grid x:Name="_rootGrid">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
@@ -91,7 +91,7 @@
|
||||
|
||||
<!-- 模型列表页 -->
|
||||
<TabItem Header="{DynamicResource Str_SpineObject}">
|
||||
<Grid>
|
||||
<Grid x:Name="_modelListGrid">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -578,7 +578,7 @@
|
||||
|
||||
<!-- 浏览页 -->
|
||||
<TabItem Header="{DynamicResource Str_Explorer}" DataContext="{Binding ExplorerListViewModel}">
|
||||
<Grid>
|
||||
<Grid x:Name="_explorerGrid">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -785,7 +785,7 @@
|
||||
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
|
||||
|
||||
<Border Grid.Column="2">
|
||||
<Grid>
|
||||
<Grid x:Name="_rightPanelGrid">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="5*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
|
||||
@@ -3,12 +3,15 @@ using NLog;
|
||||
using NLog.Layouts;
|
||||
using NLog.Targets;
|
||||
using Spine;
|
||||
using SpineViewer.Models;
|
||||
using SpineViewer.Natives;
|
||||
using SpineViewer.Resources;
|
||||
using SpineViewer.Utils;
|
||||
using SpineViewer.ViewModels.MainWindow;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -26,6 +29,11 @@ namespace SpineViewer.Views;
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// 布局文件保存路径
|
||||
/// </summary>
|
||||
public static readonly string LayoutFilePath = Path.Combine(Path.GetDirectoryName(Environment.ProcessPath), "layout.json");
|
||||
|
||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
private ListViewItem? _listViewDragSourceItem = null;
|
||||
private Point _listViewDragSourcePoint;
|
||||
@@ -46,6 +54,8 @@ public partial class MainWindow : Window
|
||||
|
||||
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
LoadLayout();
|
||||
|
||||
var vm = _vm.SFMLRendererViewModel;
|
||||
_renderPanel.CanvasMouseWheelScrolled += vm.CanvasMouseWheelScrolled;
|
||||
_renderPanel.CanvasMouseButtonPressed += vm.CanvasMouseButtonPressed;
|
||||
@@ -70,6 +80,8 @@ public partial class MainWindow : Window
|
||||
{
|
||||
var vm = _vm.SFMLRendererViewModel;
|
||||
vm.StopRender();
|
||||
|
||||
SaveLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,6 +112,50 @@ public partial class MainWindow : Window
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
|
||||
private void LoadLayout()
|
||||
{
|
||||
if (JsonHelper.Deserialize<MainWindowLayoutModel>(LayoutFilePath, out var m, true))
|
||||
{
|
||||
Left = m.WindowLeft;
|
||||
Top = m.WindowTop;
|
||||
Width = m.WindowWidth;
|
||||
Height = m.WindowHeight;
|
||||
if (m.WindowState == WindowState.Maximized)
|
||||
{
|
||||
WindowState = WindowState.Maximized;
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowState = WindowState.Normal;
|
||||
}
|
||||
|
||||
_rootGrid.ColumnDefinitions[0].Width = new(m.RootGridCol0Width);
|
||||
_modelListGrid.RowDefinitions[0].Height = new(m.ModelListRow0Height);
|
||||
_explorerGrid.RowDefinitions[0].Height = new(m.ExplorerGridRow0Height);
|
||||
_rightPanelGrid.RowDefinitions[0].Height = new(m.RightPanelGridRow0Height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SaveLayout()
|
||||
{
|
||||
var m = new MainWindowLayoutModel()
|
||||
{
|
||||
WindowLeft = Left,
|
||||
WindowTop = Top,
|
||||
WindowWidth = Width,
|
||||
WindowHeight = Height,
|
||||
WindowState = WindowState,
|
||||
|
||||
RootGridCol0Width = _rootGrid.ColumnDefinitions[0].ActualWidth,
|
||||
ModelListRow0Height = _modelListGrid.RowDefinitions[0].ActualHeight,
|
||||
ExplorerGridRow0Height = _explorerGrid.RowDefinitions[0].ActualHeight,
|
||||
RightPanelGridRow0Height = _rightPanelGrid.RowDefinitions[0].ActualHeight,
|
||||
};
|
||||
|
||||
JsonHelper.Serialize(m, LayoutFilePath);
|
||||
}
|
||||
|
||||
#region _spinesListView 事件处理
|
||||
|
||||
private void SpinesListView_RequestSelectionChanging(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user