Skip to content

Commit ae1b3d6

Browse files
authored
Merge branch 'next' into feature/Com_Reference_Explorer
2 parents 50b0618 + 8fc93ec commit ae1b3d6

26 files changed

+216
-392
lines changed

RetailCoder.VBE/API/ParserState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void Initialize(VBE vbe)
6868

6969
Func<IVBAPreprocessor> preprocessorFactory = () => new VBAPreprocessor(double.Parse(vbe.Version, CultureInfo.InvariantCulture));
7070
_attributeParser = new AttributeParser(new ModuleExporter(), preprocessorFactory);
71-
_parser = new RubberduckParser(vbe, _state, _attributeParser, preprocessorFactory,
71+
_parser = new RubberduckParser(_state, _attributeParser, preprocessorFactory,
7272
new List<ICustomDeclarationLoader> { new DebugDeclarations(_state), new FormEventDeclarations(_state) });
7373
}
7474

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,6 @@ public void Detach()
173173

174174
private void hook_MessageReceived(object sender, HookEventArgs e)
175175
{
176-
var active = User32.GetForegroundWindow();
177-
if (active != _mainWindowHandle)
178-
{
179-
return;
180-
}
181-
182176
var hotkey = sender as IHotkey;
183177
if (hotkey != null)
184178
{
@@ -207,6 +201,16 @@ private IntPtr WindowProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam)
207201
case WM.SETFOCUS:
208202
Attach();
209203
break;
204+
case WM.RUBBERDUCK_CHILD_FOCUS:
205+
if (lParam == IntPtr.Zero)
206+
{
207+
Detach();
208+
}
209+
else
210+
{
211+
Attach();
212+
}
213+
return IntPtr.Zero;
210214
case WM.NCACTIVATE:
211215
if (wParam == IntPtr.Zero)
212216
{
@@ -235,14 +239,11 @@ private bool HandleHotkeyMessage(IntPtr wParam)
235239
var processed = false;
236240
try
237241
{
238-
if (User32.IsVbeWindowActive(_mainWindowHandle))
242+
var hook = Hooks.OfType<Hotkey>().SingleOrDefault(k => k.HotkeyInfo.HookId == wParam);
243+
if (hook != null)
239244
{
240-
var hook = Hooks.OfType<Hotkey>().SingleOrDefault(k => k.HotkeyInfo.HookId == wParam);
241-
if (hook != null)
242-
{
243-
hook.OnMessageReceived();
244-
processed = true;
245-
}
245+
hook.OnMessageReceived();
246+
processed = true;
246247
}
247248
}
248249
catch (Exception exception)

RetailCoder.VBE/Common/WinAPI/User32.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ public static class User32
180180
[DllImport("user32.dll", SetLastError = true)]
181181
internal static extern bool UnregisterDeviceNotification(IntPtr handle);
182182

183+
[DllImport("user32.dll", CharSet = CharSet.Auto)]
184+
internal static extern IntPtr SendMessage(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam);
185+
183186
/// <summary>
184187
/// A helper function that returns <c>true</c> when the specified handle is that of the foreground window.
185188
/// </summary>

RetailCoder.VBE/Common/WinAPI/WM.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,11 @@ public enum WM : uint
922922
/// </summary>
923923
SYSTIMER = 0x118,
924924

925+
/// <summary>
926+
/// Private message to signal focus set/lost for a DockableWindowHost. Set wParam to the DockableWindowHost hWnd, lParam to zero for lost focus, non-zero for gained focus.
927+
/// </summary>
928+
RUBBERDUCK_CHILD_FOCUS = USER + 0x0F00,
929+
925930
/// <summary>
926931
/// The accessibility state has changed.
927932
/// </summary>

RetailCoder.VBE/Inspections/InspectionResultBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public int CompareTo(object obj)
121121
public object[] ToArray()
122122
{
123123
var module = QualifiedSelection.QualifiedName;
124-
return new object[] { Inspection.Severity.ToString(), module.ProjectTitle, module.ComponentName, Description, QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.StartColumn };
124+
return new object[] { Inspection.Severity.ToString(), module.ProjectName, module.ComponentName, Description, QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.StartColumn };
125125
}
126126

127127
public string ToCsvString()

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Linq;
5-
using System.Windows.Input;
65
using Microsoft.Vbe.Interop;
76
using NLog;
87
using Rubberduck.Navigation.Folders;
@@ -33,8 +32,7 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
3332

3433
_refreshCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param => _state.OnParseRequested(this),
3534
param => !IsBusy && _state.IsDirty());
36-
37-
_refreshComponentCommand = commands.OfType<CodeExplorer_RefreshComponentCommand>().FirstOrDefault();
35+
3836
_navigateCommand = commands.OfType<CodeExplorer_NavigateCommand>().FirstOrDefault();
3937

4038
_addTestModuleCommand = commands.OfType<CodeExplorer_AddTestModuleCommand>().FirstOrDefault();
@@ -87,17 +85,6 @@ public CodeExplorerItemViewModel SelectedItem
8785
_selectedItem = value;
8886
OnPropertyChanged();
8987

90-
if (_selectedItem is CodeExplorerProjectViewModel)
91-
{
92-
var vbe = _selectedItem.GetSelectedDeclaration().Project.VBE;
93-
var project = vbe.VBProjects.Cast<VBProject>().FirstOrDefault(f => f.HelpFile == _selectedItem.GetSelectedDeclaration().Project.HelpFile);
94-
95-
if (project != null)
96-
{
97-
vbe.ActiveVBProject = project;
98-
}
99-
}
100-
10188
// ReSharper disable ExplicitCallerInfoArgument
10289
OnPropertyChanged("CanExecuteIndenterCommand");
10390
OnPropertyChanged("CanExecuteRenameCommand");
@@ -189,25 +176,27 @@ public string PanelTitle
189176
return string.Empty;
190177
}
191178

192-
if (SelectedItem is CodeExplorerProjectViewModel)
179+
if (!(SelectedItem is ICodeExplorerDeclarationViewModel))
193180
{
194-
var node = (CodeExplorerProjectViewModel)SelectedItem;
195-
return node.Declaration.IdentifierName + string.Format(" - ({0})", node.Declaration.DeclarationType);
181+
return SelectedItem.Name;
196182
}
197183

198-
if (SelectedItem is CodeExplorerComponentViewModel)
199-
{
200-
var node = (CodeExplorerComponentViewModel)SelectedItem;
201-
return node.Declaration.IdentifierName + string.Format(" - ({0})", node.Declaration.DeclarationType);
202-
}
184+
var declaration = SelectedItem.GetSelectedDeclaration();
185+
186+
var nameWithDeclarationType = declaration.IdentifierName +
187+
string.Format(" - ({0})", RubberduckUI.ResourceManager.GetString(
188+
"DeclarationType_" + declaration.DeclarationType, UI.Settings.Settings.Culture));
203189

204-
if (SelectedItem is CodeExplorerMemberViewModel)
190+
if (string.IsNullOrEmpty(declaration.AsTypeName))
205191
{
206-
var node = (CodeExplorerMemberViewModel)SelectedItem;
207-
return node.Declaration.IdentifierName + string.Format(" - ({0})", node.Declaration.DeclarationType);
192+
return nameWithDeclarationType;
208193
}
209194

210-
return SelectedItem.Name;
195+
var typeName = declaration.HasTypeHint
196+
? Declaration.TypeHintToTypeName[declaration.TypeHint]
197+
: declaration.AsTypeName;
198+
199+
return nameWithDeclarationType + ": " + typeName;
211200
}
212201
}
213202

@@ -423,9 +412,6 @@ private void SetErrorState(CodeExplorerItemViewModel itemNode, VBComponent compo
423412
private readonly CommandBase _refreshCommand;
424413
public CommandBase RefreshCommand { get { return _refreshCommand; } }
425414

426-
private readonly CommandBase _refreshComponentCommand;
427-
public CommandBase RefreshComponentCommand { get { return _refreshComponentCommand; } }
428-
429415
private readonly CommandBase _navigateCommand;
430416
public CommandBase NavigateCommand { get { return _navigateCommand; } }
431417

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@
423423
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_AddUserFormCommand.cs" />
424424
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_CopyResultsCommand.cs" />
425425
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_OpenProjectPropertiesCommand.cs" />
426-
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_RefreshComponentCommand.cs" />
427426
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_RenameCommand.cs" />
428427
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_FindAllReferencesCommand.cs" />
429428
<Compile Include="UI\CodeExplorer\Commands\CodeExplorer_FindAllImplementationsCommand.cs" />
@@ -977,7 +976,7 @@
977976
<Compile Include="UnitTesting\AssertClass.cs" />
978977
<Compile Include="UnitTesting\AssertCompletedEventArgs.cs" />
979978
<Compile Include="UnitTesting\AssertHandler.cs" />
980-
<Compile Include="UnitTesting\UnitTestHelpers.cs" />
979+
<Compile Include="UnitTesting\UnitTestUtils.cs" />
981980
<Compile Include="UnitTesting\IAssert.cs" />
982981
<Compile Include="UnitTesting\ITestEngine.cs" />
983982
<Compile Include="UnitTesting\ITestRunner.cs" />

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,8 @@
357357
<Setter Property="ContextMenu">
358358
<Setter.Value>
359359
<ContextMenu DataContext="{Binding DataContext, Source={x:Reference CodeExplorer}}">
360-
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_RefreshComponent}"
361-
Command="{Binding RefreshComponentCommand}"
362-
CommandParameter="{Binding SelectedItem}">
360+
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Refresh}"
361+
Command="{Binding RefreshCommand}">
363362
<MenuItem.Icon>
364363
<Image Source="{StaticResource RefreshImage}" />
365364
</MenuItem.Icon>
@@ -374,7 +373,8 @@
374373
CommandParameter="{Binding SelectedItem}" />
375374
<Separator />
376375
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_OpenProjectProperties}"
377-
Command="{Binding OpenProjectPropertiesCommand}" />
376+
Command="{Binding OpenProjectPropertiesCommand}"
377+
CommandParameter="{Binding SelectedItem}" />
378378
<Separator />
379379
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Add}">
380380
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_AddTestModuleText}"
@@ -740,8 +740,8 @@
740740

741741
<Border Grid.Row="3" BorderThickness="0,1,0,0" BorderBrush="DimGray">
742742

743-
<ScrollViewer Background="WhiteSmoke" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
744-
<StackPanel Orientation="Vertical" MinHeight="48" Background="WhiteSmoke">
743+
<ScrollViewer Background="WhiteSmoke" VerticalScrollBarVisibility="Auto">
744+
<WrapPanel Orientation="Vertical" MinHeight="48" Background="WhiteSmoke">
745745

746746
<Grid Margin="4" HorizontalAlignment="Stretch">
747747
<Grid.ColumnDefinitions>
@@ -776,7 +776,7 @@
776776
CommandParameter="{Binding SelectedItem}"
777777
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_FindAllReferencesText}" />
778778
</WrapPanel>
779-
</StackPanel>
779+
</WrapPanel>
780780
</ScrollViewer>
781781
</Border>
782782
</Grid>

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System.Runtime.InteropServices;
12
using Microsoft.Vbe.Interop;
23
using NLog;
4+
using Rubberduck.Navigation.CodeExplorer;
35
using Rubberduck.UI.Command;
46

57
namespace Rubberduck.UI.CodeExplorer.Commands
@@ -13,10 +15,36 @@ public CodeExplorer_OpenProjectPropertiesCommand(VBE vbe) : base(LogManager.GetC
1315
_vbe = vbe;
1416
}
1517

18+
protected override bool CanExecuteImpl(object parameter)
19+
{
20+
return parameter != null || _vbe.VBProjects.Count == 1;
21+
}
22+
1623
protected override void ExecuteImpl(object parameter)
1724
{
1825
const int openProjectPropertiesId = 2578;
1926

27+
if (_vbe.VBProjects.Count == 1)
28+
{
29+
_vbe.CommandBars.FindControl(Id: openProjectPropertiesId).Execute();
30+
return;
31+
}
32+
33+
var node = parameter as CodeExplorerItemViewModel;
34+
while (!(node is ICodeExplorerDeclarationViewModel))
35+
{
36+
node = node.Parent; // the project node is an ICodeExplorerDeclarationViewModel--no worries here
37+
}
38+
39+
try
40+
{
41+
_vbe.ActiveVBProject = node.GetSelectedDeclaration().Project;
42+
}
43+
catch (COMException)
44+
{
45+
return; // the project was probably removed from the VBE, but not from the CE
46+
}
47+
2048
_vbe.CommandBars.FindControl(Id: openProjectPropertiesId).Execute();
2149
}
2250
}

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

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

0 commit comments

Comments
 (0)