improv(display): share file dialog path handling logic
This commit is contained in:
parent
e7c9595578
commit
beaa7bd71e
1 changed files with 40 additions and 20 deletions
|
|
@ -739,18 +739,12 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::AddFolder(result) => {
|
Message::AddFolder(result) => {
|
||||||
let selection = match Arc::into_inner(result) {
|
let path = match dialog_response(result) {
|
||||||
Some(Ok(response)) => response,
|
DialogResponse::Path(path) => path,
|
||||||
Some(Err(why)) => {
|
DialogResponse::Error(why) => {
|
||||||
// TODO:
|
tracing::error!(why, "dialog response error");
|
||||||
return Command::none();
|
return Command::none();
|
||||||
}
|
}
|
||||||
None => return Command::none(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let Ok(path) = selection.to_file_path() else {
|
|
||||||
tracing::error!(path = selection.path(), "not a valid file path");
|
|
||||||
return Command::none();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
|
|
@ -778,18 +772,12 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::AddFile(result) => {
|
Message::AddFile(result) => {
|
||||||
let selection = match Arc::into_inner(result) {
|
let path = match dialog_response(result) {
|
||||||
Some(Ok(response)) => response,
|
DialogResponse::Path(path) => path,
|
||||||
Some(Err(why)) => {
|
DialogResponse::Error(why) => {
|
||||||
// TODO:
|
tracing::error!(why, "dialog response error");
|
||||||
return Command::none();
|
return Command::none();
|
||||||
}
|
}
|
||||||
None => return Command::none(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let Ok(path) = selection.to_file_path() else {
|
|
||||||
tracing::error!(path = selection.path(), "not a valid file path");
|
|
||||||
return Command::none();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if path.is_file() {
|
if path.is_file() {
|
||||||
|
|
@ -1268,3 +1256,35 @@ pub fn color_picker_view<Message: Clone + 'static>(
|
||||||
.align_items(cosmic::iced_core::Alignment::Center)
|
.align_items(cosmic::iced_core::Alignment::Center)
|
||||||
.apply(Element::from)
|
.apply(Element::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum DialogResponse {
|
||||||
|
Error(String),
|
||||||
|
Path(PathBuf),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dialog_response(result: Arc<Result<Url, file_chooser::Error>>) -> DialogResponse {
|
||||||
|
let Some(result) = Arc::into_inner(result) else {
|
||||||
|
return DialogResponse::Error(String::from("Arc::into_inner returned None"));
|
||||||
|
};
|
||||||
|
|
||||||
|
let selection = match result {
|
||||||
|
Ok(response) => response,
|
||||||
|
Err(why) => {
|
||||||
|
let mut source: &dyn std::error::Error = &why;
|
||||||
|
let mut string = format!("open dialog subscription errored\n cause: {source}");
|
||||||
|
|
||||||
|
while let Some(new_source) = source.source() {
|
||||||
|
string.push_str(&format!("\n cause: {new_source}"));
|
||||||
|
source = new_source;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DialogResponse::Error(string);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let Ok(path) = selection.to_file_path() else {
|
||||||
|
return DialogResponse::Error(format!("not a valid file path: {}", selection.path()));
|
||||||
|
};
|
||||||
|
|
||||||
|
DialogResponse::Path(path)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue