code_review: PR #431

* move resources and styles for macOS caption button to `CaptionButtonsMacOS` because it is never used by others and should not been changed
* add `IsCloseButtonOnly` property to `CaptionButtons` and `CaptionButtonsMacOS` and replace the controls in windows
This commit is contained in:
leo 2024-09-01 16:54:20 +08:00
parent e3ee07be70
commit e19d025572
No known key found for this signature in database
25 changed files with 269 additions and 339 deletions

View file

@ -429,85 +429,6 @@
<Setter Property="Stroke" Value="Red"/> <Setter Property="Stroke" Value="Red"/>
</Style> </Style>
<Style Selector="Button.caption_button_macos">
<Setter Property="Width" Value="24"/>
<Setter Property="Height" Value="24"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style Selector="Button.caption_button_macos:nth-child(1)">
<Setter Property="Margin" Value="6,0,0,0"/>
</Style>
<Style Selector="Button.caption_button_macos Ellipse">
<Setter Property="Width" Value="14"/>
<Setter Property="Height" Value="14"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="StrokeThickness" Value=".5"/>
<Setter Property="Stroke" Value="#40000000"/>
</Style>
<Style Selector="Button.caption_button_macos.close Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.Close}"/>
</Style>
<Style Selector="Button.caption_button_macos.minimize Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.Minimize}"/>
</Style>
<Style Selector="Button.caption_button_macos.maximize Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.Maximize}"/>
</Style>
<Style Selector="Button.caption_button_macos.close:pressed Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.ClosePressed}"/>
</Style>
<Style Selector="Button.caption_button_macos.minimize:pressed Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MinimizePressed}"/>
</Style>
<Style Selector="Button.caption_button_macos.maximize:pressed Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MaximizePressed}"/>
</Style>
<Style Selector="Button.caption_button_macos Path">
<Setter Property="Width" Value="8"/>
<Setter Property="Height" Value="8"/>
<Setter Property="Stretch" Value="Fill"/>
<Setter Property="Fill" Value="Black"/>
<Setter Property="IsVisible" Value="False"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style Selector="Button.caption_button_macos.close Path">
<Setter Property="Width" Value="6"/>
<Setter Property="Height" Value="6"/>
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.CloseFG}"/>
<Setter Property="Data" Value="{StaticResource Icons.MacOS.Close}"/>
</Style>
<Style Selector="Button.caption_button_macos.minimize Path">
<Setter Property="Width" Value="8"/>
<Setter Property="Height" Value="2"/>
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MinimizeFG}"/>
<Setter Property="Data" Value="{StaticResource Icons.MacOS.Minimize}"/>
</Style>
<Style Selector="Button.caption_button_macos.maximize Path">
<Setter Property="Width" Value="6"/>
<Setter Property="Height" Value="6"/>
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MaximizeFG}"/>
<Setter Property="Data" Value="{StaticResource Icons.MacOS.Maximize}"/>
</Style>
<Style Selector="Button.caption_button_macos.close:pressed Path">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.ClosePressedFG}"/>
</Style>
<Style Selector="Button.caption_button_macos.minimize:pressed Path">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MinimizePressedFG}"/>
</Style>
<Style Selector="Button.caption_button_macos.maximize:pressed Path">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MaximizePressedFG}"/>
</Style>
<Style Selector="Grid.caption_button_box:pointerover Button.caption_button_macos Path">
<Setter Property="IsVisible" Value="True"/>
</Style>
<Style Selector="Button.caption_button_macos /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="Button.caption_button_macos:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="Button.caption_button"> <Style Selector="Button.caption_button">
<Setter Property="Width" Value="48"/> <Setter Property="Width" Value="48"/>
<Setter Property="BorderThickness" Value="0"/> <Setter Property="BorderThickness" Value="0"/>

View file

