Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions RetailCoder.VBE/API/ParserState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
using Rubberduck.Parsing.Preprocessing;
using System.Globalization;
using Rubberduck.Parsing.Symbols;
using Rubberduck.VBEditor.SafeComWrappers;
using Rubberduck.VBEditor.SafeComWrappers.VBA;

namespace Rubberduck.API
{
[ComVisible(true)]
public interface IParserState
{
void Initialize(VBE vbe);
void Initialize(Microsoft.Vbe.Interop.VBE vbe);

void Parse();
void BeginParse();
Expand Down Expand Up @@ -57,20 +58,20 @@ public ParserState()
UiDispatcher.Initialize();
}

public void Initialize(VBE vbe)
public void Initialize(Microsoft.Vbe.Interop.VBE vbe)
{
if (_parser != null)
{
throw new InvalidOperationException("ParserState is already initialized.");
}

_vbe = vbe;
_vbe = new VBE(vbe);
_state = new RubberduckParserState(null);
_state.StateChanged += _state_StateChanged;

Func<IVBAPreprocessor> preprocessorFactory = () => new VBAPreprocessor(double.Parse(vbe.Version, CultureInfo.InvariantCulture));
Func<IVBAPreprocessor> preprocessorFactory = () => new VBAPreprocessor(double.Parse(_vbe.Version, CultureInfo.InvariantCulture));
_attributeParser = new AttributeParser(new ModuleExporter(), preprocessorFactory);
_parser = new ParseCoordinator(vbe, _state, _attributeParser, preprocessorFactory,
_parser = new ParseCoordinator(_vbe, _state, _attributeParser, preprocessorFactory,
new List<ICustomDeclarationLoader> { new DebugDeclarations(_state), new SpecialFormDeclarations(_state), new FormEventDeclarations(_state), new AliasDeclarations(_state) });
}

Expand Down
12 changes: 8 additions & 4 deletions RetailCoder.VBE/Inspections/QuickFixes/IgnoreOnceQuickFix.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Antlr4.Runtime;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Resources;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor;

Expand All @@ -15,8 +16,8 @@ public IgnoreOnceQuickFix(ParserRuleContext context, QualifiedSelection selectio
: base(context, selection, InspectionsUI.IgnoreOnce)
{
_inspectionName = inspectionName;
_annotationText = "'" + Parsing.Grammar.Annotations.AnnotationMarker +
Parsing.Grammar.Annotations.IgnoreInspection + ' ' + inspectionName;
_annotationText = "'" + Annotations.AnnotationMarker +
Annotations.IgnoreInspection + ' ' + inspectionName;
}

public override bool CanFixInModule { get { return false; } } // not quite "once" if applied to entire module
Expand All @@ -27,10 +28,13 @@ public override void Fix()
var module = Selection.QualifiedName.Component.CodeModule;
{
var insertLine = Selection.Selection.StartLine;

while (insertLine != 1 && module.GetLines(insertLine - 1, 1).EndsWith(" _"))
{
insertLine--;
}
var codeLine = insertLine == 1 ? string.Empty : module.GetLines(insertLine - 1, 1);
var annotationText = _annotationText;
var ignoreAnnotation = "'" + Parsing.Grammar.Annotations.AnnotationMarker + Parsing.Grammar.Annotations.IgnoreInspection;
var ignoreAnnotation = "'" + Annotations.AnnotationMarker + Annotations.IgnoreInspection;

int commentStart;
if (codeLine.HasComment(out commentStart) && codeLine.Substring(commentStart).StartsWith(ignoreAnnotation))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void Dispose()
{
if (_state != null)
{
_state.StateChanged += _state_StateChanged;
_state.StateChanged -= _state_StateChanged;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/UI/Command/FindAllReferencesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void Dispose()
{
if (_state != null)
{
_state.StateChanged += _state_StateChanged;
_state.StateChanged -= _state_StateChanged;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/UI/Command/ShowParserErrorsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void Dispose()
{
if (_state != null)
{
_state.StateChanged += _state_StateChanged;
_state.StateChanged -= _state_StateChanged;
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion RetailCoder.VBE/UI/UnitTesting/TestExplorerModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Rubberduck.UI.UnitTesting
{
public class TestExplorerModel : ViewModelBase
public class TestExplorerModel : ViewModelBase, IDisposable
{
private readonly IVBE _vbe;
private readonly RubberduckParserState _state;
Expand Down Expand Up @@ -168,5 +168,13 @@ private void OnTestsRefreshed()
handler.Invoke(this, EventArgs.Empty);
}
}

public void Dispose()
{
if (_state != null)
{
_state.StateChanged -= State_StateChanged;
}
}
}
}
22 changes: 11 additions & 11 deletions Rubberduck.VBEEditor/SafeComWrappers/Office.Core/CommandBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public ICommandBarControls Controls
public bool IsEnabled
{
get { return !IsWrappingNullReference && Target.Enabled; }
set { Target.Enabled = value; }
set { if (!IsWrappingNullReference) Target.Enabled = value; }
}

public int Height
{
get { return IsWrappingNullReference ? 0 : Target.Height; }
set { Target.Height = value; }
set { if (!IsWrappingNullReference) Target.Height = value; }
}

public int Index
Expand All @@ -46,25 +46,25 @@ public int Index
public int Left
{
get { return IsWrappingNullReference ? 0 : Target.Left; }
set { Target.Left = value; }
set { if (!IsWrappingNullReference) Target.Left = value; }
}

public string Name
{
get { return IsWrappingNullReference ? string.Empty : Target.Name; }
set { Target.Name = value; }
set { if (!IsWrappingNullReference) Target.Name = value; }
}

public CommandBarPosition Position
{
get { return IsWrappingNullReference ? 0 : (CommandBarPosition)Target.Position; }
set { Target.Position = (Microsoft.Office.Core.MsoBarPosition)value; }
set { if (!IsWrappingNullReference) Target.Position = (Microsoft.Office.Core.MsoBarPosition)value; }
}

public int Top
{
get { return IsWrappingNullReference ? 0 : Target.Top; }
set { Target.Top = value; }
set { if (!IsWrappingNullReference) Target.Top = value; }
}

public CommandBarType Type
Expand All @@ -75,28 +75,28 @@ public CommandBarType Type
public bool IsVisible
{
get { return !IsWrappingNullReference && Target.Visible; }
set { Target.Visible = value; }
set { if (!IsWrappingNullReference) Target.Visible = value; }
}

public int Width
{
get { return IsWrappingNullReference ? 0 : Target.Width; }
set { Target.Width = value; }
set { if (!IsWrappingNullReference) Target.Width = value; }
}

public ICommandBarControl FindControl(int id)
{
return new CommandBarControl(Target.FindControl(Id: id));
return new CommandBarControl(IsWrappingNullReference ? null : Target.FindControl(Id: id));
}

public ICommandBarControl FindControl(ControlType type, int id)
{
return new CommandBarControl(Target.FindControl(type, id));
return new CommandBarControl(IsWrappingNullReference ? null : Target.FindControl(type, id));
}

public void Delete()
{
Target.Delete();
if (!IsWrappingNullReference) Target.Delete();
}

public override void Release(bool final = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public event EventHandler<CommandBarButtonClickEventArgs> Click
private void Target_Click(Microsoft.Office.Core.CommandBarButton ctrl, ref bool cancelDefault)
{
var handler = _clickHandler;
if (handler == null)
if (handler == null || IsWrappingNullReference)
{
return;
}
Expand All @@ -72,38 +72,40 @@ private void Target_Click(Microsoft.Office.Core.CommandBarButton ctrl, ref bool
public bool IsBuiltInFace
{
get { return !IsWrappingNullReference && Button.BuiltInFace; }
set { Button.BuiltInFace = value; }
set { if (!IsWrappingNullReference) Button.BuiltInFace = value; }
}

public int FaceId
{
get { return IsWrappingNullReference ? 0 : Button.FaceId; }
set { Button.FaceId = value; }
set { if (!IsWrappingNullReference) Button.FaceId = value; }
}

public string ShortcutText
{
get { return IsWrappingNullReference ? string.Empty : Button.ShortcutText; }
set { Button.ShortcutText = value; }
set { if (!IsWrappingNullReference) Button.ShortcutText = value; }
}

public ButtonState State
{
get { return IsWrappingNullReference ? 0 : (ButtonState)Button.State; }
set { Button.State = (Microsoft.Office.Core.MsoButtonState)value; }
set { if (!IsWrappingNullReference) Button.State = (Microsoft.Office.Core.MsoButtonState)value; }
}

public ButtonStyle Style
{
get { return IsWrappingNullReference ? 0 : (ButtonStyle)Button.Style; }
set { Button.Style = (Microsoft.Office.Core.MsoButtonStyle)value; }
set { if (!IsWrappingNullReference) Button.Style = (Microsoft.Office.Core.MsoButtonStyle)value; }
}

public Image Picture { get; set; }
public Image Mask { get; set; }

public void ApplyIcon()
{
if (IsWrappingNullReference) return;

Button.FaceId = 0;
if (Picture == null || Mask == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public CommandBarControl(Microsoft.Office.Core.CommandBarControl target)
public bool BeginsGroup
{
get { return !IsWrappingNullReference && Target.BeginGroup; }
set { Target.BeginGroup = value; }
set { if (!IsWrappingNullReference) Target.BeginGroup = value; }
}

public bool IsBuiltIn
Expand All @@ -25,25 +25,25 @@ public bool IsBuiltIn
public string Caption
{
get { return IsWrappingNullReference ? string.Empty : Target.Caption; }
set { Target.Caption = value; }
set { if (!IsWrappingNullReference) Target.Caption = value; }
}

public string DescriptionText
{
get { return IsWrappingNullReference ? string.Empty : Target.DescriptionText; }
set { Target.DescriptionText = value; }
set { if (!IsWrappingNullReference) Target.DescriptionText = value; }
}

public bool IsEnabled
{
get { return !IsWrappingNullReference && Target.Enabled; }
set { Target.Enabled = value; }
set { if (!IsWrappingNullReference) Target.Enabled = value; }
}

public int Height
{
get { return Target.Height; }
set { Target.Height = value; }
set { if (!IsWrappingNullReference) Target.Height = value; }
}

public int Id
Expand All @@ -64,7 +64,7 @@ public int Left
public string OnAction
{
get { return IsWrappingNullReference ? string.Empty : Target.OnAction; }
set { Target.OnAction = value; }
set { if (!IsWrappingNullReference) Target.OnAction = value; }
}

public ICommandBar Parent
Expand All @@ -75,25 +75,25 @@ public ICommandBar Parent
public string Parameter
{
get { return IsWrappingNullReference ? string.Empty : Target.Parameter; }
set { Target.Parameter = value; }
set { if (!IsWrappingNullReference) Target.Parameter = value; }
}

public int Priority
{
get { return IsWrappingNullReference ? 0 : Target.Priority; }
set { Target.Priority = value; }
set { if (!IsWrappingNullReference) Target.Priority = value; }
}

public string Tag
{
get { return Target.Tag; }
set { Target.Tag = value; }
set { if (!IsWrappingNullReference) Target.Tag = value; }
}

public string TooltipText
{
get { return IsWrappingNullReference ? string.Empty : Target.TooltipText; }
set { Target.TooltipText = value; }
set { if (!IsWrappingNullReference) Target.TooltipText = value; }
}

public int Top
Expand All @@ -109,28 +109,28 @@ public ControlType Type
public bool IsVisible
{
get { return !IsWrappingNullReference && Target.Visible; }
set { Target.Visible = value; }
set { if (!IsWrappingNullReference) Target.Visible = value; }
}

public int Width
{
get { return IsWrappingNullReference ? 0 : Target.Width; }
set { Target.Width = value; }
set { if (!IsWrappingNullReference) Target.Width = value; }
}

public bool IsPriorityDropped
{
get { return Target.IsPriorityDropped; }
get { return (!IsWrappingNullReference) && Target.IsPriorityDropped; }
}

public void Delete()
{
Target.Delete(true);
if (!IsWrappingNullReference) Target.Delete(true);
}

public void Execute()
{
Target.Execute();
if (!IsWrappingNullReference) Target.Execute();
}

public override bool Equals(ISafeComWrapper<Microsoft.Office.Core.CommandBarControl> other)
Expand Down
Loading