Skip to content

Commit 837ae9f

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into extractMethodRefactoring_Testing
2 parents 63a633f + be38cf2 commit 837ae9f

15 files changed

+127
-231
lines changed

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private ParseTreeResults GetParseTreeResults(RubberduckParserState state)
104104
{
105105
var result = new ParseTreeResults();
106106

107-
foreach (var componentTreePair in state.ParseTrees.Where(kvp => kvp.Value != null))
107+
foreach (var componentTreePair in state.ParseTrees)
108108
{
109109
/*
110110
Need to reinitialize these for each and every ParseTree we process, since the results are aggregated in the instances themselves

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,25 @@ private bool ContainsBuiltinDocumentPropertiesProperty()
9797
}
9898

9999
private bool _isErrorState;
100-
public bool IsErrorState { get { return _isErrorState; } set { _isErrorState = value; OnPropertyChanged(); } }
100+
public bool IsErrorState
101+
{
102+
get { return _isErrorState; }
103+
set
104+
{
105+
_isErrorState = value;
106+
_icon = GetImageSource(resx.Error);
107+
108+
109+
foreach (var item in Items)
110+
{
111+
((CodeExplorerMemberViewModel) item).ParentComponentHasError();
112+
}
113+
114+
OnPropertyChanged();
115+
OnPropertyChanged("CollapsedIcon");
116+
OnPropertyChanged("ExpandedIcon");
117+
}
118+
}
101119

102120
public bool IsTestModule
103121
{
@@ -149,7 +167,7 @@ private DeclarationType DeclarationType
149167
{ DeclarationType.Document, GetImageSource(resx.document_office) }
150168
};
151169

152-
private readonly BitmapImage _icon;
170+
private BitmapImage _icon;
153171
public override BitmapImage CollapsedIcon { get { return _icon; } }
154172
public override BitmapImage ExpandedIcon { get { return _icon; } }
155173
}

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerErrorNodeViewModel.cs

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

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerItemViewModel.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewMod
5757
return nodeComparison;
5858
}
5959

60-
// error nodes have the same sort value
61-
if (x is CodeExplorerErrorNodeViewModel &&
62-
y is CodeExplorerErrorNodeViewModel)
63-
{
64-
return 0;
65-
}
66-
6760
var xNode = (ICodeExplorerDeclarationViewModel)x;
6861
var yNode = (ICodeExplorerDeclarationViewModel)y;
6962

@@ -153,13 +146,6 @@ public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewMod
153146
return string.CompareOrdinal(x.NameWithSignature, y.NameWithSignature);
154147
}
155148

156-
// error nodes come after folders
157-
if (x is CodeExplorerErrorNodeViewModel ^
158-
y is CodeExplorerErrorNodeViewModel)
159-
{
160-
return x is CodeExplorerErrorNodeViewModel ? -1 : 1;
161-
}
162-
163149
return 0;
164150
}
165151
}

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerMemberViewModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ private static string DetermineMemberName(Declaration declaration)
146146
}
147147
}
148148

149-
private readonly BitmapImage _icon;
149+
public void ParentComponentHasError()
150+
{
151+
_icon = GetImageSource(resx.Warning);
152+
OnPropertyChanged("CollapsedIcon");
153+
OnPropertyChanged("ExpandedIcon");
154+
}
155+
156+
private BitmapImage _icon;
150157
public override BitmapImage CollapsedIcon { get { return _icon; } }
151158
public override BitmapImage ExpandedIcon { get { return _icon; } }
152159
}

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
using System.Collections.ObjectModel;
44
using System.Linq;
55
using System.Windows.Input;
6-
using System.Windows.Threading;
76
using Microsoft.Vbe.Interop;
87
using Rubberduck.Navigation.Folders;
8+
using Rubberduck.Parsing.Annotations;
99
using Rubberduck.Parsing.Symbols;
1010
using Rubberduck.Parsing.VBA;
1111
using Rubberduck.UI;
1212
using Rubberduck.UI.CodeExplorer.Commands;
1313
using Rubberduck.UI.Command;
14+
using Rubberduck.UI.Command.MenuItems;
15+
using Rubberduck.VBEditor;
1416

1517
// ReSharper disable CanBeReplacedWithTryCastAndCheckForNull
1618

@@ -20,12 +22,9 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
2022
{
2123
private readonly FolderHelper _folderHelper;
2224
private readonly RubberduckParserState _state;
23-
private readonly Dispatcher _dispatcher;
2425

2526
public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState state, List<ICommand> commands)
2627
{
27-
_dispatcher = Dispatcher.CurrentDispatcher;
28-
2928
_folderHelper = folderHelper;
3029
_state = state;
3130
_state.StateChanged += ParserState_StateChanged;
@@ -217,11 +216,6 @@ public string Description
217216
return ((CodeExplorerCustomFolderViewModel) SelectedItem).FolderAttribute;
218217
}
219218

220-
if (SelectedItem is CodeExplorerErrorNodeViewModel)
221-
{
222-
return ((CodeExplorerErrorNodeViewModel) SelectedItem).Name;
223-
}
224-
225219
return string.Empty;
226220
}
227221
}
@@ -267,9 +261,6 @@ private void ParserState_StateChanged(object sender, EventArgs e)
267261
return;
268262
}
269263

270-
271-
var components = userDeclarations.SelectMany(s => s.Key.VBComponents.Cast<VBComponent>()).FirstOrDefault(s => s.Name == "asdf");
272-
273264
var newProjects = userDeclarations.Select(grouping =>
274265
new CodeExplorerProjectViewModel(_folderHelper,
275266
grouping.SingleOrDefault(declaration => declaration.DeclarationType == DeclarationType.Project),
@@ -322,36 +313,60 @@ private void ParserState_ModuleStateChanged(object sender, Parsing.ParseProgress
322313
}
323314

324315
var componentProject = e.Component.Collection.Parent;
325-
var node = Projects.OfType<CodeExplorerProjectViewModel>()
316+
var projectNode = Projects.OfType<CodeExplorerProjectViewModel>()
326317
.FirstOrDefault(p => p.Declaration.Project == componentProject);
327318

328-
if (node == null)
319+
if (projectNode == null)
329320
{
330321
return;
331322
}
332323

333-
var folderNode = node.Items.First(f => f is CodeExplorerCustomFolderViewModel && f.Name == node.Name);
324+
SetErrorState(projectNode, e.Component);
334325

335-
AddErrorNode addNode = AddComponentErrorNode;
336-
_dispatcher.BeginInvoke(addNode, node, folderNode, e.Component.Name);
337-
}
326+
if (_errorStateSet) { return; }
338327

339-
private delegate void AddErrorNode(CodeExplorerItemViewModel projectNode, CodeExplorerItemViewModel folderNode, string componentName);
340-
private void AddComponentErrorNode(CodeExplorerItemViewModel projectNode, CodeExplorerItemViewModel folderNode,
341-
string componentName)
342-
{
343-
Projects.Remove(projectNode);
344-
RemoveFailingComponent(projectNode, componentName);
328+
// at this point, we know the node is newly added--we have to add a new node, not just change the icon of the old one.
345329

346-
folderNode.AddChild(new CodeExplorerErrorNodeViewModel(folderNode, componentName));
347-
Projects.Add(projectNode);
330+
var folderNode = projectNode.Items.FirstOrDefault(f => f is CodeExplorerCustomFolderViewModel && f.Name == componentProject.Name);
348331

349-
if (SortByName)
332+
UiDispatcher.Invoke(() =>
350333
{
351-
// this setter does not ensure the values are the same
352-
// it also sorts the projects by name
334+
if (folderNode == null)
335+
{
336+
folderNode = new CodeExplorerCustomFolderViewModel(projectNode, componentProject.Name,
337+
componentProject.Name);
338+
projectNode.AddChild(folderNode);
339+
}
340+
341+
var declaration = CreateDeclaration(e.Component);
342+
var newNode = new CodeExplorerComponentViewModel(folderNode, declaration, new List<Declaration>())
343+
{
344+
IsErrorState = true
345+
};
346+
347+
folderNode.AddChild(newNode);
348+
349+
// Force a refresh. OnPropertyChanged("Projects") didn't work.
353350
Projects = Projects;
351+
});
352+
}
353+
354+
private Declaration CreateDeclaration(VBComponent component)
355+
{
356+
var projectDeclaration =
357+
_state.AllUserDeclarations.FirstOrDefault(item =>
358+
item.DeclarationType == DeclarationType.Project &&
359+
item.Project.VBComponents.Cast<VBComponent>().Contains(component));
360+
361+
if (component.Type == vbext_ComponentType.vbext_ct_StdModule)
362+
{
363+
return new ProceduralModuleDeclaration(
364+
new QualifiedMemberName(new QualifiedModuleName(component), component.Name), projectDeclaration,
365+
component.Name, false, new List<IAnnotation>(), null);
354366
}
367+
368+
return new ClassModuleDeclaration(new QualifiedMemberName(new QualifiedModuleName(component), component.Name),
369+
projectDeclaration, component.Name, false, new List<IAnnotation>(), null);
355370
}
356371

357372
private void ReorderChildNodes(IEnumerable<CodeExplorerItemViewModel> nodes)
@@ -363,30 +378,30 @@ private void ReorderChildNodes(IEnumerable<CodeExplorerItemViewModel> nodes)
363378
}
364379
}
365380

366-
private bool _removedNode;
367-
private void RemoveFailingComponent(CodeExplorerItemViewModel itemNode, string componentName)
381+
private bool _errorStateSet;
382+
private void SetErrorState(CodeExplorerItemViewModel itemNode, VBComponent component)
368383
{
384+
_errorStateSet = false;
385+
369386
foreach (var node in itemNode.Items)
370387
{
371388
if (node is CodeExplorerCustomFolderViewModel)
372389
{
373-
RemoveFailingComponent(node, componentName);
390+
SetErrorState(node, component);
374391
}
375392

376-
if (_removedNode)
393+
if (_errorStateSet)
377394
{
378395
return;
379396
}
380397

381398
if (node is CodeExplorerComponentViewModel)
382399
{
383-
var component = (CodeExplorerComponentViewModel) node;
384-
if (component.Name == componentName)
400+
var componentNode = (CodeExplorerComponentViewModel) node;
401+
if (componentNode.GetSelectedDeclaration().QualifiedName.QualifiedModuleName.Component == component)
385402
{
386-
itemNode.Items.Remove(node);
387-
_removedNode = true;
388-
389-
return;
403+
componentNode.IsErrorState = true;
404+
_errorStateSet = true;
390405
}
391406
}
392407
}

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@
369369
<Compile Include="Inspections\MakeSingleLineParameterQuickFix.cs" />
370370
<Compile Include="Inspections\ObjectVariableNotSetInspection.cs" />
371371
<Compile Include="Inspections\RemoveExplicitCallStatmentQuickFix.cs" />
372-
<Compile Include="Navigation\CodeExplorer\CodeExplorerErrorNodeViewModel.cs" />
373372
<Compile Include="Navigation\CodeExplorer\ICodeExplorerDeclarationViewModel.cs" />
374373
<Compile Include="Navigation\Folders\FolderHelper.cs" />
375374
<Compile Include="Refactorings\ExtractMethod\ExtractedMethod.cs" />

RetailCoder.VBE/UI/CodeExplorer/CodeExplorer.Designer.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/CodeExplorer/CodeExplorer.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,7 @@
256256
<data name="Error" type="System.Resources.ResXFileRef, System.Windows.Forms">
257257
<value>..\..\Resources\cross-circle.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
258258
</data>
259-
</root>
259+
<data name="Warning" type="System.Resources.ResXFileRef, System.Windows.Forms">
260+
<value>..\..\Resources\exclamation.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
261+
</data>
262+
</root>

RetailCoder.VBE/UI/CodeExplorer/Commands/CodeExplorer_FindAllReferencesCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public CodeExplorer_FindAllReferencesCommand(RubberduckParserState state, FindAl
1717

1818
public override bool CanExecute(object parameter)
1919
{
20-
return _state.Status == ParserState.Ready && !(parameter is CodeExplorerCustomFolderViewModel) &&
21-
!(parameter is CodeExplorerErrorNodeViewModel);
20+
return _state.Status == ParserState.Ready && !(parameter is CodeExplorerCustomFolderViewModel);
2221
}
2322

2423
public override void Execute(object parameter)

0 commit comments

Comments
 (0)