@ -2,18 +2,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.ThemeDictionaries> <ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light"> <ResourceDictionary x:Key="Light">
<Color x:Key="Color.MacOS.Close">#FFED6A5E</Color>
<Color x:Key="Color.MacOS.CloseFG">#FF69110A</Color>
<Color x:Key="Color.MacOS.ClosePressed">#FFB24F46</Color>
<Color x:Key="Color.MacOS.ClosePressedFG">#FF2E0402</Color>
<Color x:Key="Color.MacOS.Minimize">#FFF4BF4F</Color>
<Color x:Key="Color.MacOS.MinimizeFG">#FF8F591D</Color>
<Color x:Key="Color.MacOS.MinimizePressed">#FFB78F3A</Color>
<Color x:Key="Color.MacOS.MinimizePressedFG">#FF522A0A</Color>
<Color x:Key="Color.MacOS.Maximize">#FF61C554</Color>
<Color x:Key="Color.MacOS.MaximizeFG">#FF296017</Color>
<Color x:Key="Color.MacOS.MaximizePressed">#FF48943F</Color>
<Color x:Key="Color.MacOS.MaximizePressedFG">#FF102F07</Color>
<Color x:Key="Color.Window">#FFF0F5F9</Color> <Color x:Key="Color.Window">#FFF0F5F9</Color>
<Color x:Key="Color.WindowBorder">#00000000</Color> <Color x:Key="Color.WindowBorder">#00000000</Color>
<Color x:Key="Color.TitleBar">#FFCFDEEA</Color> <Color x:Key="Color.TitleBar">#FFCFDEEA</Color>
@ -46,18 +34,6 @@
</ResourceDictionary> </ResourceDictionary>
<ResourceDictionary x:Key="Dark"> <ResourceDictionary x:Key="Dark">
<Color x:Key="Color.MacOS.Close">#FFED6A5E</Color>
<Color x:Key="Color.MacOS.CloseFG">#FF8C1A10</Color>
<Color x:Key="Color.MacOS.ClosePressed">#FFF09389</Color>
<Color x:Key="Color.MacOS.ClosePressedFG">#FF69120A</Color>
<Color x:Key="Color.MacOS.Minimize">#FFF4BF4F</Color>
<Color x:Key="Color.MacOS.MinimizeFG">#FF8F591D</Color>
<Color x:Key="Color.MacOS.MinimizePressed">#FFFBEB74</Color>
<Color x:Key="Color.MacOS.MinimizePressedFG">#FF705F1B</Color>
<Color x:Key="Color.MacOS.Maximize">#FF61C554</Color>
<Color x:Key="Color.MacOS.MaximizeFG">#FF296017</Color>
<Color x:Key="Color.MacOS.MaximizePressed">#FF86F37F</Color>
<Color x:Key="Color.MacOS.MaximizePressedFG">#FF2C681A</Color>
<Color x:Key="Color.Window">#FF252525</Color> <Color x:Key="Color.Window">#FF252525</Color>
<Color x:Key="Color.WindowBorder">#FF444444</Color> <Color x:Key="Color.WindowBorder">#FF444444</Color>
<Color x:Key="Color.TitleBar">#FF1F1F1F</Color> <Color x:Key="Color.TitleBar">#FF1F1F1F</Color>
@ -90,18 +66,6 @@
</ResourceDictionary> </ResourceDictionary>
</ResourceDictionary.ThemeDictionaries> </ResourceDictionary.ThemeDictionaries>
<SolidColorBrush x:Key="Brush.MacOS.Close" Color="{DynamicResource Color.MacOS.Close}"/>
<SolidColorBrush x:Key="Brush.MacOS.CloseFG" Color="{DynamicResource Color.MacOS.CloseFG}"/>
<SolidColorBrush x:Key="Brush.MacOS.ClosePressed" Color="{DynamicResource Color.MacOS.ClosePressed}"/>
<SolidColorBrush x:Key="Brush.MacOS.ClosePressedFG" Color="{DynamicResource Color.MacOS.ClosePressedFG}"/>
<SolidColorBrush x:Key="Brush.MacOS.Minimize" Color="{DynamicResource Color.MacOS.Minimize}"/>
<SolidColorBrush x:Key="Brush.MacOS.MinimizeFG" Color="{DynamicResource Color.MacOS.MinimizeFG}"/>
<SolidColorBrush x:Key="Brush.MacOS.MinimizePressed" Color="{DynamicResource Color.MacOS.MinimizePressed}"/>
<SolidColorBrush x:Key="Brush.MacOS.MinimizePressedFG" Color="{DynamicResource Color.MacOS.MinimizePressedFG}"/>
<SolidColorBrush x:Key="Brush.MacOS.Maximize" Color="{DynamicResource Color.MacOS.Maximize}"/>
<SolidColorBrush x:Key="Brush.MacOS.MaximizeFG" Color="{DynamicResource Color.MacOS.MaximizeFG}"/>
<SolidColorBrush x:Key="Brush.MacOS.MaximizePressed" Color="{DynamicResource Color.MacOS.MaximizePressed}"/>
<SolidColorBrush x:Key="Brush.MacOS.MaximizePressedFG" Color="{DynamicResource Color.MacOS.MaximizePressedFG}"/>
<SolidColorBrush x:Key="Brush.Window" Color="{DynamicResource Color.Window}"/> <SolidColorBrush x:Key="Brush.Window" Color="{DynamicResource Color.Window}"/>
<SolidColorBrush x:Key="Brush.WindowBorder" Color="{DynamicResource Color.WindowBorder}"/> <SolidColorBrush x:Key="Brush.WindowBorder" Color="{DynamicResource Color.WindowBorder}"/>
<SolidColorBrush x:Key="Brush.TitleBar" Color="{DynamicResource Color.TitleBar}"/> <SolidColorBrush x:Key="Brush.TitleBar" Color="{DynamicResource Color.TitleBar}"/>

View file

@ -25,14 +25,10 @@
Data="{StaticResource Icons.Info}" Data="{StaticResource Icons.Info}"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -40,12 +36,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" <v:CaptionButtons Grid.Column="2"
Classes="caption_button" IsCloseButtonOnly="True"
Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"/>
IsVisible="{OnPlatform True, macOS=False}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid> </Grid>
<Grid Grid.Row="1" ColumnDefinitions="Auto,*"> <Grid Grid.Row="1" ColumnDefinitions="Auto,*">

View file

@ -1,7 +1,5 @@
using System.Reflection; using System.Reflection;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity;
namespace SourceGit.Views namespace SourceGit.Views
{ {
@ -28,11 +26,6 @@ namespace SourceGit.Views
BeginMoveDrag(e); BeginMoveDrag(e);
} }
private void CloseWindow(object _1, RoutedEventArgs _2)
{
Close();
}
private void OnVisitAvaloniaUI(object _, PointerPressedEventArgs e) private void OnVisitAvaloniaUI(object _, PointerPressedEventArgs e)
{ {
Native.OS.OpenBrowser("https://www.avaloniaui.net/"); Native.OS.OpenBrowser("https://www.avaloniaui.net/");

View file

@ -25,14 +25,10 @@
Data="{StaticResource Icons.Password}" Data="{StaticResource Icons.Password}"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -40,12 +36,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" <v:CaptionButtons Grid.Column="2"
Classes="caption_button" IsCloseButtonOnly="True"
Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"/>
IsVisible="{OnPlatform True, macOS=False}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid> </Grid>
<StackPanel Grid.Row="1" Margin="0,16" Orientation="Vertical"> <StackPanel Grid.Row="1" Margin="0,16" Orientation="Vertical">

View file

@ -28,14 +28,10 @@
Data="{StaticResource Icons.File.Ignore}" Data="{StaticResource Icons.File.Ignore}"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -43,12 +39,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" <v:CaptionButtons Grid.Column="2"
Classes="caption_button" IsCloseButtonOnly="True"
Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"/>
IsVisible="{OnPlatform True, macOS=False}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid> </Grid>
<!-- Unchanged Files --> <!-- Unchanged Files -->

View file

@ -16,11 +16,6 @@ namespace SourceGit.Views
BeginMoveDrag(e); BeginMoveDrag(e);
} }
private void CloseWindow(object _1, RoutedEventArgs _2)
{
Close();
}
private void OnRemoveButtonClicked(object sender, RoutedEventArgs e) private void OnRemoveButtonClicked(object sender, RoutedEventArgs e)
{ {
if (DataContext is ViewModels.AssumeUnchangedManager vm && sender is Button button) if (DataContext is ViewModels.AssumeUnchangedManager vm && sender is Button button)

View file

@ -1,3 +1,4 @@
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.VisualTree; using Avalonia.VisualTree;
@ -6,6 +7,15 @@ namespace SourceGit.Views
{ {
public partial class CaptionButtons : UserControl public partial class CaptionButtons : UserControl
{ {
public static readonly StyledProperty<bool> IsCloseButtonOnlyProperty =
AvaloniaProperty.Register<CaptionButtons, bool>(nameof(IsCloseButtonOnly));
public bool IsCloseButtonOnly
{
get => GetValue(IsCloseButtonOnlyProperty);
set => SetValue(IsCloseButtonOnlyProperty, value);
}
public CaptionButtons() public CaptionButtons()
{ {
InitializeComponent(); InitializeComponent();

View file

@ -3,22 +3,152 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.CaptionButtonsMacOS"> x:Class="SourceGit.Views.CaptionButtonsMacOS"
x:Name="ThisControl">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<Color x:Key="Color.MacOS.Close">#FFED6A5E</Color>
<Color x:Key="Color.MacOS.CloseFG">#FF69110A</Color>
<Color x:Key="Color.MacOS.ClosePressed">#FFB24F46</Color>
<Color x:Key="Color.MacOS.ClosePressedFG">#FF2E0402</Color>
<Color x:Key="Color.MacOS.Minimize">#FFF4BF4F</Color>
<Color x:Key="Color.MacOS.MinimizeFG">#FF8F591D</Color>
<Color x:Key="Color.MacOS.MinimizePressed">#FFB78F3A</Color>
<Color x:Key="Color.MacOS.MinimizePressedFG">#FF522A0A</Color>
<Color x:Key="Color.MacOS.Maximize">#FF61C554</Color>
<Color x:Key="Color.MacOS.MaximizeFG">#FF296017</Color>
<Color x:Key="Color.MacOS.MaximizePressed">#FF48943F</Color>
<Color x:Key="Color.MacOS.MaximizePressedFG">#FF102F07</Color>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<Color x:Key="Color.MacOS.Close">#FFED6A5E</Color>
<Color x:Key="Color.MacOS.CloseFG">#FF8C1A10</Color>
<Color x:Key="Color.MacOS.ClosePressed">#FFF09389</Color>
<Color x:Key="Color.MacOS.ClosePressedFG">#FF69120A</Color>
<Color x:Key="Color.MacOS.Minimize">#FFF4BF4F</Color>
<Color x:Key="Color.MacOS.MinimizeFG">#FF8F591D</Color>
<Color x:Key="Color.MacOS.MinimizePressed">#FFFBEB74</Color>
<Color x:Key="Color.MacOS.MinimizePressedFG">#FF705F1B</Color>
<Color x:Key="Color.MacOS.Maximize">#FF61C554</Color>
<Color x:Key="Color.MacOS.MaximizeFG">#FF296017</Color>
<Color x:Key="Color.MacOS.MaximizePressed">#FF86F37F</Color>
<Color x:Key="Color.MacOS.MaximizePressedFG">#FF2C681A</Color>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<SolidColorBrush x:Key="Brush.MacOS.Close" Color="{DynamicResource Color.MacOS.Close}"/>
<SolidColorBrush x:Key="Brush.MacOS.CloseFG" Color="{DynamicResource Color.MacOS.CloseFG}"/>
<SolidColorBrush x:Key="Brush.MacOS.ClosePressed" Color="{DynamicResource Color.MacOS.ClosePressed}"/>
<SolidColorBrush x:Key="Brush.MacOS.ClosePressedFG" Color="{DynamicResource Color.MacOS.ClosePressedFG}"/>
<SolidColorBrush x:Key="Brush.MacOS.Minimize" Color="{DynamicResource Color.MacOS.Minimize}"/>
<SolidColorBrush x:Key="Brush.MacOS.MinimizeFG" Color="{DynamicResource Color.MacOS.MinimizeFG}"/>
<SolidColorBrush x:Key="Brush.MacOS.MinimizePressed" Color="{DynamicResource Color.MacOS.MinimizePressed}"/>
<SolidColorBrush x:Key="Brush.MacOS.MinimizePressedFG" Color="{DynamicResource Color.MacOS.MinimizePressedFG}"/>
<SolidColorBrush x:Key="Brush.MacOS.Maximize" Color="{DynamicResource Color.MacOS.Maximize}"/>
<SolidColorBrush x:Key="Brush.MacOS.MaximizeFG" Color="{DynamicResource Color.MacOS.MaximizeFG}"/>
<SolidColorBrush x:Key="Brush.MacOS.MaximizePressed" Color="{DynamicResource Color.MacOS.MaximizePressed}"/>
<SolidColorBrush x:Key="Brush.MacOS.MaximizePressedFG" Color="{DynamicResource Color.MacOS.MaximizePressedFG}"/>
</ResourceDictionary>
</UserControl.Resources>
<UserControl.Styles>
<Style Selector="Button">
<Setter Property="Width" Value="24"/>
<Setter Property="Height" Value="24"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style Selector="Button /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="Button>Grid>Ellipse">
<Setter Property="Width" Value="14"/>
<Setter Property="Height" Value="14"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="StrokeThickness" Value=".5"/>
<Setter Property="Stroke" Value="#40000000"/>
</Style>
<Style Selector="Button.close>Grid>Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.Close}"/>
</Style>
<Style Selector="Button.minimize>Grid>Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.Minimize}"/>
</Style>
<Style Selector="Button.maximize>Grid>Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.Maximize}"/>
</Style>
<Style Selector="Button.close:pressed>Grid>Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.ClosePressed}"/>
</Style>
<Style Selector="Button.minimize:pressed>Grid>Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MinimizePressed}"/>
</Style>
<Style Selector="Button.maximize:pressed>Grid>Ellipse">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MaximizePressed}"/>
</Style>
<Style Selector="Button>Grid>Path">
<Setter Property="Stretch" Value="Fill"/>
<Setter Property="Fill" Value="Black"/>
<Setter Property="IsVisible" Value="False"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style Selector="Button.close>Grid>Path">
<Setter Property="Width" Value="6"/>
<Setter Property="Height" Value="6"/>
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.CloseFG}"/>
<Setter Property="Data" Value="{StaticResource Icons.MacOS.Close}"/>
</Style>
<Style Selector="Button.minimize>Grid>Path">
<Setter Property="Width" Value="8"/>
<Setter Property="Height" Value="2"/>
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MinimizeFG}"/>
<Setter Property="Data" Value="{StaticResource Icons.MacOS.Minimize}"/>
</Style>
<Style Selector="Button.maximize>Grid>Path">
<Setter Property="Width" Value="6"/>
<Setter Property="Height" Value="6"/>
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MaximizeFG}"/>
<Setter Property="Data" Value="{StaticResource Icons.MacOS.Maximize}"/>
</Style>
<Style Selector="Button.close:pressed>Grid>Path">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.ClosePressedFG}"/>
</Style>
<Style Selector="Button.minimize:pressed>Grid>Path">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MinimizePressedFG}"/>
</Style>
<Style Selector="Button.maximize:pressed>Grid>Path">
<Setter Property="Fill" Value="{DynamicResource Brush.MacOS.MaximizePressedFG}"/>
</Style>
<Style Selector="Grid.caption_button_box:pointerover>StackPanel>Button>Grid>Path">
<Setter Property="IsVisible" Value="True"/>
</Style>
</UserControl.Styles>
<Grid Classes="caption_button_box"> <Grid Classes="caption_button_box">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal" Margin="8,0,0,0">
<Button Classes="caption_button_macos close" Click="CloseWindow" Margin="10,0,0,0"> <Button Classes="close" Click="CloseWindow">
<Grid> <Grid>
<Ellipse/> <Ellipse/>
<Path/> <Path/>
</Grid> </Grid>
</Button> </Button>
<Button Classes="caption_button_macos minimize" Click="MinimizeWindow"> <Button Classes="minimize" Click="MinimizeWindow" IsVisible="{Binding !#ThisControl.IsCloseButtonOnly}">
<Grid> <Grid>
<Ellipse/> <Ellipse/>
<Path/> <Path/>
</Grid> </Grid>
</Button> </Button>
<Button Classes="caption_button_macos maximize" Click="MaximizeOrRestoreWindow"> <Button Classes="maximize" Click="MaximizeOrRestoreWindow" IsVisible="{Binding !#ThisControl.IsCloseButtonOnly}">
<Grid> <Grid>
<Ellipse/> <Ellipse/>
<Path/> <Path/>

View file

@ -1,3 +1,4 @@
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.VisualTree; using Avalonia.VisualTree;
@ -6,6 +7,15 @@ namespace SourceGit.Views
{ {
public partial class CaptionButtonsMacOS : UserControl public partial class CaptionButtonsMacOS : UserControl
{ {
public static readonly StyledProperty<bool> IsCloseButtonOnlyProperty =
AvaloniaProperty.Register<CaptionButtonsMacOS, bool>(nameof(IsCloseButtonOnly));
public bool IsCloseButtonOnly
{
get => GetValue(IsCloseButtonOnlyProperty);
set => SetValue(IsCloseButtonOnlyProperty, value);
}
public CaptionButtonsMacOS() public CaptionButtonsMacOS()
{ {
InitializeComponent(); InitializeComponent();
@ -32,9 +42,7 @@ namespace SourceGit.Views
private void CloseWindow(object _, RoutedEventArgs e) private void CloseWindow(object _, RoutedEventArgs e)
{ {
var window = this.FindAncestorOfType<Window>(); var window = this.FindAncestorOfType<Window>();
if (window != null) window?.Close();
window.Close();
e.Handled = true; e.Handled = true;
} }
} }

View file

@ -25,14 +25,10 @@
Data="{StaticResource Icons.Info}" Data="{StaticResource Icons.Info}"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -40,12 +36,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" <v:CaptionButtons Grid.Column="2"
Classes="caption_button" IsCloseButtonOnly="True"
Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"/>
IsVisible="{OnPlatform True, macOS=False}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid> </Grid>
<StackPanel Grid.Row="1" Margin="0,16" Orientation="Vertical"> <StackPanel Grid.Row="1" Margin="0,16" Orientation="Vertical">

View file

@ -27,14 +27,10 @@
Data="{StaticResource Icons.Hotkeys}" Data="{StaticResource Icons.Hotkeys}"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -42,12 +38,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" <v:CaptionButtons Grid.Column="2"
Classes="caption_button" IsCloseButtonOnly="True"
Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"/>
IsVisible="{OnPlatform True, macOS=False}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid> </Grid>
<!-- Body --> <!-- Body -->

View file

@ -1,5 +1,4 @@
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity;
namespace SourceGit.Views namespace SourceGit.Views
{ {
@ -14,10 +13,5 @@ namespace SourceGit.Views
{ {
BeginMoveDrag(e); BeginMoveDrag(e);
} }
private void CloseWindow(object _1, RoutedEventArgs _2)
{
Close();
}
} }
} }

View file

@ -28,14 +28,10 @@
Data="{StaticResource Icons.InteractiveRebase}" Data="{StaticResource Icons.InteractiveRebase}"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -43,12 +39,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" <v:CaptionButtons Grid.Column="2"
Classes="caption_button" IsCloseButtonOnly="True"
Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"/>
IsVisible="{OnPlatform True, macOS=False}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid> </Grid>
<!-- Operation Information --> <!-- Operation Information -->

View file

@ -27,14 +27,10 @@
Data="{StaticResource Icons.Lock}" Data="{StaticResource Icons.Lock}"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -42,12 +38,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" <v:CaptionButtons Grid.Column="2"
Classes="caption_button" IsCloseButtonOnly="True"
Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"/>
IsVisible="{OnPlatform True, macOS=False}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid> </Grid>
<!-- Locked Files --> <!-- Locked Files -->

View file

@ -16,11 +16,6 @@ namespace SourceGit.Views
BeginMoveDrag(e); BeginMoveDrag(e);
} }
private void CloseWindow(object _1, RoutedEventArgs _2)
{
Close();
}
private void OnUnlockButtonClicked(object sender, RoutedEventArgs e) private void OnUnlockButtonClicked(object sender, RoutedEventArgs e)
{ {
if (DataContext is ViewModels.LFSLocks vm && sender is Button button) if (DataContext is ViewModels.LFSLocks vm && sender is Button button)

View file

@ -29,14 +29,10 @@
Margin="10,0,0,0" Margin="10,0,0,0"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -44,9 +40,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" Classes="caption_button" Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"> <v:CaptionButtons Grid.Column="2"
<Path Data="{StaticResource Icons.Window.Close}"/> IsCloseButtonOnly="True"
</Button> IsVisible="{OnPlatform True, macOS=False}"/>
</Grid> </Grid>
<!-- Body --> <!-- Body -->

View file

@ -125,12 +125,7 @@ namespace SourceGit.Views
} }
} }
private void BeginMoveWindow(object _, PointerPressedEventArgs e) protected override void OnClosing(WindowClosingEventArgs e)
{
BeginMoveDrag(e);
}
private void CloseWindow(object _1, RoutedEventArgs _2)
{ {
var config = new Commands.Config(null).ListAll(); var config = new Commands.Config(null).ListAll();
SetIfChanged(config, "user.name", DefaultUser); SetIfChanged(config, "user.name", DefaultUser);
@ -144,7 +139,12 @@ namespace SourceGit.Views
if (!GPGFormat.Value.Equals("ssh", StringComparison.Ordinal)) if (!GPGFormat.Value.Equals("ssh", StringComparison.Ordinal))
SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGExecutableFile); SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGExecutableFile);
Close(); base.OnClosing(e);
}
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
{
BeginMoveDrag(e);
} }
private async void SelectThemeOverrideFile(object _, RoutedEventArgs e) private async void SelectThemeOverrideFile(object _, RoutedEventArgs e)

