Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
33 changes: 33 additions & 0 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct UIState {
pub file_content: String,
pub renaming_file: Option<String>,
pub new_name: String,
pub new_directory_name: String,
}

impl Default for UIState {
Expand All @@ -39,6 +40,7 @@ impl Default for UIState {
file_content: String::new(),
renaming_file: None,
new_name: String::new(),
new_directory_name: String::new(),
}
}
}
Expand Down Expand Up @@ -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);
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('/') {
Expand Down
Loading