Make new file/folder an operation
This commit is contained in:
parent
f31f8a0559
commit
01a2e13e56
2 changed files with 40 additions and 15 deletions
15
src/app.rs
15
src/app.rs
|
|
@ -654,17 +654,11 @@ impl Application for App {
|
||||||
match dialog_page {
|
match dialog_page {
|
||||||
DialogPage::NewItem { parent, name, dir } => {
|
DialogPage::NewItem { parent, name, dir } => {
|
||||||
let path = parent.join(name);
|
let path = parent.join(name);
|
||||||
match if dir {
|
self.operation(if dir {
|
||||||
fs::create_dir(&path)
|
Operation::NewFolder { path }
|
||||||
} else {
|
} else {
|
||||||
fs::File::create(&path).map(|_| ())
|
Operation::NewFile { path }
|
||||||
} {
|
});
|
||||||
Ok(()) => {}
|
|
||||||
Err(err) => {
|
|
||||||
//TODO: dialog
|
|
||||||
log::warn!("failed to create {:?}: {}", path, err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -762,6 +756,7 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
Message::PendingError(id, err) => {
|
Message::PendingError(id, err) => {
|
||||||
if let Some((op, _)) = self.pending_operations.remove(&id) {
|
if let Some((op, _)) = self.pending_operations.remove(&id) {
|
||||||
|
//TODO: dialog?
|
||||||
self.failed_operations.insert(id, (op, err));
|
self.failed_operations.insert(id, (op, err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use cosmic::iced::futures::{channel::mpsc, SinkExt};
|
use cosmic::iced::futures::{channel::mpsc, SinkExt};
|
||||||
use std::path::PathBuf;
|
use std::{fs, path::PathBuf};
|
||||||
|
|
||||||
use crate::app::Message;
|
use crate::app::Message;
|
||||||
|
|
||||||
|
|
@ -10,13 +10,29 @@ fn err_str<T: ToString>(err: T) -> String {
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||||
pub enum Operation {
|
pub enum Operation {
|
||||||
/// Copy items
|
/// Copy items
|
||||||
Copy { paths: Vec<PathBuf>, to: PathBuf },
|
Copy {
|
||||||
|
paths: Vec<PathBuf>,
|
||||||
|
to: PathBuf,
|
||||||
|
},
|
||||||
/// Move items to the trash
|
/// Move items to the trash
|
||||||
Delete { paths: Vec<PathBuf> },
|
Delete {
|
||||||
|
paths: Vec<PathBuf>,
|
||||||
|
},
|
||||||
/// Move items
|
/// Move items
|
||||||
Move { paths: Vec<PathBuf>, to: PathBuf },
|
Move {
|
||||||
|
paths: Vec<PathBuf>,
|
||||||
|
to: PathBuf,
|
||||||
|
},
|
||||||
|
NewFile {
|
||||||
|
path: PathBuf,
|
||||||
|
},
|
||||||
|
NewFolder {
|
||||||
|
path: PathBuf,
|
||||||
|
},
|
||||||
/// Restore a path from the trash
|
/// Restore a path from the trash
|
||||||
Restore { paths: Vec<trash::TrashItem> },
|
Restore {
|
||||||
|
paths: Vec<trash::TrashItem>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Operation {
|
impl Operation {
|
||||||
|
|
@ -44,6 +60,20 @@ impl Operation {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Self::NewFolder { path } => {
|
||||||
|
tokio::task::spawn_blocking(|| fs::create_dir(path))
|
||||||
|
.await
|
||||||
|
.map_err(err_str)?
|
||||||
|
.map_err(err_str)?;
|
||||||
|
let _ = msg_tx.send(Message::PendingProgress(id, 100.0)).await;
|
||||||
|
}
|
||||||
|
Self::NewFile { path } => {
|
||||||
|
tokio::task::spawn_blocking(|| fs::File::create(path))
|
||||||
|
.await
|
||||||
|
.map_err(err_str)?
|
||||||
|
.map_err(err_str)?;
|
||||||
|
let _ = msg_tx.send(Message::PendingProgress(id, 100.0)).await;
|
||||||
|
}
|
||||||
Self::Restore { paths } => {
|
Self::Restore { paths } => {
|
||||||
let total = paths.len();
|
let total = paths.len();
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue