Implement clippy fixes

This commit is contained in:
Julian Mutter 2023-10-10 08:18:21 +02:00
parent 0c1260e6fc
commit f8c9cfe8f6
2 changed files with 8 additions and 10 deletions

View File

@ -22,10 +22,9 @@ fn main() {
let app = Application::builder().application_id(APP_ID).build();
app.connect_activate(move |app| {
let myui = build_ui(&app);
match cli.file.as_ref() {
Some(file) => ui::load_document(file, Rc::clone(&myui)),
None => {}
let myui = build_ui(app);
if let Some(file) = cli.file.as_ref() {
ui::load_document(file, Rc::clone(&myui));
}
});
@ -33,6 +32,5 @@ fn main() {
}
fn build_ui(app: &Application) -> Rc<RefCell<Ui>> {
let ui = Ui::build(app);
ui
Ui::build(app)
}

View File

@ -1,4 +1,4 @@
use std::{cell::RefCell, path::PathBuf, rc::Rc};
use std::{cell::RefCell, path::Path, rc::Rc};
use cairo::{Context, Format, ImageSurface};
use gtk4::{
@ -190,17 +190,17 @@ fn choose_file(ui: Rc<RefCell<Ui>>, window: &ApplicationWindow) {
filechooser.connect_response(move |d, response| {
if response == ResponseType::Accept {
let path = d.file().unwrap().path().unwrap();
load_document(&path, Rc::clone(&ui));
load_document(path, Rc::clone(&ui));
}
d.destroy();
});
filechooser.show()
}
pub fn load_document(file: &PathBuf, ui: Rc<RefCell<Ui>>) {
pub fn load_document(file: impl AsRef<Path>, ui: Rc<RefCell<Ui>>) {
println!("Loading file...");
// TODO: catch errors, maybe show error dialog
let uri = format!("file://{}", file.to_str().unwrap());
let uri = format!("file://{}", file.as_ref().to_str().unwrap());
let document_canvas = DocumentCanvas::new(poppler::Document::from_file(&uri, None).unwrap());
ui.borrow_mut().document_canvas = Some(document_canvas);