Skip to content

Commit 613ac0a

Browse files
committed
refactor: use Tapped event instead of Click to access KeyModifers
Signed-off-by: leo <longshuang@msn.cn>
1 parent eb04c87 commit 613ac0a

File tree

4 files changed

+46
-69
lines changed

4 files changed

+46
-69
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: 0 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);
@@ -301,27 +288,6 @@ protected override async void OnKeyDown(KeyEventArgs e)
301288
}
302289

303290
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;
325291
}
326292

327293
protected override void OnClosing(WindowClosingEventArgs e)
@@ -363,7 +329,6 @@ private void OnCancelSwitcher(object sender, PointerPressedEventArgs e)
363329
e.Handled = true;
364330
}
365331

366-
private KeyModifiers _unhandledModifiers = KeyModifiers.None;
367332
private WindowState _lastWindowState = WindowState.Normal;
368333
}
369334
}

src/Views/RepositoryToolbar.axaml

Lines changed: 7 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}"/>
@@ -37,8 +37,9 @@
3737

3838
<Path Width="14" Height="14" Data="{StaticResource Icons.Fetch}"/>
3939
</Button>
40+
<Button Width="0" Height="0" Click="FetchDirectlyByHotKey" IsVisible="False" HotKey="{OnPlatform Ctrl+Down, macOS=⌘+Down}"/>
4041

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}">
42+
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Tapped="Pull" IsVisible="{Binding !IsBare}" IsEnabled="{Binding !IsBare}">
4243
<ToolTip.Tip>
4344
<StackPanel Orientation="Vertical">
4445
<TextBlock Text="{DynamicResource Text.Pull}"/>
@@ -48,8 +49,9 @@
4849

4950
<Path Width="14" Height="14" Data="{StaticResource Icons.Pull}"/>
5051
</Button>
52+
<Button Width="0" Height="0" Click="PullDirectlyByHotKey" IsVisible="False" IsEnabled="{Binding !IsBare}" HotKey="{OnPlatform Ctrl+Shift+Down, macOS=⌘+Shift+Down}"/>
5153

52-
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Click="Push" HotKey="{OnPlatform Ctrl+Shift+Up, macOS=⌘+Shift+Up}">
54+
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Tapped="Push">
5355
<ToolTip.Tip>
5456
<StackPanel Orientation="Vertical">
5557
<TextBlock Text="{DynamicResource Text.Push}"/>
@@ -59,8 +61,9 @@
5961

6062
<Path Width="14" Height="14" Data="{StaticResource Icons.Push}"/>
6163
</Button>
64+
<Button Width="0" Height="0" Click="PushDirectlyByHotKey" HotKey="{OnPlatform Ctrl+Shift+Up, macOS=⌘+Shift+Up}"/>
6265

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

src/Views/RepositoryToolbar.axaml.cs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,56 +40,65 @@ 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)
46+
{
47+
repo.Fetch(e.KeyModifiers is KeyModifiers.Control);
48+
e.Handled = true;
49+
}
50+
}
51+
52+
private void FetchDirectlyByHotKey(object sender, RoutedEventArgs e)
53+
{
54+
if (DataContext is ViewModels.Repository repo)
55+
{
56+
repo.Fetch(true);
57+
e.Handled = true;
58+
}
59+
}
60+
61+
private void Pull(object sender, TappedEventArgs e)
62+
{
63+
if (DataContext is ViewModels.Repository repo)
4764
{
48-
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
49-
launcher.ClearKeyModifier();
50-
repo.Fetch(startDirectly);
65+
repo.Pull(e.KeyModifiers is KeyModifiers.Control);
5166
e.Handled = true;
5267
}
5368
}
5469

55-
private void Pull(object _, RoutedEventArgs e)
70+
private void PullDirectlyByHotKey(object sender, RoutedEventArgs e)
5671
{
57-
var launcher = this.FindAncestorOfType<Launcher>();
58-
if (launcher is not null && DataContext is ViewModels.Repository repo)
72+
if (DataContext is ViewModels.Repository repo)
5973
{
60-
if (repo.IsBare)
61-
{
62-
App.RaiseException(repo.FullPath, "Can't run `git pull` in bare repository!");
63-
return;
64-
}
74+
repo.Pull(true);
75+
e.Handled = true;
76+
}
77+
}
6578

66-
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
67-
launcher.ClearKeyModifier();
68-
repo.Pull(startDirectly);
79+
private void Push(object sender, TappedEventArgs e)
80+
{
81+
if (DataContext is ViewModels.Repository repo)
82+
{
83+
repo.Push(e.KeyModifiers is KeyModifiers.Control);
6984
e.Handled = true;
7085
}
7186
}
7287

73-
private void Push(object _, RoutedEventArgs e)
88+
private void PushDirectlyByHotKey(object sender, RoutedEventArgs e)
7489
{
75-
var launcher = this.FindAncestorOfType<Launcher>();
76-
if (launcher is not null && DataContext is ViewModels.Repository repo)
90+
if (DataContext is ViewModels.Repository repo)
7791
{
78-
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
79-
launcher.ClearKeyModifier();
80-
repo.Push(startDirectly);
92+
repo.Push(true);
8193
e.Handled = true;
8294
}
8395
}
8496

85-
private void StashAll(object _, RoutedEventArgs e)
97+
private void StashAll(object _, TappedEventArgs e)
8698
{
87-
var launcher = this.FindAncestorOfType<Launcher>();
88-
if (launcher is not null && DataContext is ViewModels.Repository repo)
99+
if (DataContext is ViewModels.Repository repo)
89100
{
90-
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
91-
launcher.ClearKeyModifier();
92-
repo.StashAll(startDirectly);
101+
repo.StashAll(e.KeyModifiers is KeyModifiers.Control);
93102
e.Handled = true;
94103
}
95104
}

0 commit comments

Comments
 (0)