Skip to content

Commit

Permalink
🐛 Fixed adding directories
Browse files Browse the repository at this point in the history
  • Loading branch information
nwrenger committed Jul 15, 2024
1 parent cec3136 commit 13eb97e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ impl fmt::Display for Error {
match self {
Error::Arguments(e) => write!(f, "Arguments: {e}."),
Error::FileSystem(e) => write!(f, "File System Error: {e}."),
Error::Clipboard(e) => write!(f, "Clipboard: {e}. Ensure your clipboard manager is running."),
Error::Clipboard(e) => write!(
f,
"Clipboard: {e}. Ensure your clipboard manager is running."
),
}
}
}
Expand Down
24 changes: 18 additions & 6 deletions src/ui/quick_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ fn new_file(siv: &mut Cursive) -> Result<()> {
})
.unwrap();

// Should `crate_dir_all` already catch but it doesn't so checking it here.
if Path::new(&new_path).try_exists().unwrap_or(false) {
Error::FileSystem("File already exists".to_string()).to_dialog(siv);
return;
}

if let Err(e) = fs::create_dir_all(new_path) {
Into::<Error>::into(e).to_dialog(siv);
return;
Expand Down Expand Up @@ -443,7 +449,7 @@ fn rename_file(siv: &mut Cursive) -> Result<()> {
.unwrap();
let layout = LinearLayout::vertical()
.child(TextView::new(
"Note the file will be autosaved before it'll be moved/renamed!",
"Note file changes will be kept while it'll be moved/renamed!",
))
.child(TextView::new(" "))
.child(
Expand Down Expand Up @@ -526,15 +532,21 @@ fn delete_file(siv: &mut Cursive) -> Result<()> {
let state = siv
.with_user_data(|state: &mut State| state.clone())
.unwrap();
let layout = LinearLayout::vertical()
.child(TextView::new(
"Note the file/directory will be deleted recursively and without a bin in between!",
))
.child(TextView::new(" "))
.child(path_input::new(
&state.project_path,
"delete_path".to_string(),
true,
)?);
siv.add_layer(
Dialog::new()
.title("Delete")
.padding_lrtb(1, 1, 1, 0)
.content(path_input::new(
&state.project_path,
"delete_path".to_string(),
true,
)?)
.content(layout)
.button("Confirm", |siv| {
let mut state = siv
.with_user_data(|state: &mut State| state.clone())
Expand Down

0 comments on commit 13eb97e

Please sign in to comment.