Skip to content

Commit 1867976

Browse files
Sébastien GeiserSébastien Geiser
Sébastien Geiser
authored and
Sébastien Geiser
committed
more hotkey and refactoring
1 parent 817a475 commit 1867976

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

RegexDialog/RegExToolDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
</MenuItem.Icon>
142142
</MenuItem>
143143
<Separator />
144-
<MenuItem Header="Show the regex in _C#" Click="ShowInCSharpButton_Click">
144+
<MenuItem Header="Show the regex in _C#" Click="ShowInCSharpButton_Click" InputGestureText="Ctrl+Shift+C">
145145
<MenuItem.Icon>
146146
<Image Source="{StaticResource ShowInCSharp}" Width="16" Height="16" />
147147
</MenuItem.Icon>
@@ -225,9 +225,9 @@
225225
</StackPanel>
226226
</Button>
227227
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
228-
<Button x:Name="ShowInCSharpButton" Click="ShowInCSharpButton_Click">
228+
<Button x:Name="ShowInCSharpButton" Click="ShowInCSharpButton_Click" ToolTip="Show the regex in C# [Ctrl+Shift+C]">
229229
<StackPanel Orientation="Horizontal">
230-
<Image Source="{StaticResource ShowInCSharp}" Width="16" Height="16" ToolTip="Show the regex in C#"/>
230+
<Image Source="{StaticResource ShowInCSharp}" Width="16" Height="16" />
231231
</StackPanel>
232232
</Button>
233233
</WrapPanel>

RegexDialog/RegExToolDialog.xaml.cs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Collections.Generic;
1010
using System.Collections.ObjectModel;
1111
using System.Diagnostics;
12+
using System.Globalization;
1213
using System.IO;
1314
using System.Linq;
1415
using System.Reflection;
@@ -239,6 +240,8 @@ private string ConvertToInputGestureText(KeyPressedEventArgs e) =>
239240
["Ctrl+V"] = ApplicationCommands.Paste,
240241
};
241242

243+
private Dictionary<string, Action> hotkeyToAction;
244+
242245
private void DelayAction(Action action, int milliseconds = 10)
243246
{
244247
Task.Run(async () =>
@@ -250,6 +253,23 @@ private void DelayAction(Action action, int milliseconds = 10)
250253

251254
private void KeyboardHookManager_KeyPressed(object sender, KeyPressedEventArgs e)
252255
{
256+
if(hotkeyToAction == null)
257+
{
258+
hotkeyToAction = new()
259+
{
260+
[$"Ctrl+{Key.Enter}"] = ShowMatches,
261+
[$"Ctrl+{Key.Space}"] = IsMatch,
262+
["Ctrl+O"] = OpenRegex,
263+
["Ctrl+S"] = SaveAs,
264+
["Ctrl+Shift+S"] = SelectAllMatches,
265+
["Ctrl+E"] = ExtractAll,
266+
["Ctrl+Shift+E"] = ExtractAll,
267+
["Ctrl+R"] = ReplaceAll,
268+
["Ctrl+Shift+R"] = ReplaceAll,
269+
["Ctrl+Shift+C"] = ShowInCSharp
270+
};
271+
}
272+
253273
try
254274
{
255275
string hotkey = ConvertToInputGestureText(e);
@@ -264,41 +284,11 @@ private void KeyboardHookManager_KeyPressed(object sender, KeyPressedEventArgs e
264284
command.Execute(null, focusedElement);
265285
}
266286
}
267-
else if (hotkey.Equals($"Ctrl+{Key.Enter}"))
268-
{
269-
e.Handled = true;
270-
DelayAction(ShowMatches);
271-
}
272-
else if (hotkey.Equals($"Ctrl+{Key.Space}"))
273-
{
274-
e.Handled = true;
275-
DelayAction(IsMatch);
276-
}
277-
else if (hotkey.Equals("Ctrl+O"))
278-
{
279-
e.Handled = true;
280-
DelayAction(OpenRegex);
281-
}
282-
else if (hotkey.Equals("Ctrl+S"))
283-
{
284-
e.Handled = true;
285-
DelayAction(SaveAs);
286-
}
287-
else if(hotkey.Equals("Ctrl+Shift+S"))
287+
else if(hotkeyToAction.ContainsKey(hotkey))
288288
{
289289
e.Handled = true;
290-
DelayAction(SelectAllMatches);
291-
}
292-
else if (hotkey.Equals("Ctrl+E") || hotkey.Equals("Ctrl+Shift+E"))
293-
{
294-
e.Handled = true;
295-
DelayAction(ExtractAll);
296-
}
297-
else if (hotkey.Equals("Ctrl+R") || hotkey.Equals("Ctrl+Shift+R"))
298-
{
299-
e.Handled = true;
300-
DelayAction(ReplaceAll);
301-
}
290+
DelayAction(hotkeyToAction[hotkey]);
291+
}
302292
}
303293
catch { }
304294
}
@@ -2596,7 +2586,7 @@ private void FindLanguageElementTextBox_PreviewKeyDown(object sender, KeyEventAr
25962586
}
25972587
}
25982588

2599-
private void Help_MenuItem_Click(object sender, RoutedEventArgs e)
2589+
private void ShowHelp()
26002590
{
26012591
try
26022592
{
@@ -2605,7 +2595,12 @@ private void Help_MenuItem_Click(object sender, RoutedEventArgs e)
26052595
catch { }
26062596
}
26072597

2608-
private void ShowInCSharpButton_Click(object sender, RoutedEventArgs e)
2598+
private void Help_MenuItem_Click(object sender, RoutedEventArgs e)
2599+
{
2600+
ShowHelp();
2601+
}
2602+
2603+
private void ShowInCSharp()
26092604
{
26102605
SetToHistory(0);
26112606

@@ -2700,6 +2695,11 @@ private void ShowInCSharpButton_Click(object sender, RoutedEventArgs e)
27002695
SetCurrentTabInCSharpHighlighting();
27012696
}
27022697

2698+
private void ShowInCSharpButton_Click(object sender, RoutedEventArgs e)
2699+
{
2700+
ShowInCSharp();
2701+
}
2702+
27032703
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
27042704
{
27052705
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));

0 commit comments

Comments
 (0)