Skip to content

Commit f2a2dea

Browse files
authored
Update ui.rs
1 parent 4993659 commit f2a2dea

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/ui.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct UIState {
2121
pub renaming_file: Option<String>,
2222
pub new_name: String,
2323
pub new_directory_name: String,
24+
pub new_file_name: String,
2425
}
2526

2627
impl Default for UIState {
@@ -41,6 +42,7 @@ impl Default for UIState {
4142
renaming_file: None,
4243
new_name: String::new(),
4344
new_directory_name: String::new(),
45+
new_file_name: String::new(),
4446
}
4547
}
4648
}
@@ -196,6 +198,35 @@ pub fn render_ui(ui: &mut egui::Ui, state: &mut UIState, connection: &mut Option
196198
}
197199
});
198200

201+
ui.horizontal(|ui| {
202+
ui.label("Create File:");
203+
ui.text_edit_singleline(&mut state.new_file_name);
204+
if ui.button("Create").clicked() {
205+
if !state.new_file_name.is_empty() {
206+
if let Some(conn) = connection {
207+
let full_path = format!("{}/{}", state.current_path, state.new_file_name);
208+
match conn.create_file(&full_path) {
209+
Ok(_) => {
210+
state.error_message =
211+
Some("File created successfully.".to_string());
212+
state.new_file_name.clear();
213+
214+
match conn.list_directory(&state.current_path) {
215+
Ok(files) => state.files = files,
216+
Err(e) => state.error_message = Some(e),
217+
}
218+
}
219+
Err(e) => {
220+
state.error_message = Some(format!("Failed to create file: {}", e));
221+
}
222+
}
223+
}
224+
} else {
225+
state.error_message = Some("File name cannot be empty.".to_string());
226+
}
227+
}
228+
});
229+
199230
ui.horizontal(|ui| {
200231
if ui.button("Up").clicked() {
201232
if let Some(pos) = state.current_path.rfind('/') {

0 commit comments

Comments
 (0)