window: Add Home/End shortcuts for first/last img

This is the same as in EOG.
Also add PageUp/Down for image navigation from EOG.
Cleanup the navigation enums as well.
This commit is contained in:
Sophie Herold 2023-02-06 19:14:01 +01:00
parent 169dd454cc
commit 69889820cd
6 changed files with 65 additions and 13 deletions

View file

@ -21,6 +21,7 @@ use crate::deps::*;
use crate::file_model::LpFileModel;
use crate::i18n::*;
use crate::thumbnail::Thumbnail;
use crate::util::{Direction, Position};
use crate::widgets::{LpImage, LpImagePage, LpSlidingView};
use adw::prelude::*;
@ -270,12 +271,11 @@ impl LpImageView {
}
/// Move forward or backwards
pub fn navigate(&self, direction: adw::NavigationDirection) {
pub fn navigate(&self, direction: Direction) {
if let Some(current_path) = self.current_path() {
let new_path = match direction {
adw::NavigationDirection::Forward => self.model().after(&current_path),
adw::NavigationDirection::Back => self.model().before(&current_path),
_ => unimplemented!("Navigation direction should only be back or forward."),
Direction::Forward => self.model().after(&current_path),
Direction::Back => self.model().before(&current_path),
};
if let Some(new_path) = new_path {
@ -284,6 +284,18 @@ impl LpImageView {
}
}
/// Jump to position
pub fn jump(&self, position: Position) {
let new_path = match position {
Position::First => self.model().first(),
Position::Last => self.model().last(),
};
if let Some(new_path) = new_path {
self.navigate_to_path(&new_path);
}
}
/// Used for drag and drop
fn navigate_to_path(&self, new_path: &Path) {
let sliding_view = self.sliding_view();