Skip to content

Commit 4c4cd63

Browse files
committed
fixes #1672
1 parent 62c1e05 commit 4c4cd63

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

RetailCoder.VBE/App.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Runtime.InteropServices.ComTypes;
1919
using System.Threading.Tasks;
2020
using System.Windows.Forms;
21+
using Rubberduck.Common.Hotkeys;
2122

2223
namespace Rubberduck
2324
{
@@ -132,9 +133,9 @@ private bool ShouldEvaluateCanExecute(Declaration selectedDeclaration, ParserSta
132133
private void _configService_SettingsChanged(object sender, EventArgs e)
133134
{
134135
_config = _configService.LoadConfiguration();
136+
_hooks.HookHotkeys();
135137
// also updates the ShortcutKey text
136138
_appMenus.Localize();
137-
_hooks.HookHotkeys();
138139
UpdateLoggingLevel();
139140
}
140141

@@ -147,9 +148,9 @@ public void Startup()
147148
{
148149
CleanReloadConfig();
149150
_appMenus.Initialize();
151+
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
150152
_appMenus.Localize();
151153
Task.Delay(1000).ContinueWith(t => UiDispatcher.Invoke(() => _parser.State.OnParseRequested(this))).ConfigureAwait(false);
152-
_hooks.HookHotkeys();
153154
UpdateLoggingLevel();
154155
}
155156

RetailCoder.VBE/Common/Hotkeys/Hotkey.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Windows.Input;
66
using Rubberduck.Common.WinAPI;
77
using NLog;
8+
using Rubberduck.UI.Command;
89

910
namespace Rubberduck.Common.Hotkeys
1011
{
@@ -58,6 +59,7 @@ public void Attach()
5859
}
5960

6061
HookKey(key, shift);
62+
SetCommandShortcutText();
6163
}
6264

6365
public void Detach()
@@ -71,6 +73,7 @@ public void Detach()
7173
Kernel32.GlobalDeleteAtom(HotkeyInfo.HookId);
7274

7375
IsAttached = false;
76+
ClearCommandShortcutText();
7477
}
7578

7679
private void HookKey(Keys key, uint shift)
@@ -90,9 +93,29 @@ private void HookKey(Keys key, uint shift)
9093

9194
HotkeyInfo = new HotkeyInfo(hookId, Combo);
9295
IsAttached = true;
96+
9397
_logger.Debug("Hotkey '{0}' hooked successfully to command '{1}'", Key, Command.GetType()); //no translation needed for Debug.Writeline
9498
}
9599

100+
private void SetCommandShortcutText()
101+
{
102+
var command = Command as CommandBase;
103+
if (command != null)
104+
{
105+
command.ShortcutText = HotkeyInfo.ToString();
106+
}
107+
}
108+
109+
private void ClearCommandShortcutText()
110+
{
111+
var command = Command as CommandBase;
112+
if (command != null)
113+
{
114+
command.ShortcutText = string.Empty;
115+
}
116+
}
117+
118+
96119
private static readonly IDictionary<char,uint> Modifiers = new Dictionary<char, uint>
97120
{
98121
{ '+', (uint)KeyModifier.SHIFT },

RetailCoder.VBE/Common/Hotkeys/HotkeyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ public override string ToString()
2525
var builder = new StringBuilder();
2626
if (_keys.HasFlag(Keys.Alt))
2727
{
28-
builder.Append("Alt");
28+
builder.Append(Rubberduck.UI.RubberduckUI.GeneralSettings_HotkeyAlt);
2929
builder.Append('+');
3030
}
3131
if (_keys.HasFlag(Keys.Control))
3232
{
33-
builder.Append("Ctrl");
33+
builder.Append(Rubberduck.UI.RubberduckUI.GeneralSettings_HotkeyCtrl);
3434
builder.Append('+');
3535
}
3636
if (_keys.HasFlag(Keys.Shift))
3737
{
38-
builder.Append("Shift");
38+
builder.Append(Rubberduck.UI.RubberduckUI.GeneralSettings_HotkeyShift);
3939
builder.Append('+');
4040
}
4141
builder.Append(_keys & ~Modifiers);

0 commit comments

Comments
 (0)