diff --git a/src/fleen_app.rs b/src/fleen_app.rs index 4937b64..1ccd5ee 100644 --- a/src/fleen_app.rs +++ b/src/fleen_app.rs @@ -125,6 +125,10 @@ impl FleenApp { Some(s) => PathBuf::from(s), None => self.root.clone() }; + if matches!(file_type, FileType::Dir) { + while target.is_file() { target.pop(); } + } + target.push(name); if target.exists() { return Err(FleenError::FileExists(target)) @@ -139,8 +143,8 @@ impl FleenApp { }; match file_type { - FileType::File => std::fs::write(target.clone(), contents), - FileType::Dir => std::fs::create_dir(target.clone()) + FileType::File => fs::write(target.clone(), contents), + FileType::Dir => fs::create_dir(target.clone()) }.map_err(|err| FleenError::FileCreate(target.clone(), err.to_string()))?; self.refresh_file_cache(true); @@ -173,4 +177,8 @@ impl FleenApp { pub fn root_path(&self) -> String { self.root.to_string_lossy().to_string() } + + pub fn image_dir_exists(&self) -> bool { + self.root.join("images").is_dir() + } } diff --git a/src/main.rs b/src/main.rs index ac403f1..52068fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,9 +54,7 @@ impl FleenUi { let title = egui::Label::new(RichText::new("Select a site to manage").size(20.0)); ui.vertical_centered(|ui| ui.add(title)); - let open_btn = Button::new("Open site..."); - let new_btn = Button::new("New site..."); - if ui.add_fill_width(open_btn).clicked() && let Some(path) = rfd::FileDialog::new().pick_folder() { + if ui.add_fill_width(Button::blue("Open site...")).clicked() && let Some(path) = rfd::FileDialog::new().pick_folder() { match FleenApp::open(path.clone()) { Ok(app) => { self.app = Some(app); @@ -65,7 +63,7 @@ impl FleenUi { } } - if ui.add_fill_width(new_btn).clicked() && let Some(path) = rfd::FileDialog::new().pick_folder() { + if ui.add_fill_width(Button::green("New site...")).clicked() && let Some(path) = rfd::FileDialog::new().pick_folder() { match FleenApp::create(path.clone()) { Ok(app) => { self.app = Some(app); @@ -159,6 +157,11 @@ impl FleenUi { } } + ui.add_enabled_ui(self.app.as_ref().unwrap().image_dir_exists(), |ui| { + if ui.add_fill_width(Button::blue("Image from clipboard")).clicked() { + + } + }); just_clicked } diff --git a/src/ui_ext.rs b/src/ui_ext.rs index 5228a58..6afe04d 100644 --- a/src/ui_ext.rs +++ b/src/ui_ext.rs @@ -22,6 +22,7 @@ impl UiExtensions for Ui { pub trait ButtonExtensions<'a> { fn red(atoms: impl IntoAtoms<'a>) -> Self; fn green(text: impl Into) -> Self; + fn blue(text: impl Into) -> Self; } impl<'a> ButtonExtensions<'a> for Button<'a> { @@ -32,4 +33,8 @@ impl<'a> ButtonExtensions<'a> for Button<'a> { fn green(text: impl Into) -> Self { Self::new(RichText::new(text).color(Color32::WHITE)).fill(Color32::DARK_GREEN) } + + fn blue(text: impl Into) -> Self { + Self::new(RichText::new(text).color(Color32::WHITE)).fill(Color32::DARK_BLUE) + } } \ No newline at end of file