mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
fix: KeyDown
event won't be triggered unless toolbar got focus (#351)
This commit is contained in:
parent
429e037adb
commit
0646db36a4
2 changed files with 27 additions and 18 deletions
|
@ -20,6 +20,11 @@ namespace SourceGit.Views
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
public bool HasKeyModifier(KeyModifiers modifier)
|
||||
{
|
||||
return _unhandledModifiers.HasFlag(modifier);
|
||||
}
|
||||
|
||||
protected override void OnOpened(EventArgs e)
|
||||
{
|
||||
base.OnOpened(e);
|
||||
|
@ -147,6 +152,17 @@ namespace SourceGit.Views
|
|||
}
|
||||
|
||||
base.OnKeyDown(e);
|
||||
|
||||
if (!e.Handled)
|
||||
{
|
||||
_unhandledModifiers = e.KeyModifiers;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnKeyUp(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyUp(e);
|
||||
_unhandledModifiers = KeyModifiers.None;
|
||||
}
|
||||
|
||||
protected override void OnClosing(WindowClosingEventArgs e)
|
||||
|
@ -178,5 +194,7 @@ namespace SourceGit.Views
|
|||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private KeyModifiers _unhandledModifiers = KeyModifiers.None;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
|
@ -11,18 +12,6 @@ namespace SourceGit.Views
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
_hasCtrl = e.KeyModifiers.HasFlag(KeyModifiers.Control);
|
||||
}
|
||||
|
||||
protected override void OnKeyUp(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyUp(e);
|
||||
_hasCtrl = false;
|
||||
}
|
||||
|
||||
private void OpenWithExternalTools(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button button && DataContext is ViewModels.Repository repo)
|
||||
|
@ -55,25 +44,29 @@ namespace SourceGit.Views
|
|||
|
||||
private void Fetch(object _, RoutedEventArgs e)
|
||||
{
|
||||
(DataContext as ViewModels.Repository)?.Fetch(_hasCtrl);
|
||||
var launcher = this.FindAncestorOfType<Launcher>();
|
||||
(DataContext as ViewModels.Repository)?.Fetch(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void Pull(object _, RoutedEventArgs e)
|
||||
{
|
||||
(DataContext as ViewModels.Repository)?.Pull(_hasCtrl);
|
||||
var launcher = this.FindAncestorOfType<Launcher>();
|
||||
(DataContext as ViewModels.Repository)?.Pull(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void Push(object _, RoutedEventArgs e)
|
||||
{
|
||||
(DataContext as ViewModels.Repository)?.Push(_hasCtrl);
|
||||
var launcher = this.FindAncestorOfType<Launcher>();
|
||||
(DataContext as ViewModels.Repository)?.Push(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void StashAll(object _, RoutedEventArgs e)
|
||||
{
|
||||
(DataContext as ViewModels.Repository)?.StashAll(_hasCtrl);
|
||||
var launcher = this.FindAncestorOfType<Launcher>();
|
||||
(DataContext as ViewModels.Repository)?.StashAll(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
@ -98,8 +91,6 @@ namespace SourceGit.Views
|
|||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private bool _hasCtrl = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue