Skip to content

Commit f44749a

Browse files
committed
refactor: use Tapped event instead of Click to access KeyModifers
Signed-off-by: leo <[email protected]>
1 parent eb04c87 commit f44749a

File tree

4 files changed

+28
-70
lines changed

4 files changed

+28
-70
lines changed

src/ViewModels/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ public void Fetch(bool autoStart)
820820

821821
public void Pull(bool autoStart)
822822
{
823-
if (!CanCreatePopup())
823+
if (IsBare || !CanCreatePopup())
824824
return;
825825

826826
if (_remotes.Count == 0)

src/Views/Launcher.axaml.cs

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,6 @@ public void BringToTop()
9393
Activate();
9494
}
9595

96-
public bool HasKeyModifier(KeyModifiers modifier)
97-
{
98-
return _unhandledModifiers.HasFlag(modifier);
99-
}
100-
101-
public void ClearKeyModifier()
102-
{
103-
_unhandledModifiers = KeyModifiers.None;
104-
}
105-
10696
protected override void OnOpened(EventArgs e)
10797
{
10898
base.OnOpened(e);
@@ -148,9 +138,6 @@ protected override async void OnKeyDown(KeyEventArgs e)
148138
if (DataContext is not ViewModels.Launcher vm)
149139
return;
150140

151-
// We should clear all unhandled key modifiers.
152-
_unhandledModifiers = KeyModifiers.None;
153-
154141
// Check for AltGr (which is detected as Ctrl+Alt)
155142
bool isAltGr = e.KeyModifiers.HasFlag(KeyModifiers.Control) &&
156143
e.KeyModifiers.HasFlag(KeyModifiers.Alt);
@@ -264,6 +251,17 @@ protected override async void OnKeyDown(KeyEventArgs e)
264251
repo.IsSearching = false;
265252
e.Handled = true;
266253
return;
254+
case Key.Down:
255+
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
256+
repo.Pull(true);
257+
else
258+
repo.Fetch(true);
259+
e.Handled = true;
260+
return;
261+
case Key.Up when e.KeyModifiers.HasFlag(KeyModifiers.Shift):
262+
repo.Push(true);
263+
e.Handled = true;
264+
return;
267265
}
268266
}
269267
else
@@ -301,27 +299,6 @@ protected override async void OnKeyDown(KeyEventArgs e)
301299
}
302300

303301
base.OnKeyDown(e);
304-
305-
// Record unhandled key modifiers.
306-
if (!e.Handled)
307-
{
308-
_unhandledModifiers = e.KeyModifiers;
309-
310-
if (!_unhandledModifiers.HasFlag(KeyModifiers.Alt) && e.Key is Key.LeftAlt or Key.RightAlt)
311-
_unhandledModifiers |= KeyModifiers.Alt;
312-
313-
if (!_unhandledModifiers.HasFlag(KeyModifiers.Control) && e.Key is Key.LeftCtrl or Key.RightCtrl)
314-
_unhandledModifiers |= KeyModifiers.Control;
315-
316-
if (!_unhandledModifiers.HasFlag(KeyModifiers.Shift) && e.Key is Key.LeftShift or Key.RightShift)
317-
_unhandledModifiers |= KeyModifiers.Shift;
318-
}
319-
}
320-
321-
protected override void OnKeyUp(KeyEventArgs e)
322-
{
323-
base.OnKeyUp(e);
324-
_unhandledModifiers = KeyModifiers.None;
325302
}
326303

327304
protected override void OnClosing(WindowClosingEventArgs e)
@@ -363,7 +340,6 @@ private void OnCancelSwitcher(object sender, PointerPressedEventArgs e)
363340
e.Handled = true;
364341
}
365342

366-
private KeyModifiers _unhandledModifiers = KeyModifiers.None;
367343
private WindowState _lastWindowState = WindowState.Normal;
368344
}
369345
}

src/Views/RepositoryToolbar.axaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</StackPanel>
2828

2929
<StackPanel Grid.Column="1" Orientation="Horizontal">
30-
<Button Classes="icon_button" Width="32" Click="Fetch" HotKey="{OnPlatform Ctrl+Down, macOS=⌘+Down}">
30+
<Button Classes="icon_button" Width="32" Tapped="Fetch">
3131
<ToolTip.Tip>
3232
<StackPanel Orientation="Vertical">
3333
<TextBlock Text="{DynamicResource Text.Fetch}"/>
@@ -38,7 +38,7 @@
3838
<Path Width="14" Height="14" Data="{StaticResource Icons.Fetch}"/>
3939
</Button>
4040

