Public Access
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Input;
|
|
using Avalonia.Interactivity;
|
|
|
|
namespace DodoSSH.Client.App.Views;
|
|
|
|
/// <summary>Settings mode's own titlebar — see the remark in the markup for why it is not TitleBar itself.</summary>
|
|
internal sealed partial class SettingsTitleBar : UserControl
|
|
{
|
|
public SettingsTitleBar() => InitializeComponent();
|
|
|
|
private readonly CaptionPresses presses = new();
|
|
|
|
private Window? Host => TopLevel.GetTopLevel(this) as Window;
|
|
|
|
/// <summary>Left button only, and only on a press nothing inside the bar has already handled.</summary>
|
|
private void OnDrag(object? sender, PointerPressedEventArgs e)
|
|
{
|
|
if (e.Handled || !e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Decided on the press, before the drag would take it: see CaptionPresses.
|
|
if (presses.IsSecond(e, this))
|
|
{
|
|
OnToggleMaximised(sender, e);
|
|
e.Handled = true;
|
|
|
|
return;
|
|
}
|
|
|
|
Host?.BeginMoveDrag(e);
|
|
}
|
|
|
|
private void OnMinimise(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (Host is { } window)
|
|
{
|
|
window.WindowState = WindowState.Minimized;
|
|
}
|
|
}
|
|
|
|
/// <summary>Both the button and a double-click on the bar arrive here, as Windows convention expects.</summary>
|
|
/// <remarks>The double-click by way of <see cref="OnDrag"/>; see <see cref="CaptionPresses"/>.</remarks>
|
|
private void OnToggleMaximised(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (Host is not { } window)
|
|
{
|
|
return;
|
|
}
|
|
|
|
window.WindowState = window.WindowState == WindowState.Maximized
|
|
? WindowState.Normal
|
|
: WindowState.Maximized;
|
|
}
|
|
|
|
private void OnClose(object? sender, RoutedEventArgs e) => Host?.Close();
|
|
}
|