Skip to content

Commit b0e206f

Browse files
authored
Merge pull request #2289 from retailcoder/next
Wrapped SafeComWrappers with interfaces
2 parents dc2b207 + dcd672f commit b0e206f

File tree

301 files changed

+5362
-2760
lines changed

Some content is hidden

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

301 files changed

+5362
-2760
lines changed

RetailCoder.VBE/API/ParserState.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Rubberduck.Parsing.Preprocessing;
1010
using System.Globalization;
1111
using Rubberduck.Parsing.Symbols;
12-
using Rubberduck.VBEditor.SafeComWrappers;
1312
using Rubberduck.VBEditor.SafeComWrappers.VBA;
1413

1514
namespace Rubberduck.API

RetailCoder.VBE/App.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,28 @@
1111
using System;
1212
using System.Globalization;
1313
using System.Windows.Forms;
14-
using Rubberduck.VBEditor.SafeComWrappers.VBA;
14+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1515

1616
namespace Rubberduck
1717
{
1818
public sealed class App : IDisposable
1919
{
20-
private readonly VBE _vbe;
20+
private readonly IVBE _vbe;
2121
private readonly IMessageBox _messageBox;
2222
private readonly IRubberduckParser _parser;
23-
private AutoSave.AutoSave _autoSave;
24-
private IGeneralConfigService _configService;
23+
private readonly AutoSave.AutoSave _autoSave;
24+
private readonly IGeneralConfigService _configService;
2525
private readonly IAppMenu _appMenus;
26-
private RubberduckCommandBar _stateBar;
27-
private IRubberduckHooks _hooks;
26+
private readonly RubberduckCommandBar _stateBar;
27+
private readonly IRubberduckHooks _hooks;
2828
private readonly UI.Settings.Settings _settings;
2929

3030
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
3131

3232
private Configuration _config;
3333

34-
public App(VBE vbe, IMessageBox messageBox,
34+
public App(IVBE vbe,
35+
IMessageBox messageBox,
3536
UI.Settings.Settings settings,
3637
IRubberduckParser parser,
3738
IGeneralConfigService configService,
@@ -145,14 +146,10 @@ public void Startup()
145146
EnsureDirectoriesExist();
146147
LoadConfig();
147148
_appMenus.Initialize();
149+
_stateBar.Initialize();
148150
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
149151
_appMenus.Localize();
150152
UpdateLoggingLevel();
151-
152-
//if (_vbe.VBProjects.Count != 0)
153-
//{
154-
// _parser.State.OnParseRequested(this);
155-
//}
156153
}
157154

158155
public void Shutdown()
@@ -177,12 +174,12 @@ private void Parser_StateChanged(object sender, EventArgs e)
177174
{
178175
Logger.Debug("App handles StateChanged ({0}), evaluating menu states...", _parser.State.Status);
179176
_appMenus.EvaluateCanExecute(_parser.State);
177+
_stateBar.SetSelectionText();
180178
}
181179

182180
private void LoadConfig()
183181
{
184182
_config = _configService.LoadConfiguration();
185-
186183
_autoSave.ConfigServiceSettingsChanged(this, EventArgs.Empty);
187184

188185
var currentCulture = RubberduckUI.Culture;
@@ -214,14 +211,12 @@ public void Dispose()
214211
_parser.State.StatusMessageUpdate -= State_StatusMessageUpdate;
215212
_parser.State.Dispose();
216213
_parser.Dispose();
217-
// I won't set this to null because other components may try to release things
218214
}
219215

220216
if (_hooks != null)
221217
{
222218
_hooks.MessageReceived -= _hooks_MessageReceived;
223219
_hooks.Dispose();
224-
_hooks = null;
225220
}
226221

227222
if (_settings != null)
@@ -232,20 +227,17 @@ public void Dispose()
232227
if (_configService != null)
233228
{
234229
_configService.SettingsChanged -= _configService_SettingsChanged;
235-
_configService = null;
236230
}
237231

238232
if (_stateBar != null)
239233
{
240234
_stateBar.Refresh -= _stateBar_Refresh;
241235
_stateBar.Dispose();
242-
_stateBar = null;
243236
}
244237

245238
if (_autoSave != null)
246239
{
247240
_autoSave.Dispose();
248-
_autoSave = null;
249241
}
250242

251243
UiDispatcher.Shutdown();

RetailCoder.VBE/AutoSave/AutoSave.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
using System.Runtime.InteropServices;
55
using System.Timers;
66
using Rubberduck.Settings;
7-
using Rubberduck.VBEditor.SafeComWrappers.VBA;
7+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
88

99
namespace Rubberduck.AutoSave
1010
{
1111
public sealed class AutoSave : IDisposable
1212
{
13-
private readonly VBE _vbe;
13+
private readonly IVBE _vbe;
1414
private readonly IGeneralConfigService _configService;
1515
private Timer _timer = new Timer();
1616

1717
private const int VbeSaveCommandId = 3;
1818

19-
public AutoSave(VBE vbe, IGeneralConfigService configService)
19+
public AutoSave(IVBE vbe, IGeneralConfigService configService)
2020
{
2121
_vbe = vbe;
2222
_configService = configService;
@@ -39,7 +39,7 @@ public void ConfigServiceSettingsChanged(object sender, EventArgs e)
3939
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
4040
{
4141
var projects = _vbe.VBProjects;
42-
if (projects.Any(p => !p.Saved))
42+
if (projects.Any(p => !p.IsSaved))
4343
{
4444
try
4545
{

RetailCoder.VBE/Common/DeclarationIconCache.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Windows.Media.Imaging;
5-
using Microsoft.Vbe.Interop;
65
using Rubberduck.Parsing.Symbols;
76

87
namespace Rubberduck.Common
@@ -29,31 +28,6 @@ public BitmapImage this[Declaration declaration]
2928
}
3029
}
3130

32-
public static BitmapImage ComponentIcon(vbext_ComponentType componentType)
33-
{
34-
Tuple<DeclarationType, Accessibility> key;
35-
switch (componentType)
36-
{
37-
case vbext_ComponentType.vbext_ct_StdModule:
38-
key = Tuple.Create(DeclarationType.ProceduralModule, Accessibility.Public);
39-
break;
40-
case vbext_ComponentType.vbext_ct_ClassModule:
41-
key = Tuple.Create(DeclarationType.ClassModule, Accessibility.Public);
42-
break;
43-
case vbext_ComponentType.vbext_ct_Document:
44-
key = Tuple.Create(DeclarationType.Document, Accessibility.Public);
45-
break;
46-
case vbext_ComponentType.vbext_ct_MSForm:
47-
key = Tuple.Create(DeclarationType.UserForm, Accessibility.Public);
48-
break;
49-
default:
50-
key = Tuple.Create(DeclarationType.Project, Accessibility.Public);
51-
break;
52-
}
53-
54-
return Images[key];
55-
}
56-
5731
private static Uri GetIconUri(DeclarationType declarationType, Accessibility accessibility)
5832
{
5933
const string baseUri = @"../../Resources/Custom/PNG/";

RetailCoder.VBE/Common/Dispatch/ReferencesEventsSink.cs

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

RetailCoder.VBE/Common/ModuleExporter.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System.IO;
22
using System.Reflection;
3-
using Rubberduck.VBEditor.Extensions;
43
using Rubberduck.Parsing.VBA;
5-
using Rubberduck.VBEditor.SafeComWrappers;
6-
using Rubberduck.VBEditor.SafeComWrappers.VBA;
4+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
75

86
namespace Rubberduck.Common
97
{
@@ -18,7 +16,7 @@ public string ExportPath
1816
}
1917
}
2018

21-
public string Export(VBComponent component)
19+
public string Export(IVBComponent component)
2220
{
2321
return component.ExportAsSourceFile(ExportPath);
2422
}

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
using Rubberduck.Settings;
1111
using Rubberduck.UI.Command;
1212
using NLog;
13-
using Rubberduck.VBEditor.SafeComWrappers;
14-
using Rubberduck.VBEditor.SafeComWrappers.VBA;
13+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1514

1615
namespace Rubberduck.Common
1716
{
@@ -29,7 +28,7 @@ public class RubberduckHooks : IRubberduckHooks
2928
private readonly IList<IAttachable> _hooks = new List<IAttachable>();
3029
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
3130

32-
public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<CommandBase> commands)
31+
public RubberduckHooks(IVBE vbe, IGeneralConfigService config, IEnumerable<CommandBase> commands)
3332
{
3433
var mainWindow = vbe.MainWindow;
3534
{

RetailCoder.VBE/Extension.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Extensibility;
2-
using Microsoft.Vbe.Interop;
32
using Ninject;
43
using Ninject.Extensions.Factory;
54
using Rubberduck.Root;
@@ -17,6 +16,7 @@
1716
using NLog;
1817
using Rubberduck.Settings;
1918
using Rubberduck.SettingsProvider;
19+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
2020

2121
namespace Rubberduck
2222
{
@@ -33,8 +33,8 @@ public class _Extension : IDTExtensibility2
3333
private const string ClassId = "8D052AD8-BBD2-4C59-8DEC-F697CA1F8A66";
3434
private const string ProgId = "Rubberduck.Extension";
3535

36-
private VBEditor.SafeComWrappers.VBA.VBE _ide;
37-
private VBEditor.SafeComWrappers.VBA.AddIn _addin;
36+
private IVBE _ide;
37+
private IAddIn _addin;
3838
private bool _isInitialized;
3939
private bool _isBeginShutdownExecuted;
4040

@@ -49,8 +49,23 @@ public void OnConnection(object Application, ext_ConnectMode ConnectMode, object
4949
{
5050
try
5151
{
52-
_ide = new VBEditor.SafeComWrappers.VBA.VBE((VBE)Application);
53-
_addin = new VBEditor.SafeComWrappers.VBA.AddIn((AddIn) AddInInst) {Object = this};
52+
if (Application is Microsoft.Vbe.Interop.VBE)
53+
{
54+
var vbe = (Microsoft.Vbe.Interop.VBE) Application;
55+
_ide = new VBEditor.SafeComWrappers.VBA.VBE(vbe);
56+
57+
var addin = (Microsoft.Vbe.Interop.AddIn)AddInInst;
58+
_addin = new VBEditor.SafeComWrappers.VBA.AddIn(addin) { Object = this };
59+
}
60+
else if (Application is Microsoft.VB6.Interop.VBIDE.VBE)
61+
{
62+
var vbe = Application as Microsoft.VB6.Interop.VBIDE.VBE;
63+
_ide = new VBEditor.SafeComWrappers.VB6.VBE(vbe);
64+
65+
var addin = (Microsoft.VB6.Interop.VBIDE.AddIn) AddInInst;
66+
_addin = new VBEditor.SafeComWrappers.VB6.AddIn(addin);
67+
}
68+
5469

5570
switch (ConnectMode)
5671
{
@@ -175,7 +190,15 @@ private void ShutdownAddIn()
175190
_kernel = null;
176191
}
177192

178-
_ide.Release();
193+
try
194+
{
195+
_ide.Release();
196+
}
197+
catch (Exception e)
198+
{
199+
_logger.Error(e);
200+
}
201+
179202
_isInitialized = false;
180203
}
181204
}

RetailCoder.VBE/Inspections/ImplicitActiveSheetReferenceInspection.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using Rubberduck.Parsing.VBA;
4-
using Rubberduck.VBEditor.SafeComWrappers;
5-
using Rubberduck.VBEditor.SafeComWrappers.VBA;
4+
using Rubberduck.VBEditor.Application;
65
using Rubberduck.VBEditor.Extensions;
7-
using Rubberduck.VBEditor.VBEHost;
6+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
87

98
namespace Rubberduck.Inspections
109
{
1110
public sealed class ImplicitActiveSheetReferenceInspection : InspectionBase
1211
{
1312
private readonly IHostApplication _hostApp;
1413

15-
public ImplicitActiveSheetReferenceInspection(VBE vbe, RubberduckParserState state)
14+
public ImplicitActiveSheetReferenceInspection(IVBE vbe, RubberduckParserState state)
1615
: base(state)
1716
{
1817
_hostApp = vbe.HostApplication();

RetailCoder.VBE/Inspections/ImplicitActiveWorkbookReferenceInspection.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
using System.Linq;
33
using Rubberduck.Parsing.Symbols;
44
using Rubberduck.Parsing.VBA;
5-
using Rubberduck.VBEditor.SafeComWrappers;
6-
using Rubberduck.VBEditor.SafeComWrappers.VBA;
5+
using Rubberduck.VBEditor.Application;
76
using Rubberduck.VBEditor.Extensions;
8-
using Rubberduck.VBEditor.VBEHost;
7+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
98

109
namespace Rubberduck.Inspections
1110
{
1211
public sealed class ImplicitActiveWorkbookReferenceInspection : InspectionBase
1312
{
1413
private readonly IHostApplication _hostApp;
1514

16-
public ImplicitActiveWorkbookReferenceInspection(VBE vbe, RubberduckParserState state)
15+
public ImplicitActiveWorkbookReferenceInspection(IVBE vbe, RubberduckParserState state)
1716
: base(state)
1817
{
1918
_hostApp = vbe.HostApplication();

RetailCoder.VBE/Inspections/InspectionBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Rubberduck.Parsing.Symbols;
66
using Rubberduck.Parsing.VBA;
77
using Rubberduck.VBEditor.SafeComWrappers;
8+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
89
using Rubberduck.VBEditor.SafeComWrappers.VBA;
910

1011
namespace Rubberduck.Inspections
@@ -92,7 +93,7 @@ protected virtual IEnumerable<Declaration> BuiltInDeclarations
9293
get { return State.AllDeclarations.Where(declaration => declaration.IsBuiltIn); }
9394
}
9495

95-
protected bool IsInspectionDisabled(VBComponent component, int line)
96+
protected bool IsInspectionDisabled(IVBComponent component, int line)
9697
{
9798
var annotations = State.GetModuleAnnotations(component).ToList();
9899

@@ -114,6 +115,11 @@ protected bool IsInspectionDisabled(VBComponent component, int line)
114115
return false;
115116
}
116117

118+
protected bool IsInspectionDisabled(VBComponent component, int line)
119+
{
120+
return IsInspectionDisabled(component, line);
121+
}
122+
117123
protected bool IsInspectionDisabled(Declaration declaration, string inspectionName)
118124
{
119125
if (declaration.DeclarationType == DeclarationType.Parameter)

0 commit comments

Comments
 (0)