sourcegit/src/Views/FileHistories.axaml.cs
leo e3c0f7d496
refactor: rewrite chromeless window (#634)
* use system chrome instead of custom caption button on macOS
* move `BeginMoveWindow` and `MaximizeOrRestoreWindow` to `ChromelessWindow`
* better supports for fullscreen mode on macOS
* redesign the layout of title bar for all windows

Signed-off-by: leo <longshuang@msn.cn>
2024-11-01 09:38:42 +08:00

65 lines
1.9 KiB
C#

using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
public partial class FileHistories : ChromelessWindow
{
public static readonly StyledProperty<bool> HasLeftCaptionButtonProperty =
AvaloniaProperty.Register<FileHistories, bool>(nameof(HasLeftCaptionButton));
public bool HasLeftCaptionButton
{
get => GetValue(HasLeftCaptionButtonProperty);
set => SetValue(HasLeftCaptionButtonProperty, value);
}
public FileHistories()
{
if (OperatingSystem.IsMacOS())
HasLeftCaptionButton = true;
InitializeComponent();
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WindowStateProperty)
HasLeftCaptionButton = WindowState != WindowState.FullScreen;
}
private void OnPressCommitSHA(object sender, PointerPressedEventArgs e)
{
if (sender is TextBlock { DataContext: Models.Commit commit } &&
DataContext is ViewModels.FileHistories vm)
{
vm.NavigateToCommit(commit);
}
e.Handled = true;
}
private void OnResetToSelectedRevision(object _, RoutedEventArgs e)
{
if (DataContext is ViewModels.FileHistories vm)
{
vm.ResetToSelectedRevision();
NotifyDonePanel.IsVisible = true;
}
e.Handled = true;
}
private void OnCloseNotifyPanel(object _, PointerPressedEventArgs e)
{
NotifyDonePanel.IsVisible = false;
e.Handled = true;
}
}
}