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
13 changes: 13 additions & 0 deletions src/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,17 @@ impl SSHConnection {
Err("SFTP subsystem not initialized.".to_string())
}
}

pub fn create_file(&self, path: &str) -> Result<(), String> {
if let Some(sftp) = &self.sftp {
let mut file = sftp
.create(Path::new(path))
.map_err(|e| format!("Failed to create file: {}", e))?;
file.write_all(b"")
.map_err(|e| format!("Failed to initialize file: {}", e))?;
Ok(())
} else {
Err("SFTP subsystem not initialized.".to_string())
}
}
}
31 changes: 31 additions & 0 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct UIState {
pub renaming_file: Option<String>,
pub new_name: String,
pub new_directory_name: String,
pub new_file_name: String,
}

impl Default for UIState {
Expand All @@ -41,6 +42,7 @@ impl Default for UIState {
renaming_file: None,
new_name: String::new(),
new_directory_name: String::new(),
new_file_name: String::new(),
}
}
}
Expand Down Expand Up @@ -196,6 +198,35 @@ pub fn render_ui(ui: &mut egui::Ui, state: &mut UIState, connection: &mut Option
}
});

ui.horizontal(|ui| {
ui.label("Create File:");
ui.text_edit_singleline(&mut state.new_file_name);
if ui.button("Create").clicked() {
if !state.new_file_name.is_empty() {
if let Some(conn) = connection {
let full_path = format!("{}/{}", state.current_path, state.new_file_name);
match conn.create_file(&full_path) {
Ok(_) => {
state.error_message =
Some("File created successfully.".to_string());
state.new_file_name.clear();

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 file: {}", e));
}
}
}
} else {
state.error_message = Some("File 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