41-
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Click="Pull" IsVisible="{Binding !IsBare}" IsEnabled="{Binding !IsBare}" HotKey="{OnPlatform Ctrl+Shift+Down, macOS=⌘+Shift+Down}">
41+
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Tapped="Pull" IsVisible="{Binding !IsBare}" IsEnabled="{Binding !IsBare}">
4242
<ToolTip.Tip>
4343
<StackPanel Orientation="Vertical">
4444
<TextBlock Text="{DynamicResource Text.Pull}"/>
@@ -49,7 +49,7 @@
4949
<Path Width="14" Height="14" Data="{StaticResource Icons.Pull}"/>
5050
</Button>
5151

52-
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Click="Push" HotKey="{OnPlatform Ctrl+Shift+Up, macOS=⌘+Shift+Up}">
52+
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Tapped="Push">
5353
<ToolTip.Tip>
5454
<StackPanel Orientation="Vertical">
5555
<TextBlock Text="{DynamicResource Text.Push}"/>
@@ -60,7 +60,7 @@
6060
<Path Width="14" Height="14" Data="{StaticResource Icons.Push}"/>
6161
</Button>
6262

63-
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Click="StashAll" IsVisible="{Binding !IsBare}">
63+
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Tapped="StashAll" IsVisible="{Binding !IsBare}">
6464
<ToolTip.Tip>
6565
<StackPanel Orientation="Vertical">
6666
<TextBlock Text="{DynamicResource Text.Stash}"/>

src/Views/RepositoryToolbar.axaml.cs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,56 +40,38 @@ private async void OpenConfigure(object sender, RoutedEventArgs e)
4040
}
4141
}
4242

43-
private void Fetch(object _, RoutedEventArgs e)
43+
private void Fetch(object sender, TappedEventArgs e)
4444
{
45-
var launcher = this.FindAncestorOfType<Launcher>();
46-
if (launcher is not null && DataContext is ViewModels.Repository repo)
45+
if (DataContext is ViewModels.Repository repo)
4746
{
48-
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
49-
launcher.ClearKeyModifier();
50-
repo.Fetch(startDirectly);
47+
repo.Fetch(e.KeyModifiers is KeyModifiers.Control);
5148
e.Handled = true;
5249
}
5350
}
5451

55-
private void Pull(object _, RoutedEventArgs e)
52+
private void Pull(object sender, TappedEventArgs e)
5653
{
57-
var launcher = this.FindAncestorOfType<Launcher>();
58-
if (launcher is not null && DataContext is ViewModels.Repository repo)
54+
if (DataContext is ViewModels.Repository repo)
5955
{
60-
if (repo.IsBare)
61-
{
62-
App.RaiseException(repo.FullPath, "Can't run `git pull` in bare repository!");
63-
return;
64-
}
65-
66-
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
67-
launcher.ClearKeyModifier();
68-
repo.Pull(startDirectly);
56+
repo.Pull(e.KeyModifiers is KeyModifiers.Control);
6957
e.Handled = true;
7058
}
7159
}
7260

73-
private void Push(object _, RoutedEventArgs e)
61+
private void Push(object sender, TappedEventArgs e)
7462
{
75-
var launcher = this.FindAncestorOfType<Launcher>();
76-
if (launcher is not null && DataContext is ViewModels.Repository repo)
63+
if (DataContext is ViewModels.Repository repo)
7764
{
78-
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
79-
launcher.ClearKeyModifier();
80-
repo.Push(startDirectly);
65+
repo.Push(e.KeyModifiers is KeyModifiers.Control);
8166
e.Handled = true;
8267
}
8368
}
8469

85-
private void StashAll(object _, RoutedEventArgs e)
70+
private void StashAll(object _, TappedEventArgs e)
8671
{
87-
var launcher = this.FindAncestorOfType<Launcher>();
88-
if (launcher is not null && DataContext is ViewModels.Repository repo)
72+
if (DataContext is ViewModels.Repository repo)
8973
{
90-
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
91-
launcher.ClearKeyModifier();
92-
repo.StashAll(startDirectly);
74+
repo.StashAll(e.KeyModifiers is KeyModifiers.Control);
9375
e.Handled = true;
9476
}
9577
}

0 commit comments

Comments
 (0)