Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit b041b83

Browse files
committed
finish implementing go to default hotkey
1 parent ec180f9 commit b041b83

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Interop/TranslationProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ private void FillToEnglishDefaults()
370370
language.Add("TemplateExists", "Template name already exists");
371371
language.Add("IllegalCharacters", "Illegal characters");
372372
language.Add("ReopenLastClosedTab", "Reopen the last closed tab");
373+
language.Add("DefaultTaken", "Default taken!");
373374
}
374375
}
375376
}

UI/Windows/OptionsWindow/OptionsWindowHotkeys.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ private void Hotkey_PreviewMouseDown(object sender, MouseButtonEventArgs e)
5353
_ctrl = hkControl;
5454
_currentControlHotkey = _ctrl.Hotkey;
5555

56-
var mi = new MenuItem();
57-
mi.Header = "Reset to default";
56+
var mi = new MenuItem
57+
{
58+
Header = "Reset to default"
59+
};
5860
var cm = new ContextMenu();
5961
cm.Items.Add(mi);
6062
hkControl.HotkeyTextBox.ContextMenu = cm;
@@ -63,16 +65,16 @@ private void Hotkey_PreviewMouseDown(object sender, MouseButtonEventArgs e)
6365
{
6466
foreach (var hk in Program.HotkeysList)
6567
{
66-
if (hk.Hotkey.ToString() == HotkeyControl.DefaultHotkeys[hkControl.Name.Substring(2)])
68+
var hkStr = hk.Hotkey.ToString();
69+
if (hkStr == HotkeyControl.DefaultHotkeys[hkControl.Name.Substring(2)] && hkStr != hkControl.Hotkey.ToString())
6770
{
68-
ShowLabel("Default taken!");
71+
ShowLabel(Program.Translations.GetLanguage("DefaultTaken"));
6972
return;
7073
}
7174
}
7275

7376
HideLabel();
74-
hkControl.Hotkey = new Hotkey(HotkeyControl.DefaultHotkeys[hkControl.Name.Substring(2)]);
75-
Program.HotkeysList.FirstOrDefault(x => x.Command == hkControl.Name.Substring(2)).Hotkey = hkControl.Hotkey;
77+
SaveHotkey(true);
7678
};
7779

7880
}
@@ -88,7 +90,7 @@ private void OnTimerTick(object sender, EventArgs e)
8890
/// <summary>
8991
/// Saves the input hotkey to the Hotkeys file, and caches it.
9092
/// </summary>
91-
private void SaveHotkey()
93+
private void SaveHotkey(bool toDefault = false)
9294
{
9395
// Create the hotkeys file if it doesn't exist for some reason
9496
if (!File.Exists(Constants.HotkeysFile))
@@ -99,6 +101,13 @@ private void SaveHotkey()
99101
// Get the control name by separating it from its x:Name suffix
100102
var ctrlName = _ctrl.Name.Substring(2);
101103

104+
// We skip checks if we're setting a default hotkey
105+
if (toDefault)
106+
{
107+
_ctrl.Hotkey = new Hotkey(HotkeyControl.DefaultHotkeys[_ctrl.Name.Substring(2)]);
108+
goto SaveDirectly;
109+
}
110+
102111
foreach (var hkInfo in Program.HotkeysList)
103112
{
104113
// Check if the user has cleared the hotkey field
@@ -131,6 +140,8 @@ private void SaveHotkey()
131140
}
132141
}
133142

143+
SaveDirectly:
144+
134145
// Modify the XML document to update hotkey
135146
var document = new XmlDocument();
136147
document.Load(Constants.HotkeysFile);

0 commit comments

Comments
 (0)