View file

@ -28,14 +28,10 @@
Margin="10,0,0,0" Margin="10,0,0,0"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -43,9 +39,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" Classes="caption_button" Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"> <v:CaptionButtons Grid.Column="2"
<Path Data="{StaticResource Icons.Window.Close}"/> IsCloseButtonOnly="True"
</Button> IsVisible="{OnPlatform True, macOS=False}"/>
</Grid> </Grid>
<!-- Body --> <!-- Body -->

View file

@ -1,5 +1,5 @@
using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity;
namespace SourceGit.Views namespace SourceGit.Views
{ {
@ -10,15 +10,15 @@ namespace SourceGit.Views
InitializeComponent(); InitializeComponent();
} }
protected override void OnClosing(WindowClosingEventArgs e)
{
(DataContext as ViewModels.RepositoryConfigure)?.Save();
base.OnClosing(e);
}
private void BeginMoveWindow(object _, PointerPressedEventArgs e) private void BeginMoveWindow(object _, PointerPressedEventArgs e)
{ {
BeginMoveDrag(e); BeginMoveDrag(e);
} }
private void CloseWindow(object _1, RoutedEventArgs _2)
{
(DataContext as ViewModels.RepositoryConfigure)?.Save();
Close();
}
} }
} }

View file

@ -29,14 +29,10 @@
Data="{StaticResource Icons.SoftwareUpdate}" Data="{StaticResource Icons.SoftwareUpdate}"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -44,12 +40,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" <v:CaptionButtons Grid.Column="2"
Classes="caption_button" IsCloseButtonOnly="True"
Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"/>
IsVisible="{OnPlatform True, macOS=False}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid> </Grid>
<!-- Body --> <!-- Body -->

