diff --git a/src/file_model.rs b/src/file_model.rs index 2707541..12214c6 100644 --- a/src/file_model.rs +++ b/src/file_model.rs @@ -119,6 +119,11 @@ impl LpFileModel { self.imp().directory.get().cloned() } + pub fn file(&self, index: u32) -> Option { + let vec = self.imp().inner.borrow(); + vec.get(index as usize).cloned() + } + pub fn index_of(&self, file: &gio::File) -> Option { let imp = self.imp(); let vec = imp.inner.borrow(); diff --git a/src/widgets/image_view.rs b/src/widgets/image_view.rs index a25c1f5..43b9119 100644 --- a/src/widgets/image_view.rs +++ b/src/widgets/image_view.rs @@ -254,17 +254,13 @@ impl LpImageView { let carousel = imp.carousel.get(); for i in 1..=N_PAGES { - if let Some(ref file) = model.item(index + i).and_then(|o| o.downcast().ok()) { + if let Some(ref file) = model.file(index + i) { carousel.append(&LpImagePage::from_file(file)) } } for i in 1..=N_PAGES { - if let Some(ref file) = index - .checked_sub(i) - .and_then(|i| model.item(i)) - .and_then(|o| o.downcast().ok()) - { + if let Some(ref file) = index.checked_sub(i).and_then(|i| model.file(i)) { carousel.prepend(&LpImagePage::from_file(file)) } } @@ -334,9 +330,7 @@ impl LpImageView { let s = prev_index + N_PAGES + i + 1; if s <= model.n_items() { - if let Some(ref file) = - model.item(s).and_then(|o| o.downcast::().ok()) - { + if let Some(ref file) = model.file(s) { carousel.append(&LpImagePage::from_file(file)); } } @@ -354,8 +348,7 @@ impl LpImageView { if let Some(ref file) = prev_index .checked_sub(N_PAGES) .and_then(|d| d.checked_sub(i + 1)) - .and_then(|d| model.item(d)) - .and_then(|i| i.downcast::().ok()) + .and_then(|d| model.file(d)) { carousel.prepend(&LpImagePage::from_file(file)); }