Add descriptions for operations
This commit is contained in:
parent
6c2ca8acf8
commit
a4094bf75c
1 changed files with 108 additions and 1 deletions
109
src/operation.rs
109
src/operation.rs
|
|
@ -1,5 +1,6 @@
|
||||||
use cosmic::iced::futures::{channel::mpsc::Sender, executor, SinkExt};
|
use cosmic::iced::futures::{channel::mpsc::Sender, executor, SinkExt};
|
||||||
use std::{
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
fs,
|
fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::{
|
sync::{
|
||||||
|
|
@ -197,10 +198,116 @@ fn copy_unique_path(from: &Path, to: &Path) -> PathBuf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn file_name<'a>(path: &'a Path) -> Cow<'a, str> {
|
||||||
|
path.file_name()
|
||||||
|
.map_or_else(|| fl!("unknown-folder").into(), |x| x.to_string_lossy())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parent_name<'a>(path: &'a Path) -> Cow<'a, str> {
|
||||||
|
let Some(parent) = path.parent() else {
|
||||||
|
return fl!("unknown-folder").into();
|
||||||
|
};
|
||||||
|
|
||||||
|
file_name(parent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn paths_parent_name<'a>(paths: &'a Vec<PathBuf>) -> Cow<'a, str> {
|
||||||
|
let Some(first_path) = paths.first() else {
|
||||||
|
return fl!("unknown-folder").into();
|
||||||
|
};
|
||||||
|
|
||||||
|
let Some(parent) = first_path.parent() else {
|
||||||
|
return fl!("unknown-folder").into();
|
||||||
|
};
|
||||||
|
|
||||||
|
for path in paths.iter() {
|
||||||
|
//TODO: is it possible to have different parents, and what should be returned?
|
||||||
|
if path.parent() != Some(parent) {
|
||||||
|
return fl!("unknown-folder").into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file_name(parent)
|
||||||
|
}
|
||||||
|
|
||||||
impl Operation {
|
impl Operation {
|
||||||
|
pub fn pending_text(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Copy { paths, to } => fl!(
|
||||||
|
"copying",
|
||||||
|
items = paths.len(),
|
||||||
|
from = paths_parent_name(paths),
|
||||||
|
to = file_name(to)
|
||||||
|
),
|
||||||
|
Self::Delete { paths } => fl!(
|
||||||
|
"moving",
|
||||||
|
items = paths.len(),
|
||||||
|
from = paths_parent_name(paths),
|
||||||
|
to = fl!("trash")
|
||||||
|
),
|
||||||
|
Self::EmptyTrash => fl!("emptying-trash"),
|
||||||
|
Self::Move { paths, to } => fl!(
|
||||||
|
"moving",
|
||||||
|
items = paths.len(),
|
||||||
|
from = paths_parent_name(paths),
|
||||||
|
to = file_name(to)
|
||||||
|
),
|
||||||
|
Self::NewFile { path } => fl!(
|
||||||
|
"creating",
|
||||||
|
name = file_name(path),
|
||||||
|
parent = parent_name(path)
|
||||||
|
),
|
||||||
|
Self::NewFolder { path } => fl!(
|
||||||
|
"creating",
|
||||||
|
name = file_name(path),
|
||||||
|
parent = parent_name(path)
|
||||||
|
),
|
||||||
|
Self::Rename { from, to } => {
|
||||||
|
fl!("renaming", from = file_name(from), to = file_name(to))
|
||||||
|
}
|
||||||
|
Self::Restore { paths } => fl!("restoring", items = paths.len()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn completed_text(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Copy { paths, to } => fl!(
|
||||||
|
"copied",
|
||||||
|
items = paths.len(),
|
||||||
|
from = paths_parent_name(paths),
|
||||||
|
to = file_name(to)
|
||||||
|
),
|
||||||
|
Self::Delete { paths } => fl!(
|
||||||
|
"moved",
|
||||||
|
items = paths.len(),
|
||||||
|
from = paths_parent_name(paths),
|
||||||
|
to = fl!("trash")
|
||||||
|
),
|
||||||
|
Self::EmptyTrash => fl!("emptied-trash"),
|
||||||
|
Self::Move { paths, to } => fl!(
|
||||||
|
"moved",
|
||||||
|
items = paths.len(),
|
||||||
|
from = paths_parent_name(paths),
|
||||||
|
to = file_name(to)
|
||||||
|
),
|
||||||
|
Self::NewFile { path } => fl!(
|
||||||
|
"created",
|
||||||
|
name = file_name(path),
|
||||||
|
parent = parent_name(path)
|
||||||
|
),
|
||||||
|
Self::NewFolder { path } => fl!(
|
||||||
|
"created",
|
||||||
|
name = file_name(path),
|
||||||
|
parent = parent_name(path)
|
||||||
|
),
|
||||||
|
Self::Rename { from, to } => fl!("renamed", from = file_name(from), to = file_name(to)),
|
||||||
|
Self::Restore { paths } => fl!("restored", items = paths.len()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn toast(&self) -> Option<String> {
|
pub fn toast(&self) -> Option<String> {
|
||||||
match self {
|
match self {
|
||||||
Self::Delete { paths } => Some(fl!("moved-to-trash", items = paths.len())),
|
Self::Delete { paths } => Some(self.completed_text()),
|
||||||
//TODO: more toasts
|
//TODO: more toasts
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue