11using System ;
2+ using System . Collections . Generic ;
3+ using System . Drawing ;
24using System . IO ;
35using System . Linq ;
46using System . Windows . Forms ;
7+ using ASCompletion . Context ;
58using JetBrains . Annotations ;
69using PluginCore ;
10+ using PluginCore . Helpers ;
11+ using ProjectManager . Controls ;
712
813namespace QuickNavigate . Forms
914{
1015 public sealed partial class OpenRecentProjectsForm : Form
1116 {
12- [ NotNull ]
13- readonly Settings settings ;
17+ [ NotNull ] readonly Settings settings ;
18+ [ NotNull ] [ ItemNotNull ] List < string > recentProjects = ProjectManager . PluginMain . Settings . RecentProjects . Where ( File . Exists ) . ToList ( ) ;
1419
1520 public OpenRecentProjectsForm ( [ NotNull ] Settings settings )
1621 {
1722 this . settings = settings ;
1823 Font = PluginBase . Settings . DefaultFont ;
1924 InitializeComponent ( ) ;
20- tree . ItemHeight = tree . Font . Height ;
25+ InitializeTree ( ) ;
2126 if ( settings . RecentProjectsSize . Width > MinimumSize . Width ) Size = settings . RecentProjectsSize ;
2227 RefrestTree ( ) ;
2328 }
2429
25- public string SelectedItem => tree ? . SelectedItem . ToString ( ) ;
30+ [ CanBeNull ]
31+ public string SelectedItem => tree ? . SelectedNode . Text ;
32+
33+ void InitializeTree ( )
34+ {
35+ tree . ImageList = new ImageList
36+ {
37+ ColorDepth = ColorDepth . Depth32Bit ,
38+ ImageSize = ScaleHelper . Scale ( new Size ( 16 , 16 ) )
39+ } ;
40+ tree . ImageList . Images . Add ( Icons . Project . Img ) ;
41+ tree . ItemHeight = tree . ImageList . ImageSize . Height ;
42+ }
2643
2744 void RefrestTree ( )
2845 {
46+ if ( recentProjects . Count == 0 ) return ;
2947 tree . BeginUpdate ( ) ;
30- tree . Items . Clear ( ) ;
48+ tree . Nodes . Clear ( ) ;
3149 FillTree ( ) ;
32- if ( tree . Items . Count > 0 ) tree . SelectedIndex = 0 ;
50+ if ( tree . Nodes . Count > 0 ) tree . SelectedNode = tree . Nodes [ 0 ] ;
3351 else open . Enabled = false ;
3452 tree . EndUpdate ( ) ;
3553 }
3654
3755 void FillTree ( )
3856 {
39- var matches = ProjectManager . PluginMain . Settings . RecentProjects
40- . Where ( File . Exists )
41- . ToList ( ) ;
42- if ( matches . Count == 0 ) return ;
4357 var search = input . Text ;
44- if ( search . Length > 0 ) matches = SearchUtil . FindAll ( matches , search ) ;
45- if ( matches . Count > 0 ) tree . Items . AddRange ( matches . ToArray ( ) ) ;
58+ var projects = search . Length > 0 ? SearchUtil . FindAll ( recentProjects , search ) : recentProjects ;
59+ if ( projects . Count > 0 ) projects . ForEach ( it => tree . Nodes . Add ( it , it , 0 ) ) ;
4660 }
4761
4862 void Navigate ( )
@@ -78,26 +92,27 @@ protected override void OnFormClosing(FormClosingEventArgs e)
7892
7993 void OnInputKeyDown ( object sender , KeyEventArgs e )
8094 {
81- var lastIndex = tree . Items . Count - 1 ;
82- var index = tree . SelectedIndex ;
95+ if ( tree . Nodes . Count < 2 ) return ;
96+ var lastIndex = tree . Nodes . Count - 1 ;
97+ var index = tree . SelectedNode . Index ;
8398 switch ( e . KeyCode )
8499 {
85100 case Keys . L :
86101 e . Handled = e . Control ;
87102 return ;
88103 case Keys . Down :
89- if ( index < lastIndex ) tree . SetSelected ( index + 1 , true ) ;
90- else if ( settings . WrapList ) tree . SetSelected ( 0 , true ) ;
104+ if ( index < lastIndex ) tree . SelectedNode = tree . SelectedNode . NextNode ;
105+ else if ( settings . WrapList ) tree . SelectedNode = tree . Nodes [ 0 ] ;
91106 break ;
92107 case Keys . Up :
93- if ( index > 0 ) tree . SetSelected ( index - 1 , true ) ;
94- else if ( settings . WrapList ) tree . SetSelected ( lastIndex , true ) ;
108+ if ( index > 0 ) tree . SelectedNode = tree . SelectedNode . PrevNode ;
109+ else if ( settings . WrapList ) tree . SelectedNode = tree . Nodes [ lastIndex ] ;
95110 break ;
96111 case Keys . Home :
97- tree . SetSelected ( 0 , true ) ;
112+ tree . SelectedNode = tree . Nodes [ 0 ] ;
98113 break ;
99114 case Keys . End :
100- tree . SetSelected ( lastIndex , true ) ;
115+ tree . SelectedNode = tree . Nodes [ lastIndex ] ;
101116 break ;
102117 default : return ;
103118 }
@@ -106,6 +121,6 @@ void OnInputKeyDown(object sender, KeyEventArgs e)
106121
107122 void OnTreeMouseDoubleClick ( object sender , MouseEventArgs e ) => Navigate ( ) ;
108123
109- void OnTreeSelectedIndexChanged ( object sender , EventArgs e ) => open . Enabled = SelectedItem != null ;
124+ void OnTreeAfterSelect ( object sender , TreeViewEventArgs e ) => open . Enabled = SelectedItem != null ;
110125 }
111126}
0 commit comments