Skip to content

Commit 076ea95

Browse files
committed
hotkeys re-attach and update menu shortcutkeys when settings are saved
1 parent 7b88d02 commit 076ea95

File tree

7 files changed

+31
-2
lines changed

7 files changed

+31
-2
lines changed

RetailCoder.VBE/App.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public App(VBE vbe, IMessageBox messageBox,
6161
_hooks = hooks;
6262
_logger = LogManager.GetCurrentClassLogger();
6363

64+
_configService.SettingsChanged += _configService_SettingsChanged;
6465
_configService.LanguageChanged += ConfigServiceLanguageChanged;
6566
_parser.State.StateChanged += Parser_StateChanged;
6667
_stateBar.Refresh += _stateBar_Refresh;
@@ -80,6 +81,13 @@ public App(VBE vbe, IMessageBox messageBox,
8081
UiDispatcher.Initialize();
8182
}
8283

84+
private void _configService_SettingsChanged(object sender, EventArgs e)
85+
{
86+
// also updates the ShortcutKey text
87+
_appMenus.Localize();
88+
_hooks.HookHotkeys();
89+
}
90+
8391
public void Startup()
8492
{
8593
CleanReloadConfig();

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ public RubberduckHooks(VBE vbe, IAttachable timerHook, IGeneralConfigService con
3838

3939
public void HookHotkeys()
4040
{
41+
Detach();
42+
_hooks.Clear();
43+
4144
var config = _config.LoadConfiguration();
4245
var settings = config.UserSettings.GeneralSettings.HotkeySettings;
4346
foreach (var hotkey in settings.Where(hotkey => hotkey.IsEnabled))
4447
{
4548
AddHook(new Hotkey(_mainWindowHandle, hotkey.ToString(), hotkey.Command));
4649
}
50+
51+
Attach();
4752
}
4853

4954
public IEnumerable<IAttachable> Hooks { get { return _hooks; } }
@@ -77,7 +82,7 @@ public void Attach()
7782
{
7883
hook.Attach();
7984
hook.MessageReceived += hook_MessageReceived;
80-
}
85+
}
8186

8287
IsAttached = true;
8388
}
@@ -110,7 +115,7 @@ public void Detach()
110115
{
111116
hook.Detach();
112117
hook.MessageReceived -= hook_MessageReceived;
113-
}
118+
}
114119

115120
IsAttached = false;
116121
}

RetailCoder.VBE/Settings/ConfigurationLoader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ private IDictionary<RubberduckHotkey, ICommand> GetCommandMappings()
9393
{ RubberduckHotkey.IndentModule, Command<IndentCurrentModuleCommand>() },
9494
{ RubberduckHotkey.IndentProcedure, Command<IndentCurrentProcedureCommand>() },
9595
{ RubberduckHotkey.FindSymbol, Command<FindSymbolCommand>() },
96+
{ RubberduckHotkey.RefactorMoveCloserToUsage, Command<RefactorMoveCloserToUsageCommand>() },
9697
{ RubberduckHotkey.InspectionResults, Command<InspectionResultsCommand>() },
9798
{ RubberduckHotkey.RefactorExtractMethod, Command<RefactorExtractMethodCommand>() },
9899
{ RubberduckHotkey.RefactorRename, Command<CodePaneRefactorRenameCommand>() },
@@ -188,6 +189,7 @@ private GeneralSettings GetDefaultGeneralSettings()
188189
new HotkeySetting{Name=RubberduckHotkey.FindSymbol.ToString(), IsEnabled=true, HasCtrlModifier = true, Key1="T", Command = commandMappings[RubberduckHotkey.InspectionResults]},
189190
new HotkeySetting{Name=RubberduckHotkey.InspectionResults.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="I", Command = commandMappings[RubberduckHotkey.InspectionResults]},
190191
new HotkeySetting{Name=RubberduckHotkey.TestExplorer.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="T", Command = commandMappings[RubberduckHotkey.TestExplorer]},
192+
new HotkeySetting{Name=RubberduckHotkey.RefactorMoveCloserToUsage.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="C", Command = commandMappings[RubberduckHotkey.RefactorMoveCloserToUsage]},
191193
new HotkeySetting{Name=RubberduckHotkey.RefactorRename.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="R", Command = commandMappings[RubberduckHotkey.RefactorRename]},
192194
new HotkeySetting{Name=RubberduckHotkey.RefactorExtractMethod.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="M", Command = commandMappings[RubberduckHotkey.RefactorExtractMethod]}
193195
},

RetailCoder.VBE/Settings/RubberduckHotkey.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public enum RubberduckHotkey
88
FindSymbol,
99
InspectionResults,
1010
TestExplorer,
11+
RefactorMoveCloserToUsage,
1112
RefactorRename,
1213
RefactorExtractMethod,
1314
}

RetailCoder.VBE/UI/Command/MenuItems/RefactorMoveCloserToUsageCommandMenuItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public RefactorMoveCloserToUsageCommandMenuItem(ICommand command)
1313

1414
public override string Key { get { return "RefactorMenu_MoveCloserToUsage"; } }
1515
public override int DisplayOrder { get { return (int)RefactoringsMenuItemDisplayOrder.MoveCloserToUsage; } }
16+
public override bool BeginGroup { get { return true; } }
1617

1718
public override bool EvaluateCanExecute(RubberduckParserState state)
1819
{

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,9 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
14921492
<data name="HotkeyDescription_FindSymbol" xml:space="preserve">
14931493
<value>Find symbol</value>
14941494
</data>
1495+
<data name="HotkeyDescription_RefactorMoveCloserToUsage" xml:space="preserve">
1496+
<value>Move declaration closer to usage</value>
1497+
</data>
14951498
<data name="RubberduckMenu_RegexSearchReplace" xml:space="preserve">
14961499
<value>Rege&amp;x Search/Replace</value>
14971500
</data>

0 commit comments

Comments
 (0)