Skip to content

Commit a4883f5

Browse files
author
SlavaRa
committed
Merge branch 'feature/138' into develop
2 parents 2f34fd5 + 4959ba2 commit a4883f5

File tree

5 files changed

+154
-111
lines changed

5 files changed

+154
-111
lines changed

QuickNavigate/Forms/ClassHierarchyForm.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using ASCompletion.Model;
1010
using JetBrains.Annotations;
1111
using PluginCore;
12+
using QuickNavigate.Helpers;
1213

1314
namespace QuickNavigate.Forms
1415
{
@@ -70,8 +71,7 @@ public ClassHierarchyForm([NotNull] ClassModel model, [NotNull] Settings setting
7071
RefreshTree();
7172
}
7273

73-
[CanBeNull]
74-
public TypeNode SelectedNode => tree.SelectedNode as TypeNode;
74+
public override TypeNode SelectedNode => tree.SelectedNode as TypeNode;
7575

7676
void InitializeTree()
7777
{
@@ -163,7 +163,7 @@ TreeNode GetPrevEnabledNode()
163163
}
164164

165165
[CanBeNull]
166-
TreeNode GetUpEnabledNode()
166+
TreeNode GetFirstEnabledNode()
167167
{
168168
TreeNode result = null;
169169
var node = tree.SelectedNode;
@@ -197,8 +197,12 @@ protected override void ShowContextMenu()
197197
protected override void ShowContextMenu(Point position)
198198
{
199199
if (SelectedNode == null) return;
200-
ContextMenuStrip.Items[2].Enabled = !curClass.Equals(SelectedNode.Model);
201-
ContextMenuStrip.Items[4].Enabled = File.Exists(SelectedNode.Model.InFile.FileName);
200+
ContextMenuStrip.Items.Clear();
201+
ContextMenuStrip.Items.Add(QuickContextMenu.GotoPositionOrLineMenuItem);
202+
ContextMenuStrip.Items.Add(QuickContextMenu.ShowInQuickOutlineMenuItem);
203+
if (!curClass.Equals(SelectedNode.Model)) ContextMenuStrip.Items.Add(QuickContextMenu.ShowInClassHierarchyMenuItem);
204+
ContextMenuStrip.Items.Add(QuickContextMenu.ShowInProjectManagerMenuItem);
205+
if (File.Exists(SelectedNode.Model.InFile.FileName)) ContextMenuStrip.Items.Add(QuickContextMenu.ShowInFileExplorerMenuItem);
202206
ContextMenuStrip.Show(tree, position);
203207
}
204208

@@ -234,10 +238,7 @@ protected override void OnKeyDown(KeyEventArgs e)
234238
}
235239
}
236240

237-
protected override void OnFormClosing(FormClosingEventArgs e)
238-
{
239-
Settings.HierarchyExplorerSize = Size;
240-
}
241+
protected override void OnFormClosing(FormClosingEventArgs e) => Settings.HierarchyExplorerSize = Size;
241242

242243
protected override void OnTreeNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
243244
{
@@ -309,7 +310,7 @@ void OnInputKeyDown(object sender, KeyEventArgs e)
309310
if (node != null) tree.SelectedNode = node;
310311
else if (PluginBase.MainForm.Settings.WrapList)
311312
{
312-
node = GetUpEnabledNode();
313+
node = GetFirstEnabledNode();
313314
if (node != null) tree.SelectedNode = node;
314315
}
315316
break;
@@ -323,7 +324,7 @@ void OnInputKeyDown(object sender, KeyEventArgs e)
323324
}
324325
break;
325326
case Keys.Home:
326-
node = GetUpEnabledNode();
327+
node = GetFirstEnabledNode();
327328
if (node != null) tree.SelectedNode = node;
328329
break;
329330
case Keys.End:

QuickNavigate/Forms/ClassModelExplorerForm.cs

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
22
using System.Diagnostics;
33
using System.Drawing;
4-
using System.Linq;
54
using System.Windows.Forms;
65
using ASCompletion.Model;
76
using JetBrains.Annotations;
8-
using PluginCore;
7+
using QuickNavigate.Helpers;
98

109
namespace QuickNavigate.Forms
1110
{
@@ -27,6 +26,8 @@ public ClassModelExplorerForm([NotNull] Settings settings)
2726
InitializeContextMenu();
2827
}
2928

29+
[CanBeNull] public virtual TypeNode SelectedNode => null;
30+
3031
protected override void Dispose(bool disposing)
3132
{
3233
if (disposing)
@@ -36,29 +37,14 @@ protected override void Dispose(bool disposing)
3637
base.Dispose(disposing);
3738
}
3839

