mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 13:20:30 +08:00
feature: remember main window position (#1315)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -118,13 +118,8 @@ namespace SourceGit.ViewModels
|
||||
UpdateTitle();
|
||||
}
|
||||
|
||||
public void Quit(double width, double height)
|
||||
public void Quit()
|
||||
{
|
||||
var pref = Preferences.Instance;
|
||||
pref.Layout.LauncherWidth = width;
|
||||
pref.Layout.LauncherHeight = height;
|
||||
pref.Save();
|
||||
|
||||
_ignoreIndexChange = true;
|
||||
|
||||
foreach (var one in Pages)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
@@ -18,6 +17,18 @@ namespace SourceGit.ViewModels
|
||||
set;
|
||||
} = 720;
|
||||
|
||||
public int LauncherPositionX
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = int.MinValue;
|
||||
|
||||
public int LauncherPositionY
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = int.MinValue;
|
||||
|
||||
public WindowState LauncherWindowState
|
||||
{
|
||||
get;
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
x:Name="ThisControl"
|
||||
Icon="/App.ico"
|
||||
Title="{Binding Title}"
|
||||
MinWidth="1024" MinHeight="600"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
MinWidth="1024" MinHeight="600">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="{Binding #ThisControl.CaptionHeight}"/>
|
||||
|
||||
@@ -42,13 +42,6 @@ namespace SourceGit.Views
|
||||
|
||||
public Launcher()
|
||||
{
|
||||
var layout = ViewModels.Preferences.Instance.Layout;
|
||||
if (layout.LauncherWindowState != WindowState.Maximized)
|
||||
{
|
||||
Width = layout.LauncherWidth;
|
||||
Height = layout.LauncherHeight;
|
||||
}
|
||||
|
||||
if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
HasLeftCaptionButton = true;
|
||||
@@ -65,6 +58,31 @@ namespace SourceGit.Views
|
||||
}
|
||||
|
||||
InitializeComponent();
|
||||
PositionChanged += OnPositionChanged;
|
||||
|
||||
var layout = ViewModels.Preferences.Instance.Layout;
|
||||
Width = layout.LauncherWidth;
|
||||
Height = layout.LauncherHeight;
|
||||
|
||||
var x = layout.LauncherPositionX;
|
||||
var y = layout.LauncherPositionY;
|
||||
if (x != int.MinValue && y != int.MinValue && Screens is { } screens)
|
||||
{
|
||||
var position = new PixelPoint(x, y);
|
||||
var size = new PixelSize((int)layout.LauncherWidth, (int)layout.LauncherHeight);
|
||||
var desiredRect = new PixelRect(position, size);
|
||||
for (var i = 0; i < screens.ScreenCount; i++)
|
||||
{
|
||||
var screen = screens.All[i];
|
||||
if (screen.WorkingArea.Contains(desiredRect))
|
||||
{
|
||||
Position = position;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
}
|
||||
|
||||
public void BringToTop()
|
||||
@@ -113,6 +131,18 @@ namespace SourceGit.Views
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnSizeChanged(SizeChangedEventArgs e)
|
||||
{
|
||||
base.OnSizeChanged(e);
|
||||
|
||||
if (WindowState == WindowState.Normal)
|
||||
{
|
||||
var layout = ViewModels.Preferences.Instance.Layout;
|
||||
layout.LauncherWidth = Width;
|
||||
layout.LauncherHeight = Height;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
var vm = DataContext as ViewModels.Launcher;
|
||||
@@ -311,7 +341,20 @@ namespace SourceGit.Views
|
||||
base.OnClosing(e);
|
||||
|
||||
if (!Design.IsDesignMode && DataContext is ViewModels.Launcher launcher)
|
||||
launcher.Quit(Width, Height);
|
||||
{
|
||||
ViewModels.Preferences.Instance.Save();
|
||||
launcher.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPositionChanged(object sender, PixelPointEventArgs e)
|
||||
{
|
||||
if (WindowState == WindowState.Normal)
|
||||
{
|
||||
var layout = ViewModels.Preferences.Instance.Layout;
|
||||
layout.LauncherPositionX = Position.X;
|
||||
layout.LauncherPositionY = Position.Y;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOpenWorkspaceMenu(object sender, RoutedEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user