2024-03-17 18:37:06 -07:00
|
|
|
using System;
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
using Avalonia;
|
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Input;
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
namespace SourceGit.Views
|
|
|
|
{
|
2024-06-26 05:56:29 -07:00
|
|
|
public partial class Launcher : ChromelessWindow
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
|
|
|
public Launcher()
|
|
|
|
{
|
2024-06-27 07:06:05 -07:00
|
|
|
var layout = ViewModels.Preference.Instance.Layout;
|
|
|
|
WindowState = layout.LauncherWindowState;
|
|
|
|
|
|
|
|
if (WindowState != WindowState.Maximized)
|
|
|
|
{
|
|
|
|
Width = layout.LauncherWidth;
|
|
|
|
Height = layout.LauncherHeight;
|
|
|
|
}
|
2024-06-27 18:37:43 -07:00
|
|
|
|
|
|
|
InitializeComponent();
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-06-12 20:54:10 -07:00
|
|
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
|
|
|
{
|
|
|
|
base.OnPropertyChanged(change);
|
|
|
|
|
2024-06-27 07:06:05 -07:00
|
|
|
if (change.Property == WindowStateProperty && MainLayout != null)
|
2024-06-12 20:54:10 -07:00
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
var state = (WindowState)change.NewValue!;
|
2024-06-12 20:54:10 -07:00
|
|
|
if (state == WindowState.Maximized)
|
2024-06-26 05:56:29 -07:00
|
|
|
MainLayout.RowDefinitions[0].Height = new GridLength(OperatingSystem.IsMacOS() ? 34 : 30);
|
2024-06-12 20:54:10 -07:00
|
|
|
else
|
2024-06-26 05:56:29 -07:00
|
|
|
MainLayout.RowDefinitions[0].Height = new GridLength(38);
|
2024-06-27 07:06:05 -07:00
|
|
|
|
|
|
|
ViewModels.Preference.Instance.Layout.LauncherWindowState = state;
|
2024-06-12 20:54:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnKeyDown(KeyEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var vm = DataContext as ViewModels.Launcher;
|
2024-07-14 00:55:15 -07:00
|
|
|
if (vm == null)
|
|
|
|
return;
|
2024-05-11 03:06:31 -07:00
|
|
|
|
|
|
|
// Ctrl+Shift+P opens preference dialog (macOS use hotkeys in system menu bar)
|
|
|
|
if (!OperatingSystem.IsMacOS() && e.KeyModifiers == (KeyModifiers.Control | KeyModifiers.Shift) && e.Key == Key.P)
|
|
|
|
{
|
|
|
|
App.OpenPreferenceCommand.Execute(null);
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-05 03:19:59 -07:00
|
|
|
if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Meta)) ||
|
|
|
|
(!OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Control)))
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
|
|
|
if (e.Key == Key.W)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
vm.CloseTab(null);
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-07-14 00:55:15 -07:00
|
|
|
|
|
|
|
if (e.Key == Key.T)
|
2024-05-05 03:19:59 -07:00
|
|
|
{
|
|
|
|
vm.AddNewTab();
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
2024-07-14 00:55:15 -07:00
|
|
|
|
|
|
|
if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Right) ||
|
2024-05-05 19:22:13 -07:00
|
|
|
(!OperatingSystem.IsMacOS() && !e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab))
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
vm.GotoNextTab();
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-07-14 00:55:15 -07:00
|
|
|
|
|
|
|
if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Left) ||
|
2024-05-05 19:22:13 -07:00
|
|
|
(!OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab))
|
|
|
|
{
|
|
|
|
vm.GotoPrevTab();
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
2024-07-14 00:55:15 -07:00
|
|
|
|
|
|
|
if (vm.ActivePage.Data is ViewModels.Repository repo)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
|
|
|
if (e.Key == Key.D1 || e.Key == Key.NumPad1)
|
|
|
|
{
|
2024-03-04 18:46:08 -08:00
|
|
|
repo.SelectedViewIndex = 0;
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-07-14 00:55:15 -07:00
|
|
|
|
|
|
|
if (e.Key == Key.D2 || e.Key == Key.NumPad2)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-03-04 18:46:08 -08:00
|
|
|
repo.SelectedViewIndex = 1;
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-07-14 00:55:15 -07:00
|
|
|
|
|
|
|
if (e.Key == Key.D3 || e.Key == Key.NumPad3)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-03-04 18:46:08 -08:00
|
|
|
repo.SelectedViewIndex = 2;
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-07-14 00:55:15 -07:00
|
|
|
|
|
|
|
if (e.Key == Key.F)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-05 19:22:13 -07:00
|
|
|
repo.IsSearching = true;
|
2024-03-04 18:46:08 -08:00
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
2024-07-14 00:55:15 -07:00
|
|
|
|
|
|
|
if (e.Key == Key.H && e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
2024-06-25 18:31:58 -07:00
|
|
|
{
|
|
|
|
repo.IsSearching = false;
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (e.Key == Key.Escape)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
vm.ActivePage.CancelPopup();
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
2024-04-27 19:19:12 -07:00
|
|
|
else if (e.Key == Key.F5)
|
|
|
|
{
|
|
|
|
if (vm.ActivePage.Data is ViewModels.Repository repo)
|
|
|
|
{
|
|
|
|
repo.RefreshAll();
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
base.OnKeyDown(e);
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnClosing(WindowClosingEventArgs e)
|
|
|
|
{
|
2024-06-27 07:06:05 -07:00
|
|
|
var pref = ViewModels.Preference.Instance;
|
|
|
|
pref.Layout.LauncherWidth = Width;
|
|
|
|
pref.Layout.LauncherHeight = Height;
|
|
|
|
|
2024-02-19 03:54:53 -08:00
|
|
|
var vm = DataContext as ViewModels.Launcher;
|
2024-07-14 00:55:15 -07:00
|
|
|
vm?.Quit();
|
2024-02-19 03:54:53 -08:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnClosing(e);
|
|
|
|
}
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
private void OnTitleBarDoubleTapped(object _, TappedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-06-13 05:26:24 -07:00
|
|
|
_pressedTitleBar = false;
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (WindowState == WindowState.Maximized)
|
2024-02-05 23:08:37 -08:00
|
|
|
WindowState = WindowState.Normal;
|
2024-03-17 18:37:06 -07:00
|
|
|
else
|
2024-02-05 23:08:37 -08:00
|
|
|
WindowState = WindowState.Maximized;
|
|
|
|
|
2024-06-12 20:54:10 -07:00
|
|
|
e.Handled = true;
|
2024-03-14 03:23:36 -07:00
|
|
|
}
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-13 19:51:15 -07:00
|
|
|
if (e.ClickCount != 2)
|
2024-06-13 02:55:22 -07:00
|
|
|
_pressedTitleBar = true;
|
|
|
|
}
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
private void MoveWindow(object _, PointerEventArgs e)
|
2024-06-13 02:55:22 -07:00
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
if (!_pressedTitleBar || e.Source == null)
|
2024-06-13 02:55:22 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
var visual = (Visual)e.Source;
|
2024-07-14 00:55:15 -07:00
|
|
|
if (visual == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#pragma warning disable CS0618
|
2024-06-13 02:55:22 -07:00
|
|
|
BeginMoveDrag(new PointerPressedEventArgs(
|
2024-06-13 18:46:30 -07:00
|
|
|
e.Source,
|
2024-06-13 02:55:22 -07:00
|
|
|
e.Pointer,
|
2024-06-13 18:46:30 -07:00
|
|
|
visual,
|
|
|
|
e.GetPosition(visual),
|
|
|
|
e.Timestamp,
|
|
|
|
new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.LeftButtonPressed),
|
2024-06-13 02:55:22 -07:00
|
|
|
e.KeyModifiers));
|
2024-07-14 00:55:15 -07:00
|
|
|
#pragma warning restore CS0618
|
2024-06-13 02:55:22 -07:00
|
|
|
}
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
private void EndMoveWindow(object _1, PointerReleasedEventArgs _2)
|
2024-06-13 02:55:22 -07:00
|
|
|
{
|
|
|
|
_pressedTitleBar = false;
|
2024-07-09 21:11:51 -07:00
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-06-13 02:55:22 -07:00
|
|
|
private bool _pressedTitleBar = false;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
}
|