39-
protected void InitializeContextMenu()
40+
protected virtual void InitializeContextMenu()
4041
{
4142
ContextMenuStrip = new ContextMenuStrip {Renderer = new DockPanelStripRenderer(false)};
42-
ContextMenuStrip.Items.Add(new ToolStripMenuItem("&Goto Position Or Line", PluginBase.MainForm.FindImage("67"), OnGotoLineOrPosition)
43-
{
44-
ShortcutKeyDisplayString = "G"
45-
});
46-
ContextMenuStrip.Items.Add(new ToolStripMenuItem("Show in Quick &Outline", PluginBase.MainForm.FindImage("315|16|0|0"), OnShowInQuickOutline)
47-
{
48-
ShortcutKeyDisplayString = "O"
49-
});
50-
ContextMenuStrip.Items.Add(new ToolStripMenuItem("Show in &Class Hierarchy", PluginBase.MainForm.FindImage("99|16|0|0"), OnShowInClassHierarchy)
51-
{
52-
ShortcutKeyDisplayString = "C"
53-
});
54-
ContextMenuStrip.Items.Add(new ToolStripMenuItem("Show in &Project Manager", PluginBase.MainForm.FindImage("274"), OnShowInProjectManager)
55-
{
56-
ShortcutKeyDisplayString = "P"
57-
});
58-
ContextMenuStrip.Items.Add(new ToolStripMenuItem("Show in &File Explorer", PluginBase.MainForm.FindImage("209"), OnShowInFileExplorer)
59-
{
60-
ShortcutKeyDisplayString = "F"
61-
});
43+
QuickContextMenu.GotoPositionOrLineMenuItem.Click += OnGotoLineOrPosition;
44+
QuickContextMenu.ShowInQuickOutlineMenuItem.Click += OnShowInQuickOutline;
45+
QuickContextMenu.ShowInClassHierarchyMenuItem.Click += OnShowInClassHierarchy;
46+
QuickContextMenu.ShowInProjectManagerMenuItem.Click += OnShowInProjectManager;
47+
QuickContextMenu.ShowInFileExplorerMenuItem.Click += OnShowInFileExplorer;
6248
}
6349

6450
protected virtual void Navigate()
@@ -82,41 +68,33 @@ protected virtual void ShowContextMenu(Point position)
8268
protected void OnGotoLineOrPosition(object sender, EventArgs e)
8369
{
8470
Debug.Assert(GotoPositionOrLine != null, "GotoPositionOrLine != null");
85-
GotoPositionOrLine(this, GetModelFromSelectedNode());
71+
GotoPositionOrLine(this, SelectedNode?.Model);
8672
}
8773

8874
protected void OnShowInQuickOutline(object sender, EventArgs e)
8975
{
9076
Debug.Assert(ShowInQuickOutline != null, "ShowInQuickOutline != null");
91-
ShowInQuickOutline(this, GetModelFromSelectedNode());
77+
ShowInQuickOutline(this, SelectedNode?.Model);
9278
}
9379

9480
protected void OnShowInClassHierarchy(object sender, EventArgs e)
9581
{
9682
Debug.Assert(ShowInClassHierarchy != null, "ShowInClassHierarchy != null");
97-
ShowInClassHierarchy(this, GetModelFromSelectedNode());
83+
ShowInClassHierarchy(this, SelectedNode?.Model);
9884
}
9985

10086
protected void OnShowInProjectManager(object sender, EventArgs e)
10187
{
10288
Debug.Assert(ShowInProjectManager != null, "ShowInProjectManager != null");
103-
ShowInProjectManager(this, GetModelFromSelectedNode());
89+
ShowInProjectManager(this, SelectedNode?.Model);
10490
}
10591

10692
protected void OnShowInFileExplorer(object sender, EventArgs e)
10793
{
10894
Debug.Assert(ShowInFileExplorer != null, "ShowInFileExplorer != null");
109-
ShowInFileExplorer(this, GetModelFromSelectedNode());
95+
ShowInFileExplorer(this, SelectedNode?.Model);
11096
}
11197

112-
TreeView GetTreeView()
113-
{
114-
var tree = ContextMenuStrip.SourceControl as TreeView;
115-
return tree ?? ContextMenuStrip.SourceControl.Controls.OfType<TreeView>().FirstOrDefault();
116-
}
117-
118-
ClassModel GetModelFromSelectedNode() => ((TypeNode) GetTreeView().SelectedNode).Model;
119-
12098
#region Event Handlers
12199

122100
protected virtual void OnTreeNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)

QuickNavigate/Forms/TypeExplorerForm.cs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using ASCompletion.Model;
1010
using JetBrains.Annotations;
1111
using PluginCore;
12+
using ProjectManager.Projects;
1213
using QuickNavigate.Collections;
1314
using QuickNavigate.Helpers;
1415

@@ -31,7 +32,7 @@ public sealed partial class TypeExplorerForm : ClassModelExplorerForm
3132
/// Initializes a new instance of the QuickNavigate.Controls.TypeExplorer
3233
/// </summary>
3334
/// <param name="settings"></param>
34-
public TypeExplorerForm(Settings settings) : base(settings)
35+
public TypeExplorerForm([NotNull] Settings settings) : base(settings)
3536
{
3637
Font = PluginBase.Settings.DefaultFont;
3738
InitializeComponent();
@@ -46,12 +47,10 @@ public TypeExplorerForm(Settings settings) : base(settings)
4647
timer.Start();
4748
}
4849

49-
[CanBeNull]
50-
ToolTip filterToolTip;
50+
[CanBeNull] public ShowInHandler SetDocumentClass;
51+
[CanBeNull] ToolTip filterToolTip;
52+
[CanBeNull] Button currentFilter;
5153

52-
[CanBeNull]
53-
Button currentFilter;
54-
5554
[CanBeNull]
5655
Button CurrentFilter
5756
{
@@ -79,8 +78,7 @@ Button CurrentFilter
7978
}
8079
}
8180

82-
[CanBeNull]
83-
public TypeNode SelectedNode => tree.SelectedNode as TypeNode;
81+
public override TypeNode SelectedNode => tree.SelectedNode as TypeNode;
8482

8583
protected override void Dispose(bool disposing)
8684
{
@@ -199,7 +197,7 @@ static IEnumerable<TypeNode> CreateNodes([NotNull] IEnumerable<string> matches,
199197
}
200198

201199
[NotNull]
202-
static TypeNode CreateNode(string type)
200+
static TypeNode CreateNode([NotNull] string type)
203201
{
204202
var aClass = TypeToClassModel[type];
205203
return new TypeNode(aClass, PluginUI.GetIcon(aClass.Flags, aClass.Access));
@@ -225,6 +223,12 @@ static IEnumerable<TypeNode> SortNodes([NotNull] IEnumerable<TypeNode> nodes, [N
225223
return nodes0.Concat(nodes1).Concat(nodes2);
226224
}
227225

226+
protected override void InitializeContextMenu()
227+
{
228+
base.InitializeContextMenu();
229+
QuickContextMenu.SetDocumentClassMenuItem.Click += OnSetDocumentClassMenuItemClick;
230+
}
231+
228232
protected override void ShowContextMenu()
229233
{
230234
if (SelectedNode == null) return;
@@ -234,7 +238,23 @@ protected override void ShowContextMenu()
234238
protected override void ShowContextMenu(Point position)
235239
{
236240
if (SelectedNode == null) return;
237-
ContextMenuStrip.Items[4].Enabled = File.Exists(SelectedNode.Model.InFile.FileName);
241+
ContextMenuStrip.Items.Clear();
242+
var classModel = SelectedNode.Model;
243+
var flags = classModel.Flags;
244+
var fileName = classModel.InFile.FileName;
245+
if ((flags & FlagType.Class) > 0
246+
&& (flags & FlagType.Interface) == 0
247+
&& (classModel.Access & Visibility.Public) > 0
248+
&& !((Project)PluginBase.CurrentProject).IsDocumentClass(fileName))
249+
{
250+
ContextMenuStrip.Items.Add(QuickContextMenu.SetDocumentClassMenuItem);
251+
ContextMenuStrip.Items.Add(new ToolStripSeparator());
252+
}
253+
ContextMenuStrip.Items.Add(QuickContextMenu.GotoPositionOrLineMenuItem);
254+
ContextMenuStrip.Items.Add(QuickContextMenu.ShowInQuickOutlineMenuItem);
255+
ContextMenuStrip.Items.Add(QuickContextMenu.ShowInClassHierarchyMenuItem);
256+
ContextMenuStrip.Items.Add(QuickContextMenu.ShowInProjectManagerMenuItem);
257+
if (File.Exists(fileName)) ContextMenuStrip.Items.Add(QuickContextMenu.ShowInFileExplorerMenuItem);
238258
ContextMenuStrip.Show(tree, position);
239259
}
240260

@@ -479,6 +499,8 @@ void OnTimerTick(object sender, EventArgs e)
479499
RefreshTree();
480500
}
481501

502+
void OnSetDocumentClassMenuItemClick(object sender, EventArgs e) => SetDocumentClass?.Invoke(this, SelectedNode.Model);
503+
482504
#endregion
483505
}
484506
}

QuickNavigate/Helpers/FormHelper.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
using ASCompletion.Context;
66
using JetBrains.Annotations;
77
using PluginCore;
8+
using PluginCore.Localization;
9+
using ProjectManager.Controls;
10+
using WeifenLuo.WinFormsUI.Docking;
11+
using PluginUI = ProjectManager.PluginUI;
812

913
namespace QuickNavigate.Helpers
1014
{
@@ -32,5 +36,62 @@ public static void Navigate([NotNull] string fileName, [NotNull] TreeNode node)
3236
}
3337

3438
public static void Navigate([NotNull] TreeNode node) => ASContext.Context.OnSelectOutlineNode(node);
39+
40+
public const string ProjectManagerGUID = "30018864-fadd-1122-b2a5-779832cbbf23";
41+
42+
[CanBeNull]
43+
public static ProjectManager.PluginUI GetProjectManagerPluginUI()
44+
{
45+
foreach (var pane in PluginBase.MainForm.DockPanel.Panes)
46+
{
47+
foreach (var dockContent in pane.Contents)
48+
{
49+
var content = (DockContent) dockContent;
50+
if (content?.GetPersistString() != ProjectManagerGUID) continue;
51+
foreach (var ui in content.Controls.OfType<PluginUI>())
52+
{
53+
return ui;
54+
}
55+
}
56+
}
57+
return null;
58+
}
59+
60+
[CanBeNull]
61+
public static FileExplorer.PluginUI GetFileExplorerPluginUI()
62+
{
63+
foreach (var pane in PluginBase.MainForm.DockPanel.Panes)
64+
{
65+
foreach (var dockContent in pane.Contents)
66+
{
67+
var content = (DockContent) dockContent;
68+
if (content?.GetPersistString() != "f534a520-bcc7-4fe4-a4b9-6931948b2686") continue;
69+
foreach (var ui in content.Controls.OfType<FileExplorer.PluginUI>())
70+
{
71+
return ui;
72+
}
73+
}
74+
}
75+
return null;
76+
}
77+
}
78+
79+
public class ShortcutId
80+
{
81+
public const string TypeExplorer = "QuickNavigate.TypeExplorer";
82+
public const string QuickOutline = "QuickNavigate.Outline";
83+
public const string ClassHierarchy = "QuickNavigate.ClassHierarchy";
84+
public const string RecentFiles = "QuickNavigate.RecentFiles";
85+
public const string RecentProjects = "QuickNavigate.RecentProjects";
86+
}
87+
88+
class QuickContextMenu
89+
{
90+
[NotNull] internal static ToolStripMenuItem GotoPositionOrLineMenuItem = new ToolStripMenuItem("&Goto Position Or Line", PluginBase.MainForm.FindImage("67")) { ShortcutKeyDisplayString = "G" };
91+
[NotNull] internal static ToolStripMenuItem ShowInQuickOutlineMenuItem = new ToolStripMenuItem("Show in Quick &Outline", PluginBase.MainForm.FindImage("315|16|0|0")) {ShortcutKeyDisplayString = "O"};
92+
[NotNull] internal static ToolStripMenuItem ShowInClassHierarchyMenuItem = new ToolStripMenuItem("Show in &Class Hierarchy", PluginBase.MainForm.FindImage("99|16|0|0")) { ShortcutKeyDisplayString = "C" };
93+
[NotNull] internal static ToolStripMenuItem ShowInProjectManagerMenuItem = new ToolStripMenuItem("Show in &Project Manager", PluginBase.MainForm.FindImage("274")) { ShortcutKeyDisplayString = "P" };
94+
[NotNull] internal static ToolStripMenuItem ShowInFileExplorerMenuItem = new ToolStripMenuItem("Show in &File Explorer", PluginBase.MainForm.FindImage("209")) { ShortcutKeyDisplayString = "F" };
95+
[NotNull] internal static ToolStripMenuItem SetDocumentClassMenuItem = new ToolStripMenuItem(TextHelper.GetString("ProjectManager.Label.SetDocumentClass"), Icons.DocumentClass.Img);
3596
}
3697
}

0 commit comments

Comments
 (0)