Skip to content

Commit 76a2c1a

Browse files
committed
added hotkeys to Rubberduck menu items
1 parent 4d91a08 commit 76a2c1a

18 files changed

+538
-492
lines changed

RetailCoder.VBE/Navigation/RegexSearchReplace/RegexSearchReplacePresenter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public RegexSearchReplacePresenter(VBE vbe, IRubberduckParser parser/*, IRegexSe
2727

2828
public void Show()
2929
{
30-
_view.ShowDialog();
30+
//_view.ShowDialog();
3131
}
3232

3333
public void Hide()
3434
{
35-
_view.Close();
35+
//_view.Close();
3636
}
3737

3838
public event EventHandler<IEnumerable<RegexSearchResult>> FindButtonResults;
@@ -65,7 +65,7 @@ private void _view_ReplaceAllButtonClicked(object sender, EventArgs e)
6565

6666
private void _view_CancelButtonClicked(object sender, EventArgs e)
6767
{
68-
_view.Close();
68+
//_view.Close();
6969
}
7070
}
7171
}

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@
345345
<Compile Include="UI\About\AboutDialog.Designer.cs">
346346
<DependentUpon>AboutDialog.cs</DependentUpon>
347347
</Compile>
348-
<Compile Include="UI\Command\IHotkeyCommand.cs" />
349348
<Compile Include="UI\Command\IndentCurrentModuleCommand.cs" />
350349
<Compile Include="UI\Command\MenuItems\InspectionResultsCommandMenuItem.cs" />
351350
<Compile Include="UI\Command\ShowParserErrorsCommand.cs" />

RetailCoder.VBE/Settings/ConfigurationLoader.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,22 @@ private IDictionary<RubberduckHotkey, ICommand> GetCommandMappings()
8989
{
9090
return new Dictionary<RubberduckHotkey, ICommand>
9191
{
92-
{ RubberduckHotkey.CodeExplorer, _commands.SingleOrDefault(cmd => cmd is CodeExplorerCommand)},
93-
{ RubberduckHotkey.IndentModule, _commands.SingleOrDefault(cmd => cmd is IndentCurrentModuleCommand)},
94-
{ RubberduckHotkey.IndentProcedure, _commands.SingleOrDefault(cmd => cmd is IndentCurrentProcedureCommand)},
95-
{ RubberduckHotkey.InspectionResults, _commands.SingleOrDefault(cmd => cmd is InspectionResultsCommand)},
96-
{ RubberduckHotkey.RefactorExtractMethod, _commands.SingleOrDefault(cmd => cmd is RefactorExtractMethodCommand)},
97-
{ RubberduckHotkey.RefactorRename, _commands.SingleOrDefault(cmd => cmd is CodePaneRefactorRenameCommand)},
98-
{ RubberduckHotkey.TestExplorer, _commands.SingleOrDefault(cmd => cmd is TestExplorerCommand)}
92+
{ RubberduckHotkey.CodeExplorer, Command<CodeExplorerCommand>() },
93+
{ RubberduckHotkey.IndentModule, Command<IndentCurrentModuleCommand>() },
94+
{ RubberduckHotkey.IndentProcedure, Command<IndentCurrentProcedureCommand>() },
95+
{ RubberduckHotkey.FindSymbol, Command<FindSymbolCommand>() },
96+
{ RubberduckHotkey.InspectionResults, Command<InspectionResultsCommand>() },
97+
{ RubberduckHotkey.RefactorExtractMethod, Command<RefactorExtractMethodCommand>() },
98+
{ RubberduckHotkey.RefactorRename, Command<CodePaneRefactorRenameCommand>() },
99+
{ RubberduckHotkey.TestExplorer, Command<TestExplorerCommand>() }
99100
};
100101
}
101102

103+
private ICommand Command<TCommand>() where TCommand : ICommand
104+
{
105+
return _commands.OfType<TCommand>().SingleOrDefault();
106+
}
107+
102108
private void AssociateHotkeyCommands(Configuration config)
103109
{
104110
var mappings = GetCommandMappings();
@@ -108,6 +114,7 @@ private void AssociateHotkeyCommands(Configuration config)
108114
if (Enum.TryParse(setting.Name, out hotkey))
109115
{
110116
setting.Command = mappings[hotkey];
117+
((CommandBase)setting.Command).ShortcutText = setting.ToMenuHotkeyString(); // yuck
111118
}
112119
}
113120
}
@@ -178,6 +185,7 @@ private GeneralSettings GetDefaultGeneralSettings()
178185
new HotkeySetting{Name=RubberduckHotkey.IndentProcedure.ToString(), IsEnabled=true, HasCtrlModifier = true, Key1="P", Command = commandMappings[RubberduckHotkey.IndentProcedure]},
179186
new HotkeySetting{Name=RubberduckHotkey.IndentModule.ToString(), IsEnabled=true, HasCtrlModifier = true, Key1="M", Command = commandMappings[RubberduckHotkey.IndentModule]},
180187
new HotkeySetting{Name=RubberduckHotkey.CodeExplorer.ToString(), IsEnabled=true, HasCtrlModifier = true, Key1="R", Command = commandMappings[RubberduckHotkey.CodeExplorer]},
188+
new HotkeySetting{Name=RubberduckHotkey.FindSymbol.ToString(), IsEnabled=true, HasCtrlModifier = true, Key1="T", Command = commandMappings[RubberduckHotkey.InspectionResults]},
181189
new HotkeySetting{Name=RubberduckHotkey.InspectionResults.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="I", Command = commandMappings[RubberduckHotkey.InspectionResults]},
182190
new HotkeySetting{Name=RubberduckHotkey.TestExplorer.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="T", Command = commandMappings[RubberduckHotkey.TestExplorer]},
183191
new HotkeySetting{Name=RubberduckHotkey.RefactorRename.ToString(), IsEnabled=true, HasCtrlModifier = true, HasShiftModifier = true, Key1="R", Command = commandMappings[RubberduckHotkey.RefactorRename]},

RetailCoder.VBE/Settings/HotkeySetting.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ public string Prompt
3131
get { return RubberduckUI.ResourceManager.GetString("HotkeyDescription_" + Name); }
3232
}
3333

34+
public string ToMenuHotkeyString()
35+
{
36+
return string.Format("{0}{1}{2}+{3}",
37+
HasShiftModifier ? "Shift" : string.Empty,
38+
HasCtrlModifier ? (HasShiftModifier ? "+" : string.Empty) + "Ctrl" : string.Empty,
39+
HasAltModifier ? (HasShiftModifier | HasCtrlModifier ? "+" : string.Empty) + "Alt" : string.Empty,
40+
Key1);
41+
}
42+
3443
public override string ToString()
3544
{
3645
return string.Format("{0}{1}{2}{3}",

RetailCoder.VBE/Settings/RubberduckHotkey.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public enum RubberduckHotkey
55
IndentProcedure,
66
IndentModule,
77
CodeExplorer,
8+
FindSymbol,
89
InspectionResults,
910
TestExplorer,
1011
RefactorRename,

RetailCoder.VBE/UI/Command/CodeExplorerCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Rubberduck.UI.Command
77
/// A command that displays the Code Explorer window.
88
/// </summary>
99
[ComVisible(false)]
10-
public class CodeExplorerCommand : CommandBase, IHotkeyCommand
10+
public class CodeExplorerCommand : CommandBase
1111
{
1212
private readonly IPresenter _presenter;
1313

RetailCoder.VBE/UI/Command/CommandBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public virtual bool CanExecute(object parameter)
1414

1515
public abstract void Execute(object parameter);
1616

17+
public virtual string ShortcutText { get; set; }
18+
1719
public event EventHandler CanExecuteChanged
1820
{
1921
add { CommandManager.RequerySuggested += value; }

RetailCoder.VBE/UI/Command/FindSymbolCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.Vbe.Interop;
44
using Rubberduck.Common;
55
using Rubberduck.Parsing.VBA;
6+
using Rubberduck.Settings;
67
using Rubberduck.UI.FindSymbol;
78

89
namespace Rubberduck.UI.Command
@@ -34,5 +35,7 @@ public override void Execute(object parameter)
3435
view.ShowDialog();
3536
}
3637
}
38+
39+
public RubberduckHotkey Hotkey { get { return RubberduckHotkey.FindSymbol; } }
3740
}
3841
}

RetailCoder.VBE/UI/Command/IHotkeyCommand.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

RetailCoder.VBE/UI/Command/IndentCurrentModuleCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Rubberduck.UI.Command
66
{
77
[ComVisible(false)]
8-
public class IndentCurrentModuleCommand : CommandBase, IHotkeyCommand
8+
public class IndentCurrentModuleCommand : CommandBase
99
{
1010
private readonly IIndenter _indenter;
1111

0 commit comments

Comments
 (0)