@@ -20,6 +20,7 @@ pub struct UIState {
2020 pub file_content : String ,
2121 pub renaming_file : Option < String > ,
2222 pub new_name : String ,
23+ pub new_directory_name : String ,
2324}
2425
2526impl Default for UIState {
@@ -39,6 +40,7 @@ impl Default for UIState {
3940 file_content : String :: new ( ) ,
4041 renaming_file : None ,
4142 new_name : String :: new ( ) ,
43+ new_directory_name : String :: new ( ) ,
4244 }
4345 }
4446}
@@ -163,6 +165,37 @@ pub fn render_ui(ui: &mut egui::Ui, state: &mut UIState, connection: &mut Option
163165 }
164166 } ) ;
165167
168+ ui. horizontal ( |ui| {
169+ ui. label ( "Create Directory:" ) ;
170+ ui. text_edit_singleline ( & mut state. new_directory_name ) ;
171+ if ui. button ( "Create" ) . clicked ( ) {
172+ if !state. new_directory_name . is_empty ( ) {
173+ if let Some ( conn) = connection {
174+ let full_path =
175+ format ! ( "{}/{}" , state. current_path, state. new_directory_name) ;
176+ match conn. create_directory ( & full_path) {
177+ Ok ( _) => {
178+ state. error_message =
179+ Some ( "Directory created successfully." . to_string ( ) ) ;
180+ state. new_directory_name . clear ( ) ; // Clear the input field &&
181+ // Refresh directory listing
182+ match conn. list_directory ( & state. current_path ) {
183+ Ok ( files) => state. files = files,
184+ Err ( e) => state. error_message = Some ( e) ,
185+ }
186+ }
187+ Err ( e) => {
188+ state. error_message =
189+ Some ( format ! ( "Failed to create directory: {}" , e) ) ;
190+ }
191+ }
192+ }
193+ } else {
194+ state. error_message = Some ( "Directory name cannot be empty." . to_string ( ) ) ;
195+ }
196+ }
197+ } ) ;
198+
166199 ui. horizontal ( |ui| {
167200 if ui. button ( "Up" ) . clicked ( ) {
168201 if let Some ( pos) = state. current_path . rfind ( '/' ) {
0 commit comments