Skip to content

Commit ffce5d8

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into Issue1380
2 parents fb205c2 + f499deb commit ffce5d8

File tree

172 files changed

+3522
-10396
lines changed

Some content is hidden

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

172 files changed

+3522
-10396
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ ClientBin/
130130
*.[Pp]ublish.xml
131131
*.pfx
132132
*.publishsettings
133+
*.playlist
133134

134135
# Monodevelop detritus
135136
*.userprefs

RetailCoder.VBE/API/ParserState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void Dispose()
161161
}
162162

163163

164-
_vbe.Release();
164+
//_vbe.Release();
165165
_disposed = true;
166166
}
167167
}

RetailCoder.VBE/App.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Rubberduck.UI;
88
using Rubberduck.UI.Command.MenuItems;
99
using System;
10+
using System.Diagnostics;
1011
using System.Globalization;
1112
using System.Windows.Forms;
1213
using Rubberduck.Inspections.Resources;
@@ -129,6 +130,7 @@ public void Shutdown()
129130
{
130131
try
131132
{
133+
Debug.WriteLine("App calling Hooks.Detach.");
132134
_hooks.Detach();
133135
}
134136
catch

RetailCoder.VBE/Extension.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
using System.Runtime.InteropServices;
1515
using System.Windows.Forms;
1616
using System.Windows.Threading;
17+
using Microsoft.Vbe.Interop;
1718
using Ninject.Extensions.Interception;
1819
using NLog;
1920
using Rubberduck.Settings;
2021
using Rubberduck.SettingsProvider;
2122
using Rubberduck.VBEditor.Events;
23+
using Rubberduck.VBEditor.SafeComWrappers;
2224
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
2325

2426
namespace Rubberduck
@@ -52,13 +54,13 @@ public void OnConnection(object Application, ext_ConnectMode ConnectMode, object
5254
{
5355
try
5456
{
55-
if (Application is Microsoft.Vbe.Interop.VBE)
57+
if (Application is VBE)
5658
{
57-
var vbe = (Microsoft.Vbe.Interop.VBE) Application;
59+
var vbe = (VBE) Application;
5860
_ide = new VBEditor.SafeComWrappers.VBA.VBE(vbe);
5961
VBENativeServices.HookEvents(_ide);
6062

61-
var addin = (Microsoft.Vbe.Interop.AddIn)AddInInst;
63+
var addin = (AddIn)AddInInst;
6264
_addin = new VBEditor.SafeComWrappers.VBA.AddIn(addin) { Object = this };
6365
}
6466
else if (Application is Microsoft.VB6.Interop.VBIDE.VBE)
@@ -221,35 +223,31 @@ private void Startup()
221223

222224
private void ShutdownAddIn()
223225
{
226+
Debug.WriteLine("Extension unhooking VBENativeServices events.");
224227
VBENativeServices.UnhookEvents();
225228

226229
var currentDomain = AppDomain.CurrentDomain;
227230
currentDomain.AssemblyResolve -= LoadFromSameFolder;
228-
231+
Debug.WriteLine("Extension broadcasting shutdown.");
229232
User32.EnumChildWindows(_ide.MainWindow.Handle(), EnumCallback, new IntPtr(0));
230233

234+
Debug.WriteLine("Extension calling ReleaseDockableHosts.");
235+
VBEditor.SafeComWrappers.VBA.Windows.ReleaseDockableHosts();
236+
231237
if (_app != null)
232238
{
239+
Debug.WriteLine("Extension calling App.Shutdown.");
233240
_app.Shutdown();
234241
_app = null;
235242
}
236243

237244
if (_kernel != null)
238245
{
246+
Debug.WriteLine("Extension calling Kernel.Dispose.");
239247
_kernel.Dispose();
240248
_kernel = null;
241249
}
242250

243-
try
244-
{
245-
_ide.Release();
246-
}
247-
catch (Exception e)
248-
{
249-
_logger.Error(e);
250-
}
251-
252-
GC.WaitForPendingFinalizers();
253251
_isInitialized = false;
254252
}
255253

RetailCoder.VBE/Inspections/QuickFixes/AssignedByValParameterMakeLocalCopyQuickFix.cs

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public AssignedByValParameterMakeLocalCopyQuickFix(Declaration target, Qualified
2727
_target = target;
2828
_dialogFactory = dialogFactory;
2929
_parserState = parserState;
30-
_forbiddenNames = GetIdentifierNamesAccessibleToProcedureContext();
31-
_localCopyVariableName = ComputeSuggestedName();
30+
_forbiddenNames = parserState.DeclarationFinder.GetDeclarationsWithIdentifiersToAvoid(target).Select(n => n.IdentifierName);
31+
_localCopyVariableName = ComputeSuggestedName();
3232
}
3333

3434
public override bool CanFixInModule { get { return false; } }
@@ -113,61 +113,5 @@ private string BuildLocalCopyAssignment()
113113
return (_target.AsTypeDeclaration is ClassModuleDeclaration ? Tokens.Set + " " : string.Empty)
114114
+ _localCopyVariableName + " = " + _target.IdentifierName;
115115
}
116-
117-
private IEnumerable<string> GetIdentifierNamesAccessibleToProcedureContext()
118-
{
119-
return _parserState.AllUserDeclarations
120-
.Where(candidateDeclaration =>
121-
(
122-
IsDeclarationInTheSameProcedure(candidateDeclaration, _target)
123-
|| IsDeclarationInTheSameModule(candidateDeclaration, _target)
124-
|| IsProjectGlobalDeclaration(candidateDeclaration, _target))
125-
).Select(declaration => declaration.IdentifierName).Distinct();
126-
}
127-
128-
private bool IsDeclarationInTheSameProcedure(Declaration candidateDeclaration, Declaration scopingDeclaration)
129-
{
130-
return candidateDeclaration.ParentScope == scopingDeclaration.ParentScope;
131-
}
132-
133-
private bool IsDeclarationInTheSameModule(Declaration candidateDeclaration, Declaration scopingDeclaration)
134-
{
135-
return candidateDeclaration.ComponentName == scopingDeclaration.ComponentName
136-
&& !IsDeclaredInMethodOrProperty(candidateDeclaration.ParentDeclaration.Context);
137-
}
138-
139-
private bool IsProjectGlobalDeclaration(Declaration candidateDeclaration, Declaration scopingDeclaration)
140-
{
141-
return candidateDeclaration.ProjectName == scopingDeclaration.ProjectName
142-
&& !(candidateDeclaration.ParentScopeDeclaration is ClassModuleDeclaration)
143-
&& (candidateDeclaration.Accessibility == Accessibility.Public
144-
|| ((candidateDeclaration.Accessibility == Accessibility.Implicit)
145-
&& (candidateDeclaration.ParentScopeDeclaration is ProceduralModuleDeclaration)));
146-
}
147-
148-
private bool IsDeclaredInMethodOrProperty(RuleContext procedureContext)
149-
{
150-
if (procedureContext is VBAParser.SubStmtContext)
151-
{
152-
return true;
153-
}
154-
else if (procedureContext is VBAParser.FunctionStmtContext)
155-
{
156-
return true;
157-
}
158-
else if (procedureContext is VBAParser.PropertyLetStmtContext)
159-
{
160-
return true;
161-
}
162-
else if (procedureContext is VBAParser.PropertyGetStmtContext)
163-
{
164-
return true;
165-
}
166-
else if (procedureContext is VBAParser.PropertySetStmtContext)
167-
{
168-
return true;
169-
}
170-
return false;
171-
}
172116
}
173117
}

RetailCoder.VBE/Refactorings/Rename/RenameRefactoring.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ public void Refactor(Declaration target)
101101

102102
private void Rename()
103103
{
104-
var declaration = _state.DeclarationFinder.GetDeclarationsAccessibleToScope(_model.Target, _model.Declarations)
104+
var declaration = _state.DeclarationFinder.GetDeclarationsWithIdentifiersToAvoid(_model.Target)
105105
.Where(d => d.IdentifierName.Equals(_model.NewName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
106106
if (declaration != null)
107107
{
108108
var message = string.Format(RubberduckUI.RenameDialog_ConflictingNames, _model.NewName,
109-
declaration.IdentifierName);
109+
declaration);
110110
var rename = _messageBox.Show(message, RubberduckUI.RenameDialog_Caption, MessageBoxButtons.YesNo,
111111
MessageBoxIcon.Exclamation);
112112

RetailCoder.VBE/UI/Controls/BindableTextEditor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public BindableTextEditor()
2424
TextArea.TextView.LinkTextUnderline = false;
2525
TextArea.TextView.LinkTextForegroundBrush = new SolidColorBrush(Colors.Green);
2626
Options.RequireControlModifierForHyperlinkClick = false;
27-
Options.EnableHyperlinks = true;
27+
//This needs some work if hyperlinks need to open in an external browser.
28+
Options.EnableHyperlinks = false;
2829
Options.EnableEmailHyperlinks = true;
2930
}
3031

RetailCoder.VBE/UI/Controls/SearchResultPresenterInstanceManager.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public SearchResultPresenterInstanceManager(IVBE vbe, IAddIn addin)
2222
private SearchResultsDockablePresenter _presenter;
2323
public SearchResultsDockablePresenter Presenter(ISearchResultsWindowViewModel viewModel)
2424
{
25-
if (_presenter == null || _presenter.IsDisposed)
25+
if (_presenter == null)
2626
{
2727
if (_view.ViewModel == null)
2828
{
@@ -54,13 +54,6 @@ private void Dispose(bool disposing)
5454
{
5555
_view.ViewModel.LastTabClosed -= viewModel_LastTabClosed;
5656
}
57-
58-
if (_presenter != null)
59-
{
60-
_presenter.Dispose();
61-
_presenter = null;
62-
}
63-
6457
_disposed = true;
6558
}
6659
}

RetailCoder.VBE/UI/DockableToolwindowPresenter.cs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Runtime.InteropServices;
34
using System.Windows.Forms;
45
using NLog;
@@ -19,7 +20,7 @@ public interface IDockablePresenter : IPresenter
1920
UserControl UserControl { get; }
2021
}
2122

22-
public abstract class DockableToolwindowPresenter : IDockablePresenter, IDisposable
23+
public abstract class DockableToolwindowPresenter : IDockablePresenter
2324
{
2425
private readonly IAddIn _addin;
2526
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
@@ -109,36 +110,9 @@ public void Hide()
109110
_window.IsVisible = false;
110111
}
111112

112-
private bool _disposed;
113-
public void Dispose()
114-
{
115-
Dispose(true);
116-
GC.SuppressFinalize(this);
117-
}
118-
119113
~DockableToolwindowPresenter()
120114
{
121-
Dispose(false);
122-
}
123-
124-
public bool IsDisposed { get { return _disposed; } }
125-
protected virtual void Dispose(bool disposing)
126-
{
127-
if (_disposed)
128-
{
129-
return;
130-
}
131-
if (disposing && _window != null)
132-
{
133-
// cleanup unmanaged resource wrappers
134-
_window.Close();
135-
_window.Release(true);
136-
}
137-
if (!disposing)
138-
{
139-
return;
140-
}
141-
_disposed = true;
115+
Debug.WriteLine("DockableToolwindowPresenter finalized.");
142116
}
143117
}
144118
}

RetailCoder.VBE/UI/DockableWindowHost.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel;
3+
using System.Diagnostics;
34
using System.Drawing;
45
using System.Runtime.InteropServices;
56
using System.Windows.Forms;
@@ -85,8 +86,8 @@ private void OnCallBackEvent(object sender, SubClassingWindowEventArgs e)
8586
}
8687
else
8788
{
89+
Debug.WriteLine("DockableWindowHost removed event handler.");
8890
_subClassingWindow.CallBackEvent -= OnCallBackEvent;
89-
_subClassingWindow.Dispose();
9091
}
9192
}
9293

@@ -146,11 +147,26 @@ protected override void DefWndProc(ref Message m)
146147
//See the comment in the ctor for why we have to listen for this.
147148
if (m.Msg == (int) WM.DESTROY)
148149
{
150+
Debug.WriteLine("DockableWindowHost received WM.DESTROY.");
149151
_thisHandle.Free();
150152
}
151153
base.DefWndProc(ref m);
152154
}
153155

156+
//override
157+
158+
public void Release()
159+
{
160+
Debug.WriteLine("DockableWindowHost release called.");
161+
_subClassingWindow.Dispose();
162+
}
163+
164+
protected override void DestroyHandle()
165+
{
166+
Debug.WriteLine("DockableWindowHost DestroyHandle called.");
167+
base.DestroyHandle();
168+
}
169+
154170
[ComVisible(false)]
155171
public class ParentWindow : SubclassingWindow
156172
{

0 commit comments

Comments
 (0)