Skip to content

Commit 0e1f4c7

Browse files
committed
Switch from ICommand to CommandBase
1 parent ed6e061 commit 0e1f4c7

File tree

56 files changed

+288
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+288
-283
lines changed

RetailCoder.VBE/App.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ private void LoadConfig()
494494
_logger.Debug("Loading configuration");
495495
_config = _configService.LoadConfiguration();
496496

497+
_autoSave.ConfigServiceSettingsChanged(this, EventArgs.Empty);
498+
497499
var currentCulture = RubberduckUI.Culture;
498500
try
499501
{

RetailCoder.VBE/AutoSave/AutoSave.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ public AutoSave(VBE vbe, IGeneralConfigService configService)
2222

2323
_configService.SettingsChanged += ConfigServiceSettingsChanged;
2424
_timer.Elapsed += _timer_Elapsed;
25-
26-
ConfigServiceSettingsChanged(null, EventArgs.Empty);
25+
_timer.Enabled = false;
2726
}
2827

29-
private void ConfigServiceSettingsChanged(object sender, EventArgs e)
28+
public void ConfigServiceSettingsChanged(object sender, EventArgs e)
3029
{
3130
var config = _configService.LoadConfiguration();
3231

RetailCoder.VBE/Common/Hotkeys/Hotkey.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ namespace Rubberduck.Common.Hotkeys
1111
public class Hotkey : IHotkey
1212
{
1313
private readonly string _key;
14-
private readonly ICommand _command;
14+
private readonly CommandBase _command;
1515
private readonly IntPtr _hWndVbe;
1616
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
1717

18-
public Hotkey(IntPtr hWndVbe, string key, ICommand command, Keys secondKey = Keys.None)
18+
public Hotkey(IntPtr hWndVbe, string key, CommandBase command, Keys secondKey = Keys.None)
1919
{
2020
_hWndVbe = hWndVbe;
2121

@@ -26,7 +26,7 @@ public Hotkey(IntPtr hWndVbe, string key, ICommand command, Keys secondKey = Key
2626
SecondKey = secondKey;
2727
}
2828

29-
public ICommand Command { get { return _command; } }
29+
public CommandBase Command { get { return _command; } }
3030
public string Key { get { return _key; } }
3131
public HotkeyInfo HotkeyInfo { get; private set; }
3232
public Keys Combo { get; private set; }

RetailCoder.VBE/Common/Hotkeys/IHotkey.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System.Windows.Forms;
22
using System.Windows.Input;
3+
using Rubberduck.UI.Command;
34

45
namespace Rubberduck.Common.Hotkeys
56
{
67
public interface IHotkey : IAttachable
78
{
89
string Key { get; }
9-
ICommand Command { get; }
10+
CommandBase Command { get; }
1011
HotkeyInfo HotkeyInfo { get; }
1112
Keys Combo { get; }
1213
Keys SecondKey { get; }

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public class RubberduckHooks : IRubberduckHooks
2626
private IRawDevice _kb;
2727
private IRawDevice _mouse;
2828
private readonly IGeneralConfigService _config;
29-
private readonly IEnumerable<ICommand> _commands;
29+
private readonly IEnumerable<CommandBase> _commands;
3030
private readonly IList<IAttachable> _hooks = new List<IAttachable>();
31-
private readonly IDictionary<RubberduckHotkey, ICommand> _mappings;
31+
private readonly IDictionary<RubberduckHotkey, CommandBase> _mappings;
3232
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
3333

34-
public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<ICommand> commands)
34+
public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<CommandBase> commands)
3535
{
3636
_vbe = vbe;
3737
_mainWindowHandle = (IntPtr)vbe.MainWindow.HWnd;
@@ -45,14 +45,14 @@ public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<IComma
4545
_mappings = GetCommandMappings();
4646
}
4747

48-
private ICommand Command<TCommand>() where TCommand : ICommand
48+
private CommandBase Command<TCommand>() where TCommand : CommandBase
4949
{
5050
return _commands.OfType<TCommand>().SingleOrDefault();
5151
}
5252

53-
private IDictionary<RubberduckHotkey, ICommand> GetCommandMappings()
53+
private IDictionary<RubberduckHotkey, CommandBase> GetCommandMappings()
5454
{
55-
return new Dictionary<RubberduckHotkey, ICommand>
55+
return new Dictionary<RubberduckHotkey, CommandBase>
5656
{
5757
{ RubberduckHotkey.ParseAll, Command<ReparseCommand>() },
5858
{ RubberduckHotkey.CodeExplorer, Command<CodeExplorerCommand>() },

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
2323
private readonly FolderHelper _folderHelper;
2424
private readonly RubberduckParserState _state;
2525

26-
public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState state, List<ICommand> commands)
26+
public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState state, List<CommandBase> commands)
2727
{
2828
_folderHelper = folderHelper;
2929
_state = state;
@@ -143,14 +143,14 @@ public bool SortBySelection
143143
}
144144
}
145145

146-
private readonly ICommand _copyResultsCommand;
147-
public ICommand CopyResultsCommand { get { return _copyResultsCommand; } }
146+
private readonly CommandBase _copyResultsCommand;
147+
public CommandBase CopyResultsCommand { get { return _copyResultsCommand; } }
148148

149-
private readonly ICommand _setNameSortCommand;
150-
public ICommand SetNameSortCommand { get { return _setNameSortCommand; } }
149+
private readonly CommandBase _setNameSortCommand;
150+
public CommandBase SetNameSortCommand { get { return _setNameSortCommand; } }
151151

152-
private readonly ICommand _setSelectionSortCommand;
153-
public ICommand SetSelectionSortCommand { get { return _setSelectionSortCommand; } }
152+
private readonly CommandBase _setSelectionSortCommand;
153+
public CommandBase SetSelectionSortCommand { get { return _setSelectionSortCommand; } }
154154

155155
private bool _sortByType = true;
156156
public bool SortByType
@@ -419,64 +419,64 @@ private void SetErrorState(CodeExplorerItemViewModel itemNode, VBComponent compo
419419
}
420420
}
421421

422-
private readonly ICommand _refreshCommand;
423-
public ICommand RefreshCommand { get { return _refreshCommand; } }
422+
private readonly CommandBase _refreshCommand;
423+
public CommandBase RefreshCommand { get { return _refreshCommand; } }
424424

425-
private readonly ICommand _refreshComponentCommand;
426-
public ICommand RefreshComponentCommand { get { return _refreshComponentCommand; } }
425+
private readonly CommandBase _refreshComponentCommand;
426+
public CommandBase RefreshComponentCommand { get { return _refreshComponentCommand; } }
427427

428-
private readonly ICommand _navigateCommand;
429-
public ICommand NavigateCommand { get { return _navigateCommand; } }
428+
private readonly CommandBase _navigateCommand;
429+
public CommandBase NavigateCommand { get { return _navigateCommand; } }
430430

431-
private readonly ICommand _addTestModuleCommand;
432-
public ICommand AddTestModuleCommand { get { return _addTestModuleCommand; } }
431+
private readonly CommandBase _addTestModuleCommand;
432+
public CommandBase AddTestModuleCommand { get { return _addTestModuleCommand; } }
433433

434-
private readonly ICommand _addStdModuleCommand;
435-
public ICommand AddStdModuleCommand { get { return _addStdModuleCommand; } }
434+
private readonly CommandBase _addStdModuleCommand;
435+
public CommandBase AddStdModuleCommand { get { return _addStdModuleCommand; } }
436436

437-
private readonly ICommand _addClassModuleCommand;
438-
public ICommand AddClassModuleCommand { get { return _addClassModuleCommand; } }
437+
private readonly CommandBase _addClassModuleCommand;
438+
public CommandBase AddClassModuleCommand { get { return _addClassModuleCommand; } }
439439

440-
private readonly ICommand _addUserFormCommand;
441-
public ICommand AddUserFormCommand { get { return _addUserFormCommand; } }
440+
private readonly CommandBase _addUserFormCommand;
441+
public CommandBase AddUserFormCommand { get { return _addUserFormCommand; } }
442442

443-
private readonly ICommand _openDesignerCommand;
444-
public ICommand OpenDesignerCommand { get { return _openDesignerCommand; } }
443+
private readonly CommandBase _openDesignerCommand;
444+
public CommandBase OpenDesignerCommand { get { return _openDesignerCommand; } }
445445

446-
private readonly ICommand _openProjectPropertiesCommand;
447-
public ICommand OpenProjectPropertiesCommand { get { return _openProjectPropertiesCommand; } }
446+
private readonly CommandBase _openProjectPropertiesCommand;
447+
public CommandBase OpenProjectPropertiesCommand { get { return _openProjectPropertiesCommand; } }
448448

449-
private readonly ICommand _renameCommand;
450-
public ICommand RenameCommand { get { return _renameCommand; } }
449+
private readonly CommandBase _renameCommand;
450+
public CommandBase RenameCommand { get { return _renameCommand; } }
451451

452-
private readonly ICommand _indenterCommand;
453-
public ICommand IndenterCommand { get { return _indenterCommand; } }
452+
private readonly CommandBase _indenterCommand;
453+
public CommandBase IndenterCommand { get { return _indenterCommand; } }
454454

455-
private readonly ICommand _findAllReferencesCommand;
456-
public ICommand FindAllReferencesCommand { get { return _findAllReferencesCommand; } }
455+
private readonly CommandBase _findAllReferencesCommand;
456+
public CommandBase FindAllReferencesCommand { get { return _findAllReferencesCommand; } }
457457

458-
private readonly ICommand _findAllImplementationsCommand;
459-
public ICommand FindAllImplementationsCommand { get { return _findAllImplementationsCommand; } }
458+
private readonly CommandBase _findAllImplementationsCommand;
459+
public CommandBase FindAllImplementationsCommand { get { return _findAllImplementationsCommand; } }
460460

461-
private readonly ICommand _importCommand;
462-
public ICommand ImportCommand { get { return _importCommand; } }
461+
private readonly CommandBase _importCommand;
462+
public CommandBase ImportCommand { get { return _importCommand; } }
463463

464-
private readonly ICommand _exportCommand;
465-
public ICommand ExportCommand { get { return _exportCommand; } }
464+
private readonly CommandBase _exportCommand;
465+
public CommandBase ExportCommand { get { return _exportCommand; } }
466466

467-
private readonly ICommand _removeCommand;
468-
public ICommand RemoveCommand { get { return _removeCommand; } }
467+
private readonly CommandBase _removeCommand;
468+
public CommandBase RemoveCommand { get { return _removeCommand; } }
469469

470-
private readonly ICommand _printCommand;
471-
public ICommand PrintCommand { get { return _printCommand; } }
470+
private readonly CommandBase _printCommand;
471+
public CommandBase PrintCommand { get { return _printCommand; } }
472472

473-
private readonly ICommand _commitCommand;
474-
public ICommand CommitCommand { get { return _commitCommand; } }
473+
private readonly CommandBase _commitCommand;
474+
public CommandBase CommitCommand { get { return _commitCommand; } }
475475

476-
private readonly ICommand _undoCommand;
477-
public ICommand UndoCommand { get { return _undoCommand; } }
476+
private readonly CommandBase _undoCommand;
477+
public CommandBase UndoCommand { get { return _undoCommand; } }
478478

479-
private readonly ICommand _externalRemoveCommand;
479+
private readonly CommandBase _externalRemoveCommand;
480480

481481
// this is a special case--we have to reset SelectedItem to prevent a crash
482482
private void ExecuteRemoveComand(object param)

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class RubberduckModule : NinjectModule
4949
private const int MsForms = 17;
5050
private const int MsFormsControl = 18;
5151

52-
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
52+
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
5353

5454
public RubberduckModule(VBE vbe, AddIn addin)
5555
{
@@ -59,7 +59,7 @@ public RubberduckModule(VBE vbe, AddIn addin)
5959

6060
public override void Load()
6161
{
62-
Logger.Debug("in RubberduckModule.Load()");
62+
_logger.Debug("in RubberduckModule.Load()");
6363

6464
// bind VBE and AddIn dependencies to host-provided instances.
6565
Bind<VBE>().ToConstant(_vbe);
@@ -149,7 +149,7 @@ public override void Load()
149149
ConfigureProjectExplorerContextMenu();
150150

151151
BindWindowsHooks();
152-
Logger.Debug("completed RubberduckModule.Load()");
152+
_logger.Debug("completed RubberduckModule.Load()");
153153
}
154154

155155
private void BindWindowsHooks()
@@ -308,10 +308,10 @@ private static int FindRubberduckMenuInsertionIndex(CommandBarControls controls,
308308
private void BindCommandsToMenuItems()
309309
{
310310
var types = Assembly.GetExecutingAssembly().GetTypes()
311-
.Where(type => type.IsClass && type.Namespace != null && type.Namespace.StartsWith(typeof(CommandBase).Namespace ?? string.Empty))
311+
.Where(type => type.IsClass && type.Namespace != null && type.Namespace.StartsWith(typeof(CommandBase).Namespace ?? String.Empty))
312312
.ToList();
313313

314-
// note: ICommand naming convention: [Foo]Command
314+
// note: CommandBase naming convention: [Foo]Command
315315
var baseCommandTypes = new[] { typeof(CommandBase), typeof(RefactorCommandBase) };
316316
var commands = types.Where(type => type.IsClass && baseCommandTypes.Contains(type.BaseType) && type.Name.EndsWith("Command"));
317317
foreach (var command in commands)
@@ -323,15 +323,16 @@ private void BindCommandsToMenuItems()
323323
var item = types.SingleOrDefault(type => type.Name == commandName + "CommandMenuItem");
324324
if (item != null)
325325
{
326-
var binding = Bind<ICommand>().To(command);
326+
var binding = Bind<CommandBase>().To(command);
327327
var whenCommandMenuItemCondition =
328328
binding.WhenInjectedInto(item).BindingConfiguration.Condition;
329329
var whenHooksCondition =
330330
binding.WhenInjectedInto<RubberduckHooks>().BindingConfiguration.Condition;
331331

332332
binding.When(request => whenCommandMenuItemCondition(request) || whenHooksCondition(request))
333-
.InSingletonScope()
334-
.Intercept().With<FatalExceptionInterceptor>();
333+
.InSingletonScope();
334+
335+
binding.Intercept().With<FatalExceptionInterceptor>();
335336
}
336337
}
337338
catch (InvalidOperationException)
@@ -351,7 +352,7 @@ private void BindCommandsToCodeExplorer()
351352

352353
foreach (var command in commands)
353354
{
354-
Bind<ICommand>().To(command).InSingletonScope();
355+
Bind<CommandBase>().To(command).InSingletonScope();
355356
}
356357
}
357358

RetailCoder.VBE/UI/About/AboutControlViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public string Version
1717
}
1818
}
1919

20-
private ICommand _uriCommand;
21-
public ICommand UriCommand
20+
private CommandBase _uriCommand;
21+
public CommandBase UriCommand
2222
{
2323
get
2424
{

RetailCoder.VBE/UI/Command/IMenuItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface IMenuItem
1616
public interface ICommandMenuItem : IMenuItem
1717
{
1818
bool EvaluateCanExecute(RubberduckParserState state);
19-
ICommand Command { get; }
19+
CommandBase Command { get; }
2020
Image Image { get; }
2121
Image Mask { get; }
2222
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Rubberduck.UI.Command.MenuItems
55
{
66
public class AboutCommandMenuItem : CommandMenuItemBase
77
{
8-
public AboutCommandMenuItem(ICommand command) : base(command)
8+
public AboutCommandMenuItem(CommandBase command) : base(command)
99
{
1010
}
1111

0 commit comments

Comments
 (0)