@@ -13,37 +13,29 @@ namespace QuickNavigate.Forms
1313{
1414 public sealed partial class OpenRecentProjectsForm : Form
1515 {
16+ [ NotNull ] readonly Settings settings ;
1617 [ NotNull ] [ ItemNotNull ] readonly List < string > recentProjects = ProjectManager . PluginMain . Settings . RecentProjects . Where ( File . Exists ) . ToList ( ) ;
1718
1819 public OpenRecentProjectsForm ( [ NotNull ] Settings settings )
1920 {
21+ this . settings = settings ;
22+ Font = PluginBase . Settings . DefaultFont ;
2023 InitializeComponent ( ) ;
24+ if ( settings . RecentProjectsSize . Width > MinimumSize . Width ) Size = settings . RecentProjectsSize ;
2125 InitializeTree ( ) ;
26+ InitializeContextMenu ( ) ;
2227 InitializeTheme ( ) ;
23- Settings = settings ;
28+ openInNewWindow . Visible = PluginBase . MainForm . MultiInstanceMode ;
2429 RefrestTree ( ) ;
2530 }
2631
32+ [ CanBeNull ] ContextMenuStrip contextMenu ;
33+
2734 public bool InNewWindow { get ; private set ; }
2835
2936 [ CanBeNull ]
30- public string SelectedItem => tree ? . SelectedNode . Text ;
31-
32- [ NotNull ] Settings settings ;
33-
34- [ NotNull ]
35- public Settings Settings
36- {
37- get { return settings ; }
38- set
39- {
40- settings = value ;
41- if ( settings . RecentProjectsSize . Width > MinimumSize . Width ) Size = settings . RecentProjectsSize ;
42- Font = PluginBase . Settings . DefaultFont ;
43- openInNewWindow . Visible = PluginBase . MainForm . MultiInstanceMode ;
44- }
45- }
46-
37+ public string SelectedItem => tree . SelectedNode ? . Text ;
38+
4739 void InitializeTree ( )
4840 {
4941 tree . ImageList = new ImageList
@@ -55,6 +47,15 @@ void InitializeTree()
5547 tree . ItemHeight = tree . ImageList . ImageSize . Height ;
5648 }
5749
50+ void InitializeContextMenu ( )
51+ {
52+ if ( ! PluginBase . MainForm . MultiInstanceMode ) return ;
53+ input . ContextMenu = new ContextMenu ( ) ;
54+ contextMenu = new ContextMenuStrip { Renderer = new DockPanelStripRenderer ( false ) } ;
55+ contextMenu . Items . Add ( "Open in new Window" ) . Click += ( s , args ) => NavigateInNewWindow ( ) ;
56+ contextMenu . Items [ 0 ] . Select ( ) ;
57+ }
58+
5859 void InitializeTheme ( )
5960 {
6061 input . BackColor = PluginBase . MainForm . GetThemeColor ( "TextBox.BackColor" , SystemColors . Window ) ;
@@ -105,6 +106,21 @@ void Navigate()
105106 DialogResult = DialogResult . OK ;
106107 }
107108
109+ void NavigateInNewWindow ( )
110+ {
111+ InNewWindow = SelectedItem != null ;
112+ Navigate ( ) ;
113+ }
114+
115+ void ShowContextMenu ( )
116+ {
117+ var selectedNode = tree . SelectedNode ;
118+ if ( selectedNode == null ) return ;
119+ ShowContextMenu ( new Point ( selectedNode . Bounds . X , selectedNode . Bounds . Bottom ) ) ;
120+ }
121+
122+ void ShowContextMenu ( [ NotNull ] Point position ) => contextMenu ? . Show ( tree , position ) ;
123+
108124 protected override void OnKeyDown ( KeyEventArgs e )
109125 {
110126 switch ( e . KeyCode )
@@ -120,6 +136,10 @@ protected override void OnKeyDown(KeyEventArgs e)
120136 input . SelectAll ( ) ;
121137 }
122138 break ;
139+ case Keys . Apps :
140+ e . Handled = true ;
141+ ShowContextMenu ( ) ;
142+ break ;
123143 }
124144 }
125145
@@ -188,10 +208,6 @@ void OnTreeDrawNode(object sender, DrawTreeNodeEventArgs e)
188208 graphics . DrawString ( $ "({ path } )", font , moduleBrush , x , bounds . Top , StringFormat . GenericDefault ) ;
189209 }
190210
191- void OnOpenInNewWindowClick ( object sender , EventArgs e )
192- {
193- InNewWindow = SelectedItem != null ;
194- Navigate ( ) ;
195- }
211+ void OnOpenInNewWindowClick ( object sender , EventArgs e ) => NavigateInNewWindow ( ) ;
196212 }
197213}
0 commit comments