Skip to content

Commit 31a8cc3

Browse files
committed
Merge branch 'next' into translationHotkeys
2 parents 54e9083 + fef0d75 commit 31a8cc3

35 files changed

+273
-128
lines changed

RetailCoder.VBE/API/ParserState.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ public void Initialize(VBE vbe)
6565
_parser = new RubberduckParser(vbe, _state, _attributeParser);
6666
}
6767

68+
/// <summary>
69+
/// Blocking call, for easier unit-test code
70+
/// </summary>
6871
public void Parse()
6972
{
7073
// blocking call
7174
_parser.Parse();
7275
}
7376

77+
/// <summary>
78+
/// Begins asynchronous parsing
79+
/// </summary>
7480
public void BeginParse()
7581
{
7682
// non-blocking call

RetailCoder.VBE/App.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public void Startup()
8484
{
8585
CleanReloadConfig();
8686

87+
foreach (var project in _vbe.VBProjects.Cast<VBProject>())
88+
{
89+
_parser.State.AddProject(project);
90+
}
91+
8792
_appMenus.Initialize();
8893
_appMenus.Localize();
8994

@@ -94,6 +99,8 @@ public void Startup()
9499
#region sink handlers. todo: move to another class
95100
async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
96101
{
102+
_parser.State.RemoveProject(e.Item);
103+
97104
Debug.WriteLine(string.Format("Project '{0}' was removed.", e.Item.Name));
98105
Tuple<IConnectionPoint, int> value;
99106
if (_componentsEventsConnectionPoints.TryGetValue(e.Item.VBComponents, out value))
@@ -107,6 +114,8 @@ async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
107114

108115
async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
109116
{
117+
_parser.State.AddProject(e.Item);
118+
110119
if (!_parser.State.AllDeclarations.Any())
111120
{
112121
// forces menus to evaluate their CanExecute state:

RetailCoder.VBE/AutoSave/AutoSave.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ private void _timer_Elapsed(object sender, ElapsedEventArgs e)
4848
{
4949
try
5050
{
51-
// note: VBProject.FileName getter throws IOException if unsaved
52-
_vbe.VBProjects.OfType<VBProject>().Select(p => p.FileName).ToList();
51+
var projects = _vbe.VBProjects.OfType<VBProject>().Select(p => p.FileName).ToList();
5352
}
54-
catch (DirectoryNotFoundException)
53+
catch (IOException)
5554
{
55+
// note: VBProject.FileName getter throws IOException if unsaved
5656
return;
5757
}
5858

RetailCoder.VBE/Common/DeclarationExtensions.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public static IEnumerable<Declaration> FindEventProcedures(this IEnumerable<Decl
354354
var handlerNames = events.Select(e => withEventsDeclaration.IdentifierName + '_' + e.IdentifierName);
355355

356356
return items.Where(item => item.Project != null
357-
&& item.Project.Equals(withEventsDeclaration.Project)
357+
&& item.ProjectName == withEventsDeclaration.ProjectName
358358
&& item.ParentScope == withEventsDeclaration.ParentScope
359359
&& item.DeclarationType == DeclarationType.Procedure
360360
&& handlerNames.Any(name => item.IdentifierName == name))
@@ -363,7 +363,7 @@ public static IEnumerable<Declaration> FindEventProcedures(this IEnumerable<Decl
363363

364364
private static IEnumerable<Declaration> GetTypeMembers(this IEnumerable<Declaration> declarations, Declaration type)
365365
{
366-
return declarations.Where(item => item.Project != null && item.Project.Equals(type.Project) && item.ParentScope == type.Scope);
366+
return declarations.Where(item => item.Project != null && item.ProjectName == type.ProjectName && item.ParentScope == type.Scope);
367367
}
368368

369369
/// <summary>
@@ -394,10 +394,18 @@ public static Declaration FindInterfaceMember(this IEnumerable<Declaration> decl
394394
var matches = members.Where(m => !m.IsBuiltIn && implementation.IdentifierName == m.ComponentName + '_' + m.IdentifierName).ToList();
395395

396396
return matches.Count > 1
397-
? matches.SingleOrDefault(m => m.Project == implementation.Project)
397+
? matches.SingleOrDefault(m => m.ProjectName == implementation.ProjectName)
398398
: matches.First();
399399
}
400400

401+
public static Declaration FindTarget(this IEnumerable<Declaration> declarations, QualifiedSelection selection)
402+
{
403+
var items = declarations.ToList();
404+
Debug.Assert(!items.Any(item => item.IsBuiltIn));
405+
406+
return items.SingleOrDefault(item => item.IsSelected(selection) || item.References.Any(reference => reference.IsSelected(selection)));
407+
}
408+
401409
/// <summary>
402410
/// Returns the declaration contained in a qualified selection.
403411
/// To get the selection of a variable or field, use FindVariable(QualifiedSelection)
@@ -412,7 +420,7 @@ public static Declaration FindTarget(this IEnumerable<Declaration> declarations,
412420

413421
var target = items
414422
.Where(item => !item.IsBuiltIn)
415-
.FirstOrDefault(item => item.IsSelected(selection)
423+
.SingleOrDefault(item => item.IsSelected(selection)
416424
|| item.References.Any(r => r.IsSelected(selection)));
417425

418426
if (target != null && validDeclarationTypes.Contains(target.DeclarationType))
@@ -531,8 +539,7 @@ public static Declaration FindInterface(this IEnumerable<Declaration> declaratio
531539
implementsStmt.GetSelection().StartColumn, reference.Selection.EndLine,
532540
reference.Selection.EndColumn);
533541

534-
if (reference.QualifiedModuleName.ComponentName == selection.QualifiedName.ComponentName &&
535-
reference.QualifiedModuleName.Project == selection.QualifiedName.Project &&
542+
if (reference.QualifiedModuleName.Equals(selection.QualifiedName) &&
536543
completeSelection.Contains(selection.Selection))
537544
{
538545
return declaration;

RetailCoder.VBE/Common/Dispatch/VBProjectsEventsSink.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@ public class VBProjectsEventsSink : _dispVBProjectsEvents
88
public event EventHandler<DispatcherEventArgs<VBProject>> ProjectAdded;
99
public void ItemAdded(VBProject VBProject)
1010
{
11-
OnDispatch(ProjectAdded, VBProject);
11+
if (VBProject.Protection == vbext_ProjectProtection.vbext_pp_none)
12+
{
13+
OnDispatch(ProjectAdded, VBProject);
14+
}
1215
}
1316

1417
public event EventHandler<DispatcherEventArgs<VBProject>> ProjectRemoved;
1518
public void ItemRemoved(VBProject VBProject)
1619
{
17-
OnDispatch(ProjectRemoved, VBProject);
20+
if (VBProject.Protection == vbext_ProjectProtection.vbext_pp_none)
21+
{
22+
OnDispatch(ProjectRemoved, VBProject);
23+
}
1824
}
1925

2026
public event EventHandler<DispatcherRenamedEventArgs<VBProject>> ProjectRenamed;
2127
public void ItemRenamed(VBProject VBProject, string OldName)
2228
{
2329
var handler = ProjectRenamed;
24-
if (handler != null)
30+
if (handler != null && VBProject.Protection == vbext_ProjectProtection.vbext_pp_none)
2531
{
2632
handler.Invoke(this, new DispatcherRenamedEventArgs<VBProject>(VBProject, OldName));
2733
}
@@ -30,7 +36,10 @@ public void ItemRenamed(VBProject VBProject, string OldName)
3036
public event EventHandler<DispatcherEventArgs<VBProject>> ProjectActivated;
3137
public void ItemActivated(VBProject VBProject)
3238
{
33-
OnDispatch(ProjectActivated, VBProject);
39+
if (VBProject.Protection == vbext_ProjectProtection.vbext_pp_none)
40+
{
41+
OnDispatch(ProjectActivated, VBProject);
42+
}
3443
}
3544

3645
private void OnDispatch(EventHandler<DispatcherEventArgs<VBProject>> dispatched, VBProject project)

RetailCoder.VBE/Common/Hotkeys/Hotkey.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ private void HookKey(Keys key, uint shift)
8383
var success = User32.RegisterHotKey(_hWndVbe, hookId, shift, (uint)key);
8484
if (!success)
8585
{
86-
throw new Win32Exception(Rubberduck.UI.RubberduckUI.CommonHotkey_KeyNotRegistered);
86+
Debug.WriteLine("Hotkey ({0}) not registered.", key);
87+
//throw new Win32Exception("HotKey was not registered.");
8788
}
8889

8990
HotkeyInfo = new HotkeyInfo(hookId, Combo);

RetailCoder.VBE/Inspections/MoveFieldCloserToUsageInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private Declaration ParentDeclaration(IdentifierReference reference)
6161

6262
return UserDeclarations.SingleOrDefault(d =>
6363
reference.ParentScoping.Equals(d) && declarationTypes.Contains(d.DeclarationType) &&
64-
d.Project == reference.QualifiedModuleName.Project);
64+
d.QualifiedName.QualifiedModuleName.Equals(reference.QualifiedModuleName));
6565
}
6666
}
6767
}

RetailCoder.VBE/Inspections/ProcedureNotUsedInspection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private bool IsPublicModuleMember(IEnumerable<Declaration> modules, Declaration
8383
return false;
8484
}
8585

86-
var parent = modules.Where(item => item.Project == procedure.Project)
86+
var parent = modules.Where(item => item.ProjectName == procedure.ProjectName)
8787
.SingleOrDefault(item => item.IdentifierName == procedure.ComponentName);
8888

8989
return parent != null;
@@ -102,7 +102,7 @@ private bool IsClassLifeCycleHandler(IEnumerable<Declaration> classes, Declarati
102102
return false;
103103
}
104104

105-
var parent = classes.Where(item => item.Project == procedure.Project)
105+
var parent = classes.Where(item => item.ProjectName == procedure.ProjectName)
106106
.SingleOrDefault(item => item.IdentifierName == procedure.ComponentName);
107107

108108
return parent != null;
@@ -118,7 +118,7 @@ private bool IsInterfaceMember(IEnumerable<Declaration> declarations, IEnumerabl
118118
{
119119
// get the procedure's parent module
120120
var enumerable = classes as IList<Declaration> ?? classes.ToList();
121-
var parent = enumerable.Where(item => item.Project == procedure.Project)
121+
var parent = enumerable.Where(item => item.ProjectName == procedure.ProjectName)
122122
.SingleOrDefault(item => item.IdentifierName == procedure.ComponentName);
123123

124124
if (parent == null)

RetailCoder.VBE/Inspections/ProcedureShouldBeFunctionInspectionResult.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ private void UpdateCalls()
122122
!d.IsBuiltIn &&
123123
d.IdentifierName == procedureName &&
124124
d.Context is VBAParser.SubStmtContext &&
125-
d.ComponentName == _subStmtQualifiedContext.ModuleName.ComponentName &&
126-
d.Project == _subStmtQualifiedContext.ModuleName.Project);
125+
d.QualifiedName.QualifiedModuleName.Equals(_subStmtQualifiedContext.ModuleName));
127126

128127
if (procedure == null) { return; }
129128

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static IEnumerable<CodeExplorerItemViewModel> FindFolders(IEnumerable<De
8383
public override BitmapImage CollapsedIcon { get { return _icon; } }
8484
public override BitmapImage ExpandedIcon { get { return _icon; } }
8585

86-
public override string Name { get { return _declaration.CustomFolder; } }
86+
public override string Name { get { return _declaration.IdentifierName; } }
8787
public override QualifiedSelection? QualifiedSelection { get { return _declaration.QualifiedSelection; } }
8888
}
8989
}

0 commit comments

Comments
 (0)