Skip to content

Commit 1d2e55d

Browse files
committed
Merge branch 'UI'
2 parents fe6dcd0 + 8fcdf32 commit 1d2e55d

11 files changed

+108
-49
lines changed

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
<Compile Include="SourceControl\Repository.cs" />
268268
<Compile Include="UI\CodeExplorer\TreeNodeNavigateCodeEventArgs.cs" />
269269
<Compile Include="UI\CodeExplorer\TreeViewDisplayStyle.cs" />
270+
<Compile Include="UI\IdentifierReferences\IdentifierReferenceListItem.cs" />
270271
<Compile Include="UI\IdentifierReferences\IdentifierReferencesListControl.cs">
271272
<SubType>UserControl</SubType>
272273
</Compile>

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerDockablePresenter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ private void ShowDesigner(object sender, EventArgs e)
118118
var node = Control.SolutionTree.SelectedNode;
119119
if (node != null && node.Tag != null)
120120
{
121-
var selection = (QualifiedSelection)node.Tag;
122-
var module = VBE.FindCodeModules(selection.QualifiedName).FirstOrDefault();
121+
var selection = (Declaration)node.Tag;
122+
var module = VBE.FindCodeModules(selection.QualifiedName.QualifiedModuleName).FirstOrDefault();
123123
if (module == null)
124124
{
125125
return;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Rubberduck.Parsing;
2+
using Rubberduck.Parsing.Symbols;
3+
4+
namespace Rubberduck.UI.IdentifierReferences
5+
{
6+
public class IdentifierReferenceListItem
7+
{
8+
private readonly IdentifierReference _reference;
9+
10+
public IdentifierReferenceListItem(IdentifierReference reference)
11+
{
12+
_reference = reference;
13+
}
14+
15+
public QualifiedSelection Selection { get { return new QualifiedSelection(_reference.QualifiedModuleName, _reference.Selection); } }
16+
public string IdentifierName { get { return _reference.IdentifierName; } }
17+
18+
public string DisplayString
19+
{
20+
get
21+
{
22+
return string.Format("{0} - {1}, line {2}",
23+
_reference.Context.Parent.GetText(),
24+
Selection.QualifiedName.ModuleName,
25+
Selection.Selection.StartLine);
26+
}
27+
}
28+
}
29+
}

RetailCoder.VBE/UI/IdentifierReferences/IdentifierReferencesListControl.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Drawing;
5-
using System.Data;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
9-
using System.Windows.Forms;
1+
using System.Windows.Forms;
2+
using Rubberduck.Parsing.Symbols;
103

114
namespace Rubberduck.UI.IdentifierReferences
125
{
136
public partial class IdentifierReferencesListControl : UserControl, IDockableUserControl
147
{
15-
public IdentifierReferencesListControl()
8+
public IdentifierReferencesListControl(Declaration target)
169
{
1710
InitializeComponent();
11+
Target = target;
1812
}
1913

20-
public string IdentifierName { get; set; }
14+
public Declaration Target { get; private set; }
2115

2216
private const string ClassId = "972A7CE8-55A0-48F5-B607-2035E81D28CF";
2317
string IDockableUserControl.ClassId { get { return ClassId; } }
24-
string IDockableUserControl.Caption { get { return string.Format(RubberduckUI.AllReferences_Caption, IdentifierName); } }
18+
string IDockableUserControl.Caption { get { return string.Format(RubberduckUI.AllReferences_Caption, Target.IdentifierName); } }
2519
}
2620
}
Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,25 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using System.Linq;
62
using Microsoft.Vbe.Interop;
7-
using Rubberduck.Parsing;
83
using Rubberduck.Parsing.Symbols;
94

105
namespace Rubberduck.UI.IdentifierReferences
116
{
12-
public class IdentifierReferenceListItem
13-
{
14-
private readonly IdentifierReference _reference;
15-
16-
public IdentifierReferenceListItem(IdentifierReference reference)
17-
{
18-
_reference = reference;
19-
}
20-
21-
public QualifiedSelection Selection { get { return new QualifiedSelection(_reference.QualifiedModuleName, _reference.Selection); } }
22-
public string IdentifierName { get { return _reference.IdentifierName; } }
23-
}
24-
257
public class IdentifierReferencesListDockablePresenter : DockablePresenterBase
268
{
27-
public IdentifierReferencesListDockablePresenter(VBE vbe, AddIn addin, IdentifierReferencesListControl control, Declaration target)
9+
public IdentifierReferencesListDockablePresenter(VBE vbe, AddIn addin, IdentifierReferencesListControl control, Declaration target)
2810
: base(vbe, addin, control)
2911
{
30-
var listBox = ((IdentifierReferencesListControl) UserControl).ResultBox;
12+
BindTarget(target);
13+
}
3114

32-
listBox.DataSource = target.References.Select(reference => new IdentifierReferenceListItem(reference));
33-
listBox.DisplayMember = "IdentifierName";
15+
private void BindTarget(Declaration target)
16+
{
17+
var listBox = Control.ResultBox;
18+
listBox.DataSource = target.References.Select(reference => new IdentifierReferenceListItem(reference)).ToList();
19+
listBox.DisplayMember = "DisplayString";
3420
listBox.ValueMember = "Selection";
3521
}
22+
23+
IdentifierReferencesListControl Control { get { return UserControl as IdentifierReferencesListControl; } }
3624
}
3725
}

RetailCoder.VBE/UI/RefactorMenu.cs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System.Drawing;
22
using System.Linq;
3-
using Antlr4.Runtime;
43
using Microsoft.Office.Core;
54
using Microsoft.Vbe.Interop;
65
using Rubberduck.Extensions;
76
using Rubberduck.Parsing;
87
using Rubberduck.Parsing.Symbols;
98
using Rubberduck.Properties;
9+
using Rubberduck.UI.IdentifierReferences;
1010
using Rubberduck.UI.Refactorings.ExtractMethod;
1111
using Rubberduck.UI.Refactorings.Rename;
1212
using Rubberduck.VBA;
@@ -38,20 +38,62 @@ public void Initialize(CommandBarControls menuControls)
3838
InitializeRefactorContextMenu();
3939
}
4040

41+
private CommandBarPopup _refactorCodePaneContextMenu;
42+
public CommandBarPopup RefactorCodePaneContextMenu { get { return _refactorCodePaneContextMenu; } }
43+
4144
private CommandBarButton _extractMethodContextButton;
4245
private CommandBarButton _renameContextButton;
4346

4447
private void InitializeRefactorContextMenu()
4548
{
4649
var beforeItem = IDE.CommandBars["Code Window"].Controls.Cast<CommandBarControl>().First(control => control.Id == 2529).Index;
47-
var menu = IDE.CommandBars["Code Window"].Controls.Add(Type: MsoControlType.msoControlPopup, Temporary: true, Before:beforeItem) as CommandBarPopup;
48-
menu.BeginGroup = true;
49-
menu.Caption = "&Refactor";
50+
_refactorCodePaneContextMenu = IDE.CommandBars["Code Window"].Controls.Add(Type: MsoControlType.msoControlPopup, Temporary: true, Before:beforeItem) as CommandBarPopup;
51+
_refactorCodePaneContextMenu.BeginGroup = true;
52+
_refactorCodePaneContextMenu.Caption = "&Refactor";
5053

5154
var extractMethodIcon = Resources.ExtractMethod_6786_32;
5255
extractMethodIcon.MakeTransparent(Color.White);
53-
_extractMethodContextButton = AddButton(menu, "Extract &Method", false, OnExtractMethodButtonClick, extractMethodIcon);
54-
_renameContextButton = AddButton(menu, "&Rename", false, OnRenameButtonClick);
56+
_extractMethodContextButton = AddButton(_refactorCodePaneContextMenu, "Extract &Method", false, OnExtractMethodButtonClick, extractMethodIcon);
57+
_renameContextButton = AddButton(_refactorCodePaneContextMenu, "&Rename", false, OnRenameButtonClick);
58+
59+
InitializeFindReferencesContextMenu(); //todo: untangle that mess...
60+
}
61+
62+
private CommandBarButton _findAllReferencesContextMenu;
63+
private void InitializeFindReferencesContextMenu()
64+
{
65+
var beforeItem = IDE.CommandBars["Code Window"].Controls.Cast<CommandBarControl>().First(control => control.Id == 2529).Index;
66+
_findAllReferencesContextMenu = IDE.CommandBars["Code Window"].Controls.Add(Type: MsoControlType.msoControlButton, Temporary: true, Before: beforeItem) as CommandBarButton;
67+
_findAllReferencesContextMenu.Caption = "&Find all references...";
68+
_findAllReferencesContextMenu.Click += _findAllReferencesContextMenu_Click;
69+
}
70+
71+
private void _findAllReferencesContextMenu_Click(CommandBarButton Ctrl, ref bool CancelDefault)
72+
{
73+
var selection = IDE.ActiveCodePane.GetSelection();
74+
var declarations = _parser.Parse(IDE.ActiveVBProject).Declarations;
75+
76+
var target = declarations.Items
77+
.Where(item => item.DeclarationType != DeclarationType.ModuleOption)
78+
.FirstOrDefault(item => IsSelectedDeclaration(selection, item)
79+
|| IsSelectedReference(selection, item));
80+
81+
var window = new IdentifierReferencesListControl(target);
82+
var presenter = new IdentifierReferencesListDockablePresenter(IDE, AddIn, window, target);
83+
presenter.Show();
84+
}
85+
86+
private bool IsSelectedReference(QualifiedSelection selection, Declaration declaration)
87+
{
88+
return declaration.References.Any(r =>
89+
r.QualifiedModuleName == selection.QualifiedName &&
90+
r.Selection.ContainsFirstCharacter(selection.Selection));
91+
}
92+
93+
private bool IsSelectedDeclaration(QualifiedSelection selection, Declaration declaration)
94+
{
95+
return declaration.QualifiedName.QualifiedModuleName == selection.QualifiedName
96+
&& (declaration.Selection.ContainsFirstCharacter(selection.Selection));
5597
}
5698

5799
private void OnExtractMethodButtonClick(CommandBarButton Ctrl, ref bool CancelDefault)

RetailCoder.VBE/UI/Refactorings/Rename/RenamePresenter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ private void PromptIfTargetImplementsInterface(ref Declaration target)
244244

245245
private bool IsSelectedReference(QualifiedSelection selection, Declaration declaration)
246246
{
247-
return declaration.References.Any(r => r.Selection.ContainsFirstCharacter(selection.Selection));
247+
return declaration.References.Any(r =>
248+
r.QualifiedModuleName == selection.QualifiedName &&
249+
r.Selection.ContainsFirstCharacter(selection.Selection));
248250
}
249251

250252
private bool IsSelectedDeclaration(QualifiedSelection selection, Declaration declaration)

RetailCoder.VBE/UI/RubberduckMenu.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Linq;
34
using Microsoft.Office.Core;
45
using Microsoft.Vbe.Interop;
56
using Rubberduck.Config;
7+
using Rubberduck.Extensions;
68
using Rubberduck.Inspections;
7-
using Rubberduck.Parsing;
89
using Rubberduck.Parsing.Symbols;
910
using Rubberduck.UI.CodeExplorer;
1011
using Rubberduck.UI.CodeInspections;
12+
using Rubberduck.UI.IdentifierReferences;
1113
using Rubberduck.UI.Settings;
1214
using Rubberduck.UI.SourceControl;
1315
using Rubberduck.UI.ToDoItems;

RetailCoder.VBE/UI/Settings/TodoSettingPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Rubberduck.UI.Settings
55
{
66
public class TodoSettingPresenter
77
{
8-
private ITodoSettingsView _view;
8+
private readonly ITodoSettingsView _view;
99

1010
public ToDoMarker ActiveMarker
1111
{

0 commit comments

Comments
 (0)