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

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