Skip to content

Commit 902be51

Browse files
committed
Close #840
1 parent 783a448 commit 902be51

File tree

7 files changed

+71
-2
lines changed

7 files changed

+71
-2
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
3131
_state.ModuleStateChanged += ParserState_ModuleStateChanged;
3232

3333
_refreshCommand = commands.OfType<CodeExplorer_RefreshCommand>().FirstOrDefault();
34+
_refreshComponentCommand = commands.OfType<CodeExplorer_RefreshComponentCommand>().FirstOrDefault();
3435
_navigateCommand = commands.OfType<CodeExplorer_NavigateCommand>().FirstOrDefault();
3536

3637
_addTestModuleCommand = commands.OfType<CodeExplorer_AddTestModuleCommand>().FirstOrDefault();
@@ -311,6 +312,9 @@ private void RemoveFailingComponent(CodeExplorerItemViewModel itemNode, string c
311312
private readonly ICommand _refreshCommand;
312313
public ICommand RefreshCommand { get { return _refreshCommand; } }
313314

315+
private readonly ICommand _refreshComponentCommand;
316+
public ICommand RefreshComponentCommand { get { return _refreshComponentCommand; } }
317+
314318
private readonly ICommand _navigateCommand;
315319
public ICommand NavigateCommand { get { return _navigateCommand; } }
316320

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@
385385
</Compile>
386386
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_CommitCommand.cs" />
387387
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_AddUserFormCommand.cs" />
388+
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_RefreshComponentCommand.cs" />
388389
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_RenameCommand.cs" />
389390
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_FindAllReferencesCommand.cs" />
390391
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_FindAllImplementationsCommand.cs" />

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
<Setter Property="ContextMenu">
146146
<Setter.Value>
147147
<ContextMenu DataContext="{Binding DataContext, Source={x:Reference CodeExplorer}}">
148+
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_RefreshComponent}"
149+
Command="{Binding RefreshComponentCommand}"
150+
CommandParameter="{Binding SelectedItem}"/>
148151
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Navigate}"
149152
FontWeight="Bold"
150153
Command="{Binding NavigateCommand}"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Rubberduck.Navigation.CodeExplorer;
2+
using Rubberduck.Parsing.VBA;
3+
using Rubberduck.UI.Command;
4+
5+
namespace Rubberduck.UI.CodeExplorer.Commands
6+
{
7+
public class CodeExplorer_RefreshComponentCommand : CommandBase
8+
{
9+
private readonly RubberduckParserState _state;
10+
11+
public CodeExplorer_RefreshComponentCommand(RubberduckParserState state)
12+
{
13+
_state = state;
14+
}
15+
16+
public override bool CanExecute(object parameter)
17+
{
18+
var node = parameter as CodeExplorerComponentViewModel;
19+
20+
return node != null && node.QualifiedSelection.HasValue &&
21+
_state.GetModuleState(node.QualifiedSelection.Value.QualifiedName.Component) == ParserState.Pending;
22+
}
23+
24+
public override void Execute(object parameter)
25+
{
26+
var node = (CodeExplorerComponentViewModel) parameter;
27+
28+
// ReSharper disable once PossibleInvalidOperationException - CanExecute ensures it has a value
29+
_state.OnParseRequested(this, node.QualifiedSelection.Value.QualifiedName.Component);
30+
}
31+
}
32+
}

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

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

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,4 +1566,7 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
15661566
<data name="NoIndentAnnotation" xml:space="preserve">
15671567
<value>Add '@NoIndent</value>
15681568
</data>
1569+
<data name="CodeExplorer_RefreshComponent" xml:space="preserve">
1570+
<value>Refresh component</value>
1571+
</data>
15691572
</root>

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,24 @@ private ParserState EvaluateParserState()
269269

270270
public ParserState GetModuleState(VBComponent component)
271271
{
272-
return _moduleStates.GetOrAdd(new QualifiedModuleName(component), ParserState.Pending);
272+
var key = new QualifiedModuleName(component);
273+
274+
var isDirty = IsNewOrModified(key);
275+
var state = _moduleStates.GetOrAdd(key, ParserState.Pending);
276+
277+
if (!isDirty)
278+
{
279+
return state;
280+
}
281+
282+
if (state == ParserState.Pending)
283+
{
284+
return state; // we are slated for a reparse already
285+
}
286+
287+
_moduleStates.TryUpdate(key, ParserState.Pending, state);
288+
289+
return ParserState.Pending;
273290
}
274291

275292
private ParserState _status;

0 commit comments

Comments
 (0)