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;
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
|
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-02-05 23:08:37 -08:00
|
|
|
InitializeComponent();
|
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-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
|
|
|
{
|
|
|
|
var state = (WindowState)change.NewValue;
|
|
|
|
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-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-05-05 03:19:59 -07:00
|
|
|
else if (e.Key == Key.T)
|
|
|
|
{
|
|
|
|
vm.AddNewTab();
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
2024-05-05 04:45:28 -07:00
|
|
|
else 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-05-05 19:22:13 -07:00
|
|
|
else if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Left) ||
|
|
|
|
(!OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab))
|
|
|
|
{
|
|
|
|
vm.GotoPrevTab();
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
else if (vm.ActivePage.Data is ViewModels.Repository repo)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
else if (e.Key == Key.D2 || e.Key == Key.NumPad2)
|
|
|
|
{
|
2024-03-04 18:46:08 -08:00
|
|
|
repo.SelectedViewIndex = 1;
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else if (e.Key == Key.D3 || e.Key == Key.NumPad3)
|
|
|
|
{
|
2024-03-04 18:46:08 -08:00
|
|
|
repo.SelectedViewIndex = 2;
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
else if (e.Key == Key.F)
|
|
|
|
{
|
2024-05-05 19:22:13 -07:00
|
|
|
repo.IsSearching = true;
|
2024-03-04 18:46:08 -08:00
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
2024-06-25 18:31:58 -07:00
|
|
|
else if (e.Key == Key.H && e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
vm.Quit();
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnClosing(e);
|
|
|
|
}
|
|
|
|
|
2024-06-12 20:54:10 -07:00
|
|
|
private void OnTitleBarDoubleTapped(object sender, 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-03-17 18:37:06 -07:00
|
|
|
private void BeginMoveWindow(object sender, PointerPressedEventArgs e)
|
|
|
|
{
|
2024-05-13 19:51:15 -07:00
|
|
|
if (e.ClickCount != 2)
|
2024-06-13 02:55:22 -07:00
|
|
|
_pressedTitleBar = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void MoveWindow(object sender, PointerEventArgs e)
|
|
|
|
{
|
|
|
|
if (!_pressedTitleBar)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var visual = (Visual)e.Source;
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void EndMoveWindow(object sender, PointerReleasedEventArgs e)
|
|
|
|
{
|
|
|
|
_pressedTitleBar = false;
|
2024-06-26 05:56:29 -07:00
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnPopupSure(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (DataContext is ViewModels.Launcher vm)
|
2024-02-05 23:08:37 -08:00
|
|
|
vm.ActivePage.ProcessPopup();
|
2024-06-26 05:56:29 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnPopupCancel(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (DataContext is ViewModels.Launcher vm)
|
2024-02-05 23:08:37 -08:00
|
|
|
vm.ActivePage.CancelPopup();
|
2024-06-26 05:56:29 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnPopupCancelByClickMask(object sender, PointerPressedEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
OnPopupCancel(sender, e);
|
|
|
|
}
|
|
|
|
|
2024-06-26 05:56:29 -07:00
|
|
|
private void OnDismissNotification(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is Button btn && DataContext is ViewModels.Launcher vm)
|
|
|
|
vm.DismissNotification(btn.DataContext as ViewModels.Notification);
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|