Skip to content

Commit

Permalink
Revert "Implemented ICommand - removed existing RD menu."
Browse files Browse the repository at this point in the history
This reverts commit 910309a.
  • Loading branch information
retailcoder committed Aug 5, 2015
1 parent 6fffafb commit 53d9ddc
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 328 deletions.
25 changes: 14 additions & 11 deletions RetailCoder.VBE/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,34 @@
using Rubberduck.Parsing.VBA;
using Rubberduck.Settings;
using Rubberduck.UI;
using Rubberduck.UI.Commands;
using Rubberduck.UI.ParserErrors;

namespace Rubberduck
{
public class App : IDisposable
{
private readonly IMessageBox _messageBox;
private readonly RubberduckParentMenu _rubberduckMenu;
private readonly IParserErrorsPresenterFactory _parserErrorsPresenterFactory;
private readonly IRubberduckParserFactory _parserFactory;
private readonly IInspectorFactory _inspectorFactory;
private IParserErrorsPresenter _parserErrorsPresenter;
private readonly IGeneralConfigService _configService;
private readonly IRubberduckMenuFactory _menuFactory;

private IRubberduckParser _parser;
private IMenu _menu;
private Configuration _config;

public App(IMessageBox messageBox,
RubberduckParentMenu rubberduckMenu,
//IMenu integratedUserInterface,
IRubberduckMenuFactory menuFactory,
IParserErrorsPresenterFactory parserErrorsPresenterFactory,
IRubberduckParserFactory parserFactory,
IInspectorFactory inspectorFactory,
IGeneralConfigService configService)
{
_messageBox = messageBox;
_rubberduckMenu = rubberduckMenu;
_menuFactory = menuFactory;
_parserErrorsPresenterFactory = parserErrorsPresenterFactory;
_parserFactory = parserFactory;
_inspectorFactory = inspectorFactory;
Expand All @@ -43,7 +44,6 @@ public class App : IDisposable

public void Startup()
{
_rubberduckMenu.Initialize();
CleanReloadConfig();
}

Expand Down Expand Up @@ -85,7 +85,8 @@ private void Setup()

_inspectorFactory.Create();

_rubberduckMenu.Localize();
_menu = _menuFactory.Create();
_menu.Initialize();
}

private void _parser_ParseStarted(object sender, ParseStartedEventArgs e)
Expand All @@ -106,17 +107,19 @@ public void Dispose()

protected virtual void Dispose(bool disposing)
{
if (!disposing)
{
return;
}
if (!disposing) { return; }

CleanUp();
_rubberduckMenu.Remove();
}

private void CleanUp()
{
var menu = _menu as IDisposable;
if (menu != null)
{
menu.Dispose();
}

if (_parser != null)
{
_parser.ParseStarted -= _parser_ParseStarted;
Expand Down
48 changes: 7 additions & 41 deletions RetailCoder.VBE/Root/RubberduckModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Office.Core;
using Microsoft.Vbe.Interop;
using Ninject;
using Ninject.Extensions.Conventions;
Expand All @@ -13,7 +12,6 @@
using Rubberduck.Settings;
using Rubberduck.UI;
using Rubberduck.UI.CodeInspections;
using Rubberduck.UI.Commands;
using Rubberduck.VBEditor.VBEHost;

namespace Rubberduck.Root
Expand Down Expand Up @@ -48,55 +46,23 @@ public override void Load()
Assembly.GetAssembly(typeof(IRubberduckParser))
};

BindRubberduckMenu();
BindMenuTypes();
BindToolbarTypes();

ApplyConfigurationConvention(assemblies);
ApplyDefaultInterfacesConvention(assemblies);
ApplyAbstractFactoryConvention(assemblies);
}

private void BindRubberduckMenu()
private void BindMenuTypes()
{
const int windowMenuId = 30009;
var menuBarControls = _vbe.CommandBars[1].Controls;
var beforeIndex = FindMenuInsertionIndex(menuBarControls, windowMenuId);

_kernel.Bind(t => t.FromThisAssembly()
.SelectAllClasses()
.InNamespaceOf<ICommand>()
.EndingWith("CommandMenuItem")
.BindToSelf());

//_kernel.Bind(t => t.FromThisAssembly()
// .SelectAllClasses()
// .InNamespaceOf<ICommand>()
// .EndingWith("Command")
// .Where(type => type.GetInterfaces().Contains(typeof (ICommand)))
// .BindAllInterfaces()
// .Configure(binding => binding
// .When(request => request.Service == typeof(ICommand)
// && request.Target.Member.DeclaringType.Name.StartsWith("????"))));

_kernel.Bind<ICommand>().To<AboutCommand>().WhenInjectedExactlyInto<AboutCommandMenuItem>();
_kernel.Bind<ICommand>().To<OptionsCommand>().WhenInjectedExactlyInto<OptionsCommandMenuItem>();
_kernel.Bind<ICommand>().To<CodeExplorerCommand>().WhenInjectedExactlyInto<CodeExplorerCommandMenuItem>();

_kernel.Bind<RubberduckParentMenu>().ToSelf()
.WithConstructorArgument("parent", menuBarControls)
.WithConstructorArgument("beforeIndex", beforeIndex);
_kernel.Bind<IMenu>().To<RubberduckMenu>(); // todo: confirm RubberduckMenuFactory is actually needed
_kernel.Bind<IMenu>().To<FormContextMenu>().WhenTargetHas<FormContextMenuAttribute>();
}

private int FindMenuInsertionIndex(CommandBarControls controls, int beforeId)
private void BindToolbarTypes()
{
for (var i = 1; i <= controls.Count; i++)
{
if (controls[i].BuiltIn && controls[i].Id == beforeId)
{
return i;
}
}

return controls.Count;
_kernel.Bind<IToolbar>().To<CodeInspectionsToolbar>().WhenTargetHas<CodeInspectionsToolbarAttribute>();
}

private void ApplyDefaultInterfacesConvention(IEnumerable<Assembly> assemblies)
Expand Down
10 changes: 3 additions & 7 deletions RetailCoder.VBE/Rubberduck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,7 @@
<Compile Include="Refactorings\ReorderParameters\ReorderParametersRefactoring.cs" />
<Compile Include="Root\RubberduckModule.cs" />
<Compile Include="UI\Commands\AboutCommand.cs" />
<Compile Include="UI\Commands\ICommand.cs" />
<Compile Include="UI\Commands\ICommandBar.cs" />
<Compile Include="UI\Commands\ICommandMenuItem.cs" />
<Compile Include="UI\Commands\IMenuItem.cs" />
<Compile Include="UI\Commands\IRubberduckMenuCommand.cs" />
<Compile Include="Settings\DisplayLanguageSetting.cs" />
<Compile Include="Settings\SourceControlConfiguration.cs" />
<Compile Include="Settings\SourceControlConfigurationService.cs" />
Expand Down Expand Up @@ -308,13 +305,12 @@
<Compile Include="Inspections\VariableNotAssignedInspection.cs" />
<Compile Include="Inspections\IdentifierNotAssignedInspectionResult.cs" />
<Compile Include="UI\Commands\OptionsCommand.cs" />
<Compile Include="UI\Commands\ParentMenu.cs" />
<Compile Include="UI\Commands\ParentMenuNotFoundException.cs" />
<Compile Include="UI\Commands\RubberduckParentMenu.cs" />
<Compile Include="UI\Commands\CodeExplorerCommand.cs" />
<Compile Include="UI\Commands\RubberduckCommandBase.cs" />
<Compile Include="UI\Commands\ToolbarState.cs" />
<Compile Include="UI\FolderBrowser.cs" />
<Compile Include="UI\IMessageBox.cs" />
<Compile Include="UI\Commands\RubberduckMenuCommand.cs" />
<Compile Include="UI\ParserErrors\ParseErrorListItem.cs" />
<Compile Include="UI\RubberduckUI.de.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
38 changes: 25 additions & 13 deletions RetailCoder.VBE/UI/Commands/AboutCommand.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
using System;
using System.Drawing;
using System.Linq;
using Microsoft.Office.Core;
using Microsoft.Vbe.Interop;

namespace Rubberduck.UI.Commands
{
public class AboutCommand : ICommand
/// <summary>
/// A command that displays the "About" dialog.
/// </summary>
public class AboutCommand : RubberduckCommandBase
{
public void Execute()
private readonly VBE _vbe;

public AboutCommand(IRubberduckMenuCommand command, VBE vbe)
: base(command)
{
using (var window = new _AboutWindow())
_vbe = vbe;
}

public override void Initialize()
{
var parent = _vbe.CommandBars[1].Controls.OfType<CommandBarPopup>()
.SingleOrDefault(control => control.Caption == RubberduckUI.RubberduckMenu);

if (parent == null)
{
window.ShowDialog();
throw new ParentMenuNotFoundException(RubberduckUI.RubberduckMenu);
}

Command.AddCommandBarButton(parent.Controls, RubberduckUI.RubberduckMenu_About, true);
}
}

public class AboutCommandMenuItem : CommandMenuItemBase
{
public AboutCommandMenuItem(ICommand command)
: base(command)
public override void ExecuteAction()
{
using (var window = new _AboutWindow())
{
window.ShowDialog();
}
}

public override string Key { get { return "RubberduckMenu_About"; } }
}
}
12 changes: 0 additions & 12 deletions RetailCoder.VBE/UI/Commands/ICommand.cs

This file was deleted.

13 changes: 0 additions & 13 deletions RetailCoder.VBE/UI/Commands/ICommandBar.cs

This file was deleted.

29 changes: 0 additions & 29 deletions RetailCoder.VBE/UI/Commands/ICommandMenuItem.cs

This file was deleted.

16 changes: 0 additions & 16 deletions RetailCoder.VBE/UI/Commands/IMenuItem.cs

This file was deleted.

33 changes: 33 additions & 0 deletions RetailCoder.VBE/UI/Commands/IRubberduckMenuCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Drawing;
using Microsoft.Office.Core;

namespace Rubberduck.UI.Commands
{
/// <summary>
/// An object that encapsulates the logic to wire up a number of CommandBarControl instances to a specific command.
/// </summary>
public interface IRubberduckMenuCommand
{
/// <summary>
/// Associates a new <see cref="CommandBarButton"/> to the command.
/// </summary>
/// <param name="parent">The parent control collection to add the button to.</param>
/// <param name="caption">The localized caption for the command.</param>
/// <param name="beginGroup">Optionally specifies that the UI element begins a command group.</param>
/// <param name="beforeIndex">Optionally specifies the index of the UI element in the parent collection.</param>
/// <param name="image">An optional icon to represent the command.</param>
/// <param name="mask">A transparency mask for the command's icon. Required if <see cref="image"/> is not null.</param>
void AddCommandBarButton(CommandBarControls parent, string caption, bool beginGroup = false, int? beforeIndex = null, Image image = null, Image mask = null);

/// <summary>
/// Destroys all UI elements associated to the command.
/// </summary>
void Release();

/// <summary>
/// Requests execution of the command.
/// </summary>
event EventHandler RequestExecute;
}
}

0 comments on commit 53d9ddc

Please sign in to comment.