minor bug

This commit is contained in:
2025-09-05 00:25:02 -05:00
parent ddf5c377f6
commit d526cac08a
3 changed files with 22 additions and 6 deletions
+10 -2
View File
@@ -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()
}
}
+7 -4
View File
@@ -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
}
+5
View File
@@ -22,6 +22,7 @@ impl UiExtensions for Ui {
pub trait ButtonExtensions<'a> {
fn red(atoms: impl IntoAtoms<'a>) -> Self;
fn green(text: impl Into<String>) -> Self;
fn blue(text: impl Into<String>) -> Self;
}
impl<'a> ButtonExtensions<'a> for Button<'a> {
@@ -32,4 +33,8 @@ impl<'a> ButtonExtensions<'a> for Button<'a> {
fn green(text: impl Into<String>) -> Self {
Self::new(RichText::new(text).color(Color32::WHITE)).fill(Color32::DARK_GREEN)
}
fn blue(text: impl Into<String>) -> Self {
Self::new(RichText::new(text).color(Color32::WHITE)).fill(Color32::DARK_BLUE)
}
}