chore(example): Support special filenames in open-dialog example
This commit is contained in:
parent
b15ae66ac8
commit
23bb4a122f
1 changed files with 7 additions and 4 deletions
|
|
@ -114,17 +114,20 @@ impl cosmic::Application for App {
|
||||||
return cosmic::command::future(async move {
|
return cosmic::command::future(async move {
|
||||||
// Check if its a valid local file path.
|
// Check if its a valid local file path.
|
||||||
let path = match url.scheme() {
|
let path = match url.scheme() {
|
||||||
"file" => url.path(),
|
"file" => url.to_file_path().unwrap(),
|
||||||
other => {
|
other => {
|
||||||
return Message::Error(format!("{url} has unknown scheme: {other}"));
|
return Message::Error(format!("{url} has unknown scheme: {other}"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Open the file by its path.
|
// Open the file by its path.
|
||||||
let mut file = match tokio::fs::File::open(path).await {
|
let mut file = match tokio::fs::File::open(&path).await {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(why) => {
|
Err(why) => {
|
||||||
return Message::Error(format!("failed to open {path}: {why}"));
|
return Message::Error(format!(
|
||||||
|
"failed to open {}: {why}",
|
||||||
|
path.display()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -132,7 +135,7 @@ impl cosmic::Application for App {
|
||||||
contents.clear();
|
contents.clear();
|
||||||
|
|
||||||
if let Err(why) = file.read_to_string(&mut contents).await {
|
if let Err(why) = file.read_to_string(&mut contents).await {
|
||||||
return Message::Error(format!("failed to read {path}: {why}"));
|
return Message::Error(format!("failed to read {}: {why}", path.display()));
|
||||||
}
|
}
|
||||||
|
|
||||||
contents.shrink_to_fit();
|
contents.shrink_to_fit();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue