From c282743094b275ee51948dc0daa099b8edd4eee0 Mon Sep 17 00:00:00 2001 From: 0xb-s <145866191+0xb-s@users.noreply.github.com> Date: Mon, 16 Dec 2024 05:56:41 -0800 Subject: [PATCH 1/4] Update ssh.rs --- src/ssh.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ssh.rs b/src/ssh.rs index 34c8314..bfd0e00 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -192,4 +192,13 @@ impl SSHConnection { Err("SFTP session not initialized.".to_string()) } } + + pub fn create_directory(&self, path: &str) -> Result<(), String> { + if let Some(sftp) = &self.sftp { + sftp.mkdir(Path::new(path), 0o755) + .map_err(|e| format!("Failed to create directory: {}", e)) + } else { + Err("SFTP subsystem not initialized.".to_string()) + } + } } From 4acf3ae074d9ec35b38bad583e6011dc1a5d2d49 Mon Sep 17 00:00:00 2001 From: 0xb-s <145866191+0xb-s@users.noreply.github.com> Date: Mon, 16 Dec 2024 05:57:00 -0800 Subject: [PATCH 2/4] Update ui.rs --- src/ui.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/ui.rs b/src/ui.rs index 07f53c7..7b8af4b 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -20,6 +20,7 @@ pub struct UIState { pub file_content: String, pub renaming_file: Option, pub new_name: String, + pub new_directory_name: String, } impl Default for UIState { @@ -39,6 +40,7 @@ impl Default for UIState { file_content: String::new(), renaming_file: None, new_name: String::new(), + new_directory_name: String::new(), } } } @@ -163,6 +165,37 @@ pub fn render_ui(ui: &mut egui::Ui, state: &mut UIState, connection: &mut Option } }); + ui.horizontal(|ui| { + ui.label("Create Directory:"); + ui.text_edit_singleline(&mut state.new_directory_name); // Use the new field + if ui.button("Create").clicked() { + if !state.new_directory_name.is_empty() { + if let Some(conn) = connection { + let full_path = + format!("{}/{}", state.current_path, state.new_directory_name); + match conn.create_directory(&full_path) { + Ok(_) => { + state.error_message = + Some("Directory created successfully.".to_string()); + state.new_directory_name.clear(); // Clear the input field + // Refresh directory listing + match conn.list_directory(&state.current_path) { + Ok(files) => state.files = files, + Err(e) => state.error_message = Some(e), + } + } + Err(e) => { + state.error_message = + Some(format!("Failed to create directory: {}", e)); + } + } + } + } else { + state.error_message = Some("Directory name cannot be empty.".to_string()); + } + } + }); + ui.horizontal(|ui| { if ui.button("Up").clicked() { if let Some(pos) = state.current_path.rfind('/') { From 40795e7717606ae0dc5487be1a31a17423b8168b Mon Sep 17 00:00:00 2001 From: 0xb-s <145866191+0xb-s@users.noreply.github.com> Date: Mon, 16 Dec 2024 05:58:49 -0800 Subject: [PATCH 3/4] Update ui.rs --- src/ui.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 7b8af4b..992b8bf 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -167,7 +167,7 @@ pub fn render_ui(ui: &mut egui::Ui, state: &mut UIState, connection: &mut Option ui.horizontal(|ui| { ui.label("Create Directory:"); - ui.text_edit_singleline(&mut state.new_directory_name); // Use the new field + ui.text_edit_singleline(&mut state.new_directory_name); if ui.button("Create").clicked() { if !state.new_directory_name.is_empty() { if let Some(conn) = connection { @@ -177,7 +177,7 @@ pub fn render_ui(ui: &mut egui::Ui, state: &mut UIState, connection: &mut Option Ok(_) => { state.error_message = Some("Directory created successfully.".to_string()); - state.new_directory_name.clear(); // Clear the input field + state.new_directory_name.clear(); // Clear the input field && // Refresh directory listing match conn.list_directory(&state.current_path) { Ok(files) => state.files = files, From b6e5036efd537cd89da3ae16976ea11a90eae8d4 Mon Sep 17 00:00:00 2001 From: 0xb-s <145866191+0xb-s@users.noreply.github.com> Date: Mon, 16 Dec 2024 05:59:55 -0800 Subject: [PATCH 4/4] fmt --- src/ui.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui.rs b/src/ui.rs index 992b8bf..8c8e8ab 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -167,7 +167,7 @@ pub fn render_ui(ui: &mut egui::Ui, state: &mut UIState, connection: &mut Option ui.horizontal(|ui| { ui.label("Create Directory:"); - ui.text_edit_singleline(&mut state.new_directory_name); + ui.text_edit_singleline(&mut state.new_directory_name); if ui.button("Create").clicked() { if !state.new_directory_name.is_empty() { if let Some(conn) = connection {