View file

@ -26,14 +26,10 @@
Data="{StaticResource Icons.Edit}" Data="{StaticResource Icons.Edit}"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -41,12 +37,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" <v:CaptionButtons Grid.Column="2"
Classes="caption_button" IsCloseButtonOnly="True"
Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"/>
IsVisible="{OnPlatform True, macOS=False}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid> </Grid>
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="8"> <StackPanel Grid.Row="1" Orientation="Vertical" Margin="8">

View file

@ -1,3 +1,4 @@
using System;
using System.IO; using System.IO;
using Avalonia.Input; using Avalonia.Input;
@ -33,22 +34,25 @@ namespace SourceGit.Views
} }
} }
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
App.Quit(_exitCode);
}
private void BeginMoveWindow(object _, PointerPressedEventArgs e) private void BeginMoveWindow(object _, PointerPressedEventArgs e)
{ {
BeginMoveDrag(e); BeginMoveDrag(e);
} }
private void CloseWindow(object _1, RoutedEventArgs _2)
{
App.Quit(-1);
}
private void SaveAndClose(object _1, RoutedEventArgs _2) private void SaveAndClose(object _1, RoutedEventArgs _2)
{ {
File.WriteAllText(_file, Editor.Text); File.WriteAllText(_file, Editor.Text);
App.Quit(0); _exitCode = 0;
Close();
} }
private readonly string _file; private readonly string _file;
private int _exitCode = -1;
} }
} }

