mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
always replace mime type on file change
This commit is contained in:
parent
5fcb90133f
commit
8004f51c70
1 changed files with 21 additions and 43 deletions
|
|
@ -61,52 +61,30 @@ impl File {
|
||||||
this.set_label("Buffering, please wait.."); // @TODO progress
|
this.set_label("Buffering, please wait.."); // @TODO progress
|
||||||
file.load_bytes_async(Cancellable::NONE, {
|
file.load_bytes_async(Cancellable::NONE, {
|
||||||
let file = file.clone();
|
let file = file.clone();
|
||||||
move |result| {
|
move |result| match result {
|
||||||
match result {
|
Ok((bytes, _)) => file.query_info_async(
|
||||||
Ok((bytes, _)) => {
|
|
||||||
// try autocomplete content type (if None)
|
|
||||||
if header.borrow().mime.is_none() {
|
|
||||||
file.query_info_async(
|
|
||||||
"standard::content-type",
|
"standard::content-type",
|
||||||
FileQueryInfoFlags::NONE,
|
FileQueryInfoFlags::NONE,
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
Cancellable::NONE,
|
Cancellable::NONE,
|
||||||
move |file_info| {
|
move |file_info| {
|
||||||
if let Ok(file_info) = file_info {
|
header.borrow_mut().mime = match file_info {
|
||||||
header.borrow_mut().mime =
|
Ok(file_info) => file_info.content_type(),
|
||||||
file_info.content_type();
|
Err(_) => None,
|
||||||
}
|
};
|
||||||
// async operations completed, unlock the form
|
|
||||||
// * @TODO make shared function for members below?
|
|
||||||
control.update(
|
|
||||||
Some(bytes.len()),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
buffer.replace(Some(bytes));
|
|
||||||
this.set_css_classes(&[CLASS.2]);
|
|
||||||
this.set_label(
|
|
||||||
path.to_str().unwrap(),
|
|
||||||
);
|
|
||||||
this.set_sensitive(true);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
// no async operations left, update/unlock immediately
|
|
||||||
} else {
|
|
||||||
control.update(Some(bytes.len()), None);
|
control.update(Some(bytes.len()), None);
|
||||||
buffer.replace(Some(bytes));
|
buffer.replace(Some(bytes));
|
||||||
|
|
||||||
this.set_css_classes(&[CLASS.2]);
|
this.set_css_classes(&[CLASS.2]);
|
||||||
this.set_label(path.to_str().unwrap());
|
this.set_label(path.to_str().unwrap());
|
||||||
this.set_sensitive(true);
|
this.set_sensitive(true);
|
||||||
}
|
},
|
||||||
}
|
),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
this.set_css_classes(&[CLASS.0]);
|
this.set_css_classes(&[CLASS.0]);
|
||||||
this.set_label(e.message());
|
this.set_label(e.message());
|
||||||
this.set_sensitive(true);
|
this.set_sensitive(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
None => todo!(),
|
None => todo!(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue