Skip to content

Commit cf3149c

Browse files
author
SlavaRa
committed
closes #138
1 parent 2f34fd5 commit cf3149c

File tree

5 files changed

+143
-92
lines changed

5 files changed

+143
-92
lines changed

QuickNavigate/Forms/ClassHierarchyForm.cs

Lines changed: 11 additions & 9 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
{
@@ -163,7 +164,7 @@ TreeNode GetPrevEnabledNode()
163164
}
164165

165166
[CanBeNull]
166-
TreeNode GetUpEnabledNode()
167+
TreeNode GetFirstEnabledNode()
167168
{
168169
TreeNode result = null;
169170
var node = tree.SelectedNode;
@@ -197,8 +198,12 @@ protected override void ShowContextMenu()
197198
protected override void ShowContextMenu(Point position)
198199
{
199200
if (SelectedNode == null) return;
200-
ContextMenuStrip.Items[2].Enabled = !curClass.Equals(SelectedNode.Model);
201-
ContextMenuStrip.Items[4].Enabled = File.Exists(SelectedNode.Model.InFile.FileName);
201+
ContextMenuStrip.Items.Clear();
202+
ContextMenuStrip.Items.Add(QuickContextMenu.GotoPositionOrLineMenuItem);
203+
ContextMenuStrip.Items.Add(QuickContextMenu.ShowInQuickOutlineMenuItem);
204+
if (!curClass.Equals(SelectedNode.Model)) ContextMenuStrip.Items.Add(QuickContextMenu.ShowInClassHierarchyMenuItem);
205+
ContextMenuStrip.Items.Add(QuickContextMenu.ShowInProjectManagerMenuItem);
206+
if (File.Exists(SelectedNode.Model.InFile.FileName)) ContextMenuStrip.Items.Add(QuickContextMenu.ShowInFileExplorerMenuItem);
202207
ContextMenuStrip.Show(tree, position);
203208
}
204209

@@ -234,10 +239,7 @@ protected override void OnKeyDown(KeyEventArgs e)
234239
}
235240
}
236241

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

242244
protected override void OnTreeNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
243245
{
@@ -309,7 +311,7 @@ void OnInputKeyDown(object sender, KeyEventArgs e)
309311
if (node != null) tree.SelectedNode = node;
310312
else if (PluginBase.MainForm.Settings.WrapList)
311313
{
312-
node = GetUpEnabledNode();
314+
node = GetFirstEnabledNode();
313315
if (node != null) tree.SelectedNode = node;
314316
}
315317
break;
@@ -323,7 +325,7 @@ void OnInputKeyDown(object sender, KeyEventArgs e)
323325
}
324326
break;
325327
case Keys.Home:
326-
node = GetUpEnabledNode();
328+
node = GetFirstEnabledNode();
327329
if (node != null) tree.SelectedNode = node;
328330
break;
329331
case Keys.End:

QuickNavigate/Forms/ClassModelExplorerForm.cs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Windows.Forms;
66
using ASCompletion.Model;
77
using JetBrains.Annotations;
8-
using PluginCore;
8+
using QuickNavigate.Helpers;
99

1010
namespace QuickNavigate.Forms
1111
{
@@ -36,29 +36,14 @@ protected override void Dispose(bool disposing)
3636
base.Dispose(disposing);
3737
}
3838

39-
protected void InitializeContextMenu()
39+
protected virtual void InitializeContextMenu()
4040
{
4141
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-
});
42+
QuickContextMenu.GotoPositionOrLineMenuItem.Click += OnGotoLineOrPosition;
43+
QuickContextMenu.ShowInQuickOutlineMenuItem.Click += OnShowInQuickOutline;
44+
QuickContextMenu.ShowInClassHierarchyMenuItem.Click += OnShowInClassHierarchy;
45+
QuickContextMenu.ShowInProjectManagerMenuItem.Click += OnShowInProjectManager;
46+
QuickContextMenu.ShowInFileExplorerMenuItem.Click += OnShowInFileExplorer;
6247
}
6348

6449
protected virtual void Navigate()

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+
[CanBeNull] public 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)