refactor: replace all window with custom ChromelessWindow

This commit is contained in:
leo 2024-06-13 11:54:10 +08:00
parent 68061f82b1
commit f5b35d3db2
No known key found for this signature in database
GPG key ID: B528468E49CD0E58
23 changed files with 414 additions and 649 deletions

View file

@ -7,8 +7,17 @@ using Avalonia.Interactivity;
namespace SourceGit.Views
{
public partial class Launcher : Window, Models.INotificationReceiver
public partial class Launcher : ChromelessWindow, Models.INotificationReceiver
{
public static readonly StyledProperty<GridLength> TitleBarHeightProperty =
AvaloniaProperty.Register<Launcher, GridLength>(nameof(TitleBarHeight), new GridLength(38, GridUnitType.Pixel));
public GridLength TitleBarHeight
{
get => GetValue(TitleBarHeightProperty);
set => SetValue(TitleBarHeightProperty, value);
}
public Launcher()
{
DataContext = new ViewModels.Launcher();
@ -34,6 +43,20 @@ namespace SourceGit.Views
}
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WindowStateProperty)
{
var state = (WindowState)change.NewValue;
if (state == WindowState.Maximized)
SetCurrentValue(TitleBarHeightProperty, new GridLength(OperatingSystem.IsMacOS() ? 34 : 30));
else
SetCurrentValue(TitleBarHeightProperty, new GridLength(38, GridUnitType.Pixel));
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
var vm = DataContext as ViewModels.Launcher;
@ -136,36 +159,20 @@ namespace SourceGit.Views
base.OnClosing(e);
}
private void MaximizeOrRestoreWindow(object sender, TappedEventArgs e)
private void OnTitleBarDoubleTapped(object sender, TappedEventArgs e)
{
if (WindowState == WindowState.Maximized)
{
WindowState = WindowState.Normal;
}
else
{
WindowState = WindowState.Maximized;
}
e.Handled = true;
}
private void CustomResizeWindow(object sender, PointerPressedEventArgs e)
{
if (sender is Border border)
{
if (border.Tag is WindowEdge edge)
{
BeginResizeDrag(edge, e);
}
}
e.Handled = true;
}
private void BeginMoveWindow(object sender, PointerPressedEventArgs e)
{
if (e.ClickCount != 2)
{
BeginMoveDrag(e);
}
}
private void ScrollTabs(object sender, PointerWheelEventArgs e)