image_view: Pass model to update_action_state()

Due to the latest refactoring passes, it was possible
for the model to be borrowed twice when navigating
to a file. This commit makes model an argument
to update_action_state() so we don't need to acquire
another borrow. We have the model already in all cases
where we use update_action_state().
This commit is contained in:
Christopher Davis 2022-06-29 18:45:45 -04:00
parent ddb02d0eb7
commit e8511bf5d5

View file

@ -191,7 +191,7 @@ impl LpImageView {
imp.filename.replace(util::get_file_display_name(file)); imp.filename.replace(util::get_file_display_name(file));
carousel.append(&LpImagePage::from_file(file)); carousel.append(&LpImagePage::from_file(file));
self.fill_carousel(model, index); self.fill_carousel(model, index);
self.update_action_state(index); self.update_action_state(model, index);
} }
} }
@ -243,7 +243,7 @@ impl LpImageView {
// Clear everything on either side, then refill // Clear everything on either side, then refill
self.clear_carousel(true); self.clear_carousel(true);
self.fill_carousel(model, new_index); self.fill_carousel(model, new_index);
self.update_action_state(new_index); self.update_action_state(model, new_index);
drop(guard); drop(guard);
} }
@ -290,11 +290,7 @@ impl LpImageView {
} }
} }
pub fn update_action_state(&self, index: u32) { pub fn update_action_state(&self, model: &LpFileModel, index: u32) {
let imp = self.imp();
let b = imp.model.borrow();
let model = b.as_ref().unwrap();
let next_enabled = model.item(index + 1).is_some(); let next_enabled = model.item(index + 1).is_some();
let prev_enabled = index.checked_sub(1).and_then(|i| model.item(i)).is_some(); let prev_enabled = index.checked_sub(1).and_then(|i| model.item(i)).is_some();
@ -315,7 +311,7 @@ impl LpImageView {
if model_index != prev_index { if model_index != prev_index {
imp.filename.replace(util::get_file_display_name(&current)); imp.filename.replace(util::get_file_display_name(&current));
self.notify("filename"); self.notify("filename");
self.update_action_state(model_index); self.update_action_state(model, model_index);
// We've moved forward // We've moved forward
if let Some(diff) = model_index.checked_sub(prev_index) { if let Some(diff) = model_index.checked_sub(prev_index) {