@@ -16,8 +16,8 @@ use std::str::Split;
1616use std:: sync:: Arc ;
1717
1818/// contains all states of the app.
19- /// It's not like the [crate:: AsmServer] which only contains the information of a file.
20- /// App will exists even no file opened. (no [crate:: AsmServer] exists)
19+ /// It's not like the [AsmServer] which only contains the information of a file.
20+ /// App will exists even no file opened. (no [AsmServer] exists)
2121#[ derive( Default , Clone , Debug ) ]
2222pub struct App {
2323 pub top : Arc < Mutex < Top > > ,
@@ -29,6 +29,7 @@ pub struct App {
2929#[ derive( Clone , Debug ) ]
3030pub enum UIMessage {
3131 OpenFile ( OpenFileMessage ) ,
32+ CloseDir ( StrRef ) ,
3233}
3334
3435#[ derive( Clone , Debug ) ]
@@ -61,6 +62,9 @@ impl AppContainer {
6162 UIMessage :: OpenFile ( message) => {
6263 server. switch_or_open ( & message. path , self ) ;
6364 }
65+ UIMessage :: CloseDir ( path) => {
66+ server. close_dir ( & path, self ) ;
67+ }
6468 }
6569 }
6670 }
@@ -99,6 +103,7 @@ pub struct RawDirInfo {
99103 pub opened : bool ,
100104 pub level : u16 ,
101105 pub title : StrRef ,
106+ pub dir_key : StrRef ,
102107}
103108
104109pub type DirMap = BTreeMap < StrRef , DirInfo > ;
@@ -124,8 +129,14 @@ fn visible_items<'a, 'b>(dir_info: &'b mut DirInfo, container: &'a mut Vec<FileE
124129}
125130
126131impl DirInfo {
127- pub fn from_classes ( title : StrRef , class_names : & [ StrRef ] ) -> Self {
128- let mut root_node = DirInfo { raw : RawDirInfo { title, ..Default :: default ( ) } , ..Default :: default ( ) } ;
132+ pub fn from_classes ( class_names : & [ StrRef ] ) -> Self {
133+ let root_raw_dir = RawDirInfo {
134+ title : Arc :: from ( "Root" ) ,
135+ dir_key : Arc :: from ( "" ) ,
136+ level : 0 ,
137+ opened : true ,
138+ } ;
139+ let mut root_node = DirInfo { raw : root_raw_dir, ..Default :: default ( ) } ;
129140 for class_name in class_names {
130141 root_node. put_entry_if_absent ( class_name. clone ( ) ) ;
131142 }
@@ -170,7 +181,7 @@ impl DirInfo {
170181 }
171182
172183 fn entry_parts ( path : & str ) -> Peekable < Enumerate < Split < char > > > {
173- path[ 1 .. ( path . len ( ) - 1 ) ] . split ( '/' ) . enumerate ( ) . peekable ( )
184+ path. split ( '/' ) . enumerate ( ) . peekable ( )
174185 }
175186
176187 fn put_file_if_absent ( & mut self , level : u16 , file_key : StrRef , file_name : StrRef ) -> & mut FileInfo {
@@ -182,8 +193,16 @@ impl DirInfo {
182193
183194 fn put_dir_if_absent ( & mut self , level : u16 , folder_name : StrRef ) -> & mut DirInfo {
184195 let title = folder_name. clone ( ) ;
185- self . dirs . entry ( folder_name) . or_insert_with ( || {
186- let raw = RawDirInfo { title, level, ..Default :: default ( ) } ;
196+ let parent_dir_key = & self . raw . dir_key ;
197+ let dir_key: StrRef ;
198+ if parent_dir_key. is_empty ( ) {
199+ // direct n
200+ dir_key = folder_name. into ( ) ;
201+ } else {
202+ dir_key = format ! ( "{}/{}" , parent_dir_key, folder_name) . into ( ) ;
203+ }
204+ self . dirs . entry ( title. clone ( ) ) . or_insert_with ( || {
205+ let raw = RawDirInfo { title, level, dir_key, ..Default :: default ( ) } ;
187206 DirInfo { raw, ..Default :: default ( ) }
188207 } )
189208 }
0 commit comments