View file

@ -27,14 +27,10 @@
Data="{StaticResource Icons.Statistics}" Data="{StaticResource Icons.Statistics}"
IsVisible="{OnPlatform True, macOS=False}"/> IsVisible="{OnPlatform True, macOS=False}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}"> <v:CaptionButtonsMacOS Grid.Column="0"
<Button Classes="caption_button_macos close" Click="CloseWindow"> Margin="0,2,0,0"
<Grid> IsCloseButtonOnly="True"
<Ellipse/> IsVisible="{OnPlatform False, macOS=True}"/>
<Path/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold" Classes="bold"
@ -42,12 +38,9 @@
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Button Grid.Column="2" <v:CaptionButtons Grid.Column="2"
Classes="caption_button" IsCloseButtonOnly="True"
Click="CloseWindow" IsVisible="{OnPlatform True, macOS=False}"/>
IsVisible="{OnPlatform True, macOS=False}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid> </Grid>
<!-- View mode switcher --> <!-- View mode switcher -->

View file

@ -5,7 +5,6 @@ using System.Globalization;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media; using Avalonia.Media;
namespace SourceGit.Views namespace SourceGit.Views
@ -227,10 +226,5 @@ namespace SourceGit.Views
{ {
BeginMoveDrag(e); BeginMoveDrag(e);
} }
private void CloseWindow(object _1, RoutedEventArgs _2)
{
Close();
}
} }
} }