Skip to content

Commit

Permalink
Merge pull request #7 from rubberduck-vba/next
Browse files Browse the repository at this point in the history
Pull from Next
  • Loading branch information
Hosch250 committed Jul 20, 2015
2 parents 9f143ff + 67b9549 commit 7992cf9
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 39 deletions.
28 changes: 14 additions & 14 deletions RetailCoder.VBE/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class App : IDisposable
private readonly VBE _vbe;
private readonly AddIn _addIn;
private Inspector _inspector;
private ParserErrorsPresenter _parserErrorsPresenter;
private readonly IGeneralConfigService _configService = new ConfigurationLoader();
private readonly ActiveCodePaneEditor _editor;
private IParserErrorsPresenter _parserErrorsPresenter;
private readonly IConfigurationLoader _configService = new ConfigurationLoader();
private readonly IActiveCodePaneEditor _editor;
private readonly IRubberduckCodePaneFactory _factory;
private IRubberduckParser _parser;
private readonly IRubberduckParser _parser;

private Configuration _config;
private RubberduckMenu _menu;
Expand All @@ -33,16 +33,21 @@ public class App : IDisposable
private bool _displayToolbar = false;
private Point _toolbarCoords = new Point(-1, -1);

public App(VBE vbe, AddIn addIn)
public App(VBE vbe, AddIn addIn, IParserErrorsPresenter presenter, IRubberduckParser parser, IRubberduckCodePaneFactory factory, IActiveCodePaneEditor editor)
{
_vbe = vbe;
_addIn = addIn;
_factory = new RubberduckCodePaneFactory();
_factory = factory;
_parser = parser;

_parserErrorsPresenter = new ParserErrorsPresenter(vbe, addIn);
_parserErrorsPresenter = presenter;
_configService.SettingsChanged += _configService_SettingsChanged;

_editor = new ActiveCodePaneEditor(vbe, _factory);
// todo: figure out why Ninject can't seem to resolve the VBE dependency to ActiveCodePaneEditor if it's in the VBEDitor assembly.
// could it be that the VBE type in the two assemblies is actually different?
// aren't the two assemblies using the exact same Microsoft.Vbe.Interop assemby?

_editor = editor; // */ new ActiveCodePaneEditor(vbe, _factory);

LoadConfig();

Expand Down Expand Up @@ -79,7 +84,7 @@ private void LoadConfig()

private void Setup()
{
_parser = new RubberduckParser(_factory);
//_parser = new RubberduckParser(_factory);
_parser.ParseStarted += _parser_ParseStarted;
_parser.ParserError += _parser_ParserError;

Expand Down Expand Up @@ -150,11 +155,6 @@ private void CleanUp()
_inspector.Dispose();
}

if (_parserErrorsPresenter != null)
{
_parserErrorsPresenter.Dispose();
}

if (_parser != null)
{
_parser.ParseStarted -= _parser_ParseStarted;
Expand Down
20 changes: 16 additions & 4 deletions RetailCoder.VBE/Extension.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using Extensibility;
using Microsoft.Vbe.Interop;
using Ninject;
using Rubberduck.Root;
using Rubberduck.UI;
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane;

namespace Rubberduck
{
Expand All @@ -20,6 +22,7 @@ public class _Extension : IDTExtensibility2, IDisposable
private const string ProgId = "Rubberduck.Extension";

private App _app;
private IKernel _kernel;

public void OnAddInsUpdate(ref Array custom)
{
Expand All @@ -33,14 +36,23 @@ public void OnConnection(object Application, ext_ConnectMode ConnectMode, object
{
try
{
_app = new App((VBE)Application, (AddIn)AddInInst);
_kernel = new StandardKernel();
Compose((VBE) Application, (AddIn) AddInInst);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, RubberduckUI.RubberduckLoadFailure, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void Compose(VBE application, AddIn addin)
{
var conventions = new RubberduckConventions(_kernel);
conventions.Apply(application, addin);

_app = _kernel.Get<App>();
}

public void OnStartupComplete(ref Array custom)
{

Expand All @@ -58,9 +70,9 @@ public void Dispose()

protected virtual void Dispose(bool disposing)
{
if (disposing & _app != null)
if (disposing & _kernel != null)
{
_app.Dispose();
_kernel.Dispose();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions RetailCoder.VBE/Inspections/Inspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace Rubberduck.Inspections
public class Inspector : IInspector, IDisposable
{
private readonly IRubberduckParser _parser;
private readonly IGeneralConfigService _configService;
private readonly IConfigurationLoader _configService;
private readonly IList<IInspection> _inspections;

public Inspector(IRubberduckParser parser, IGeneralConfigService configService)
public Inspector(IRubberduckParser parser, IConfigurationLoader configService)
{
_parser = parser;
_parser.ParseStarted += _parser_ParseStarted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Rubberduck.VBEditor
{
// todo: fix VBE dependency and move back to Rubberduck.VBEditor, or create VBEditor namespace in this assembly.
public class ActiveCodePaneEditor : IActiveCodePaneEditor
{
private readonly VBE _vbe;
Expand Down Expand Up @@ -46,7 +47,6 @@ public void SetSelection(QualifiedSelection selection)

public string GetLines(Selection selection)
{
// ReSharper disable once UseIndexedProperty
return Editor.get_Lines(selection.StartLine, selection.LineCount);
}

Expand Down
33 changes: 33 additions & 0 deletions RetailCoder.VBE/Root/RubberduckConventions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Linq;
using Microsoft.Vbe.Interop;
using Ninject;
using Ninject.Extensions.Conventions;
using Rubberduck.Parsing;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor;

namespace Rubberduck.Root
{
internal class RubberduckConventions
{
private readonly IKernel _kernel;

public RubberduckConventions(IKernel kernel)
{
_kernel = kernel;
}

public void Apply(VBE vbe, AddIn addin)
{
_kernel.Bind<VBE>().ToConstant(vbe);
_kernel.Bind<AddIn>().ToConstant(addin);
_kernel.Bind<App>().ToSelf();

// bind IFoo to Foo across all assemblies:
_kernel.Bind(t => t.FromThisAssembly().SelectAllClasses().BindDefaultInterface());
_kernel.Bind(t => t.FromAssemblyContaining<Selection>().SelectAllClasses().BindDefaultInterface());
_kernel.Bind(t => t.FromAssemblyContaining<IRubberduckParser>().SelectAllClasses().BindDefaultInterface()
.ConfigureFor<RubberduckParser>(service => service.InSingletonScope()));
}
}
}
5 changes: 5 additions & 0 deletions RetailCoder.VBE/Rubberduck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@
<HintPath>..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Ninject.Extensions.Conventions">
<HintPath>..\packages\Ninject.Extensions.Conventions.3.2.0.0\lib\net45-full\Ninject.Extensions.Conventions.dll</HintPath>
</Reference>
<Reference Include="Office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<SpecificVersion>False</SpecificVersion>
<EmbedInteropTypes>True</EmbedInteropTypes>
Expand Down Expand Up @@ -249,6 +252,8 @@
<Compile Include="Refactorings\ReorderParameters\ReorderParametersPresenter.cs" />
<Compile Include="Refactorings\ReorderParameters\ReorderParametersPresenterFactory.cs" />
<Compile Include="Refactorings\ReorderParameters\ReorderParametersRefactoring.cs" />
<Compile Include="Root\ActiveCodePaneEditor.cs" />
<Compile Include="Root\RubberduckConventions.cs" />
<Compile Include="Settings\DisplayLanguageSetting.cs" />
<Compile Include="Settings\SourceControlConfiguration.cs" />
<Compile Include="Settings\SourceControlConfigurationService.cs" />
Expand Down
4 changes: 2 additions & 2 deletions RetailCoder.VBE/Settings/ConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace Rubberduck.Settings
{
public interface IGeneralConfigService : IConfigurationService<Configuration>
public interface IConfigurationLoader : IConfigurationService<Configuration>
{
CodeInspectionSetting[] GetDefaultCodeInspections();
Configuration GetDefaultConfiguration();
ToDoMarker[] GetDefaultTodoMarkers();
IList<IInspection> GetImplementedCodeInspections();
}

public class ConfigurationLoader : XmlConfigurationServiceBase<Configuration>, IGeneralConfigService
public class ConfigurationLoader : XmlConfigurationServiceBase<Configuration>, IConfigurationLoader
{
protected override string ConfigFile
{
Expand Down
9 changes: 8 additions & 1 deletion RetailCoder.VBE/UI/ParserErrors/ParserErrorsPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ public override string ToString()
}
}

public class ParserErrorsPresenter : DockablePresenterBase
public interface IParserErrorsPresenter
{
void Show();
void Clear();
void AddError(ParseErrorEventArgs error);
}

public class ParserErrorsPresenter : DockablePresenterBase, IParserErrorsPresenter
{
public ParserErrorsPresenter(VBE vbe, AddIn addin)
: base(vbe, addin, new SimpleListControl(RubberduckUI.ParseErrors_Caption))
Expand Down
4 changes: 2 additions & 2 deletions RetailCoder.VBE/UI/RubberduckMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class RubberduckMenu : Menu
private readonly CodeExplorerMenu _codeExplorerMenu;
private readonly CodeInspectionsMenu _codeInspectionsMenu;
private readonly RefactorMenu _refactorMenu;
private readonly IGeneralConfigService _configService;
private readonly IConfigurationLoader _configService;
private readonly IRubberduckParser _parser;
private readonly IActiveCodePaneEditor _editor;
private readonly IRubberduckCodePaneFactory _factory;
Expand All @@ -40,7 +40,7 @@ internal class RubberduckMenu : Menu

private ProjectExplorerContextMenu _projectExplorerContextMenu;

public RubberduckMenu(VBE vbe, AddIn addIn, IGeneralConfigService configService, IRubberduckParser parser, IActiveCodePaneEditor editor, IInspector inspector, IRubberduckCodePaneFactory factory)
public RubberduckMenu(VBE vbe, AddIn addIn, IConfigurationLoader configService, IRubberduckParser parser, IActiveCodePaneEditor editor, IInspector inspector, IRubberduckCodePaneFactory factory)
: base(vbe, addIn)
{
_addIn = addIn;
Expand Down
8 changes: 2 additions & 6 deletions RetailCoder.VBE/UI/Settings/GeneralSettingsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ namespace Rubberduck.UI.Settings
{
public partial class GeneralSettingsControl : UserControl
{
private readonly IGeneralConfigService _configService;
private readonly DisplayLanguageSetting _currentLanguage;

public GeneralSettingsControl()
{
InitializeComponent();
Expand All @@ -18,11 +15,9 @@ public GeneralSettingsControl()
LoadLanguageList();
}

public GeneralSettingsControl(DisplayLanguageSetting displayLanguage, IGeneralConfigService configService)
public GeneralSettingsControl(DisplayLanguageSetting displayLanguage)
: this()
{
_configService = configService;
_currentLanguage = displayLanguage;
LanguageList.SelectedItem = displayLanguage;
}

Expand All @@ -41,6 +36,7 @@ private void LoadLanguageList()
new DisplayLanguageSetting("de-DE"),
};

// ReSharper disable once CoVariantArrayConversion
LanguageList.Items.AddRange(settings.Where(item => item.Exists).ToArray());
LanguageList.DisplayMember = "Name";
}
Expand Down
6 changes: 3 additions & 3 deletions RetailCoder.VBE/UI/Settings/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class _SettingsDialog : Form
private const string ProgId = "Rubberduck.UI.Settings.SettingsDialog";

private Configuration _config;
private IGeneralConfigService _configService;
private IConfigurationLoader _configService;
private ConfigurationTreeViewControl _treeview;
private Control _activeControl;

Expand Down Expand Up @@ -85,7 +85,7 @@ private void OkButton_Click(object sender, EventArgs e)
Close();
}

public _SettingsDialog(IGeneralConfigService configService)
public _SettingsDialog(IConfigurationLoader configService)
: this()
{
_configService = configService;
Expand All @@ -105,7 +105,7 @@ private void LoadWindow()
splitContainer1.Panel1.Controls.Add(_treeview);
_treeview.Dock = DockStyle.Fill;

_generalSettingsView = new GeneralSettingsControl(_config.UserSettings.LanguageSetting, _configService);
_generalSettingsView = new GeneralSettingsControl(_config.UserSettings.LanguageSetting);

var markers = _config.UserSettings.ToDoListSettings.ToDoMarkers;
var gridViewSort = new GridViewSort<ToDoMarker>("Priority", true);
Expand Down
1 change: 1 addition & 0 deletions RetailCoder.VBE/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<package id="Antlr4" version="4.3.0" targetFramework="net45" />
<package id="Antlr4.Runtime" version="4.3.0" targetFramework="net45" />
<package id="Ninject" version="3.2.2.0" targetFramework="net45" />
<package id="Ninject.Extensions.Conventions" version="3.2.0.0" targetFramework="net45" />
<package id="NLog" version="3.2.1" targetFramework="net45" />
<package id="NLog.Schema" version="3.2.1" targetFramework="net45" />
</packages>
1 change: 0 additions & 1 deletion Rubberduck.VBEEditor/Rubberduck.VBEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActiveCodePaneEditor.cs" />
<Compile Include="DocumentEventHandlerPrefixes.cs" />
<Compile Include="Extensions\CodeModuleExtensions.cs" />
<Compile Include="CodeModuleSelection.cs" />
Expand Down
6 changes: 3 additions & 3 deletions RubberduckTests/Mocks/MockProjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public MockProjectBuilder AddComponent(string name, vbext_ComponentType type, st
/// <summary>
/// Adds a new mock component to the project.
/// Use the <see cref="AddComponent(string,vbext_ComponentType,string)"/> overload to add module components.
/// Use this overload to add user forms created with a <see cref="MockUserFormBuilder"/> instance.
/// Use this overload to add user forms created with a <see cref="RubberduckTests.Mocks.MockUserFormBuilder"/> instance.
/// </summary>
/// <param name="component">The component to add.</param>
/// <returns>Returns the <see cref="MockProjectBuilder"/> instance.</returns>
Expand Down Expand Up @@ -88,11 +88,11 @@ public MockVbeBuilder MockVbeBuilder()
}

/// <summary>
/// Creates a <see cref="MockUserFormBuilder"/> to build a new form component.
/// Creates a <see cref="RubberduckTests.Mocks.MockUserFormBuilder"/> to build a new form component.
/// </summary>
/// <param name="name">The name of the component.</param>
/// <param name="content">The VBA code associated to the component.</param>
public MockUserFormBuilder UserFormBuilder(string name, string content)
public MockUserFormBuilder MockUserFormBuilder(string name, string content)
{
var component = CreateComponentMock(name, vbext_ComponentType.vbext_ct_MSForm, content);
return new MockUserFormBuilder(component, this);
Expand Down
3 changes: 3 additions & 0 deletions RubberduckTests/RubberduckTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
<HintPath>..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Ninject.Extensions.Conventions">
<HintPath>..\packages\Ninject.Extensions.Conventions.3.2.0.0\lib\net45-full\Ninject.Extensions.Conventions.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\packages\NLog.3.2.1\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
Expand Down
1 change: 1 addition & 0 deletions RubberduckTests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<package id="LibGit2Sharp" version="0.22.0-pre20150516171636" targetFramework="net45" />
<package id="Moq" version="4.2.1409.1722" targetFramework="net45" />
<package id="Ninject" version="3.2.2.0" targetFramework="net45" />
<package id="Ninject.Extensions.Conventions" version="3.2.0.0" targetFramework="net45" />
<package id="NLog" version="3.2.1" targetFramework="net45" />
</packages>

0 comments on commit 7992cf9

Please sign in to comment.