mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-29 14:25:00 +00:00
feature: remember main window position (#1315)
Some checks are pending
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions
Localization Check / localization-check (push) Waiting to run
Some checks are pending
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions
Localization Check / localization-check (push) Waiting to run
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
8d5a6bf4e9
commit
f36ab4a189
4 changed files with 65 additions and 17 deletions
|
@ -118,13 +118,8 @@ namespace SourceGit.ViewModels
|
||||||
UpdateTitle();
|
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;
|
_ignoreIndexChange = true;
|
||||||
|
|
||||||
foreach (var one in Pages)
|
foreach (var one in Pages)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
|
@ -18,6 +17,18 @@ namespace SourceGit.ViewModels
|
||||||
set;
|
set;
|
||||||
} = 720;
|
} = 720;
|
||||||
|
|
||||||
|
public int LauncherPositionX
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = int.MinValue;
|
||||||
|
|
||||||
|
public int LauncherPositionY
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = int.MinValue;
|
||||||
|
|
||||||
public WindowState LauncherWindowState
|
public WindowState LauncherWindowState
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
|
|
@ -11,8 +11,7 @@
|
||||||
x:Name="ThisControl"
|
x:Name="ThisControl"
|
||||||
Icon="/App.ico"
|
Icon="/App.ico"
|
||||||
Title="{Binding Title}"
|
Title="{Binding Title}"
|
||||||
MinWidth="1024" MinHeight="600"
|
MinWidth="1024" MinHeight="600">
|
||||||
WindowStartupLocation="CenterScreen">
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="{Binding #ThisControl.CaptionHeight}"/>
|
<RowDefinition Height="{Binding #ThisControl.CaptionHeight}"/>
|
||||||
|
|
|
@ -42,13 +42,6 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
public Launcher()
|
public Launcher()
|
||||||
{
|
{
|
||||||
var layout = ViewModels.Preferences.Instance.Layout;
|
|
||||||
if (layout.LauncherWindowState != WindowState.Maximized)
|
|
||||||
{
|
|
||||||
Width = layout.LauncherWidth;
|
|
||||||
Height = layout.LauncherHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OperatingSystem.IsMacOS())
|
if (OperatingSystem.IsMacOS())
|
||||||
{
|
{
|
||||||
HasLeftCaptionButton = true;
|
HasLeftCaptionButton = true;
|
||||||
|
@ -65,6 +58,31 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
|
|
||||||
InitializeComponent();
|
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()
|
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)
|
protected override void OnKeyDown(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
var vm = DataContext as ViewModels.Launcher;
|
var vm = DataContext as ViewModels.Launcher;
|
||||||
|
@ -311,7 +341,20 @@ namespace SourceGit.Views
|
||||||
base.OnClosing(e);
|
base.OnClosing(e);
|
||||||
|
|
||||||
if (!Design.IsDesignMode && DataContext is ViewModels.Launcher launcher)
|
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)
|
private void OnOpenWorkspaceMenu(object sender, RoutedEventArgs e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue