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:
parent
169dd454cc
commit
69889820cd
6 changed files with 65 additions and 13 deletions
|
|
@ -102,6 +102,18 @@
|
||||||
<property name="accelerator">Right</property>
|
<property name="accelerator">Right</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">First Image</property>
|
||||||
|
<property name="action-name">win.first</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Last Image</property>
|
||||||
|
<property name="action-name">win.last</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
|
|
|
||||||
|
|
@ -180,8 +180,10 @@ impl LpApplication {
|
||||||
self.set_accels_for_action("win.toggle-fullscreen", &["F11"]);
|
self.set_accels_for_action("win.toggle-fullscreen", &["F11"]);
|
||||||
self.set_accels_for_action("win.set-background", &["<Ctrl>F8"]);
|
self.set_accels_for_action("win.set-background", &["<Ctrl>F8"]);
|
||||||
|
|
||||||
self.set_accels_for_action("win.previous", &["Left"]);
|
self.set_accels_for_action("win.previous", &["Left", "Page_Down"]);
|
||||||
self.set_accels_for_action("win.next", &["Right"]);
|
self.set_accels_for_action("win.next", &["Right", "Page_Up"]);
|
||||||
|
self.set_accels_for_action("win.first", &["Home"]);
|
||||||
|
self.set_accels_for_action("win.last", &["End"]);
|
||||||
|
|
||||||
self.set_accels_for_action("win.zoom-to(1.0)", &["1", "KP_1", "<Ctrl>1", "<Ctrl>KP_1"]);
|
self.set_accels_for_action("win.zoom-to(1.0)", &["1", "KP_1", "<Ctrl>1", "<Ctrl>KP_1"]);
|
||||||
self.set_accels_for_action("win.zoom-to(2.0)", &["2", "KP_2", "<Ctrl>2", "<Ctrl>KP_2"]);
|
self.set_accels_for_action("win.zoom-to(2.0)", &["2", "KP_2", "<Ctrl>2", "<Ctrl>KP_2"]);
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,16 @@ impl LpFileModel {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return first path
|
||||||
|
pub fn first(&self) -> Option<PathBuf> {
|
||||||
|
self.imp().files.borrow().first().cloned()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns last path
|
||||||
|
pub fn last(&self) -> Option<PathBuf> {
|
||||||
|
self.imp().files.borrow().last().cloned()
|
||||||
|
}
|
||||||
|
|
||||||
/// Currently sorts by name
|
/// Currently sorts by name
|
||||||
fn sort(files: &mut IndexSet<PathBuf>) {
|
fn sort(files: &mut IndexSet<PathBuf>) {
|
||||||
files.sort_by(|x, y| util::compare_by_name(x, y));
|
files.sort_by(|x, y| util::compare_by_name(x, y));
|
||||||
|
|
|
||||||
12
src/util.rs
12
src/util.rs
|
|
@ -123,3 +123,15 @@ pub async fn spawn<T: Debug + Send + 'static>(
|
||||||
.spawn(async_global_executor::spawn_blocking(f))?
|
.spawn(async_global_executor::spawn_blocking(f))?
|
||||||
.await)
|
.await)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum Position {
|
||||||
|
First,
|
||||||
|
Last,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum Direction {
|
||||||
|
Back,
|
||||||
|
Forward,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ use crate::deps::*;
|
||||||
use crate::file_model::LpFileModel;
|
use crate::file_model::LpFileModel;
|
||||||
use crate::i18n::*;
|
use crate::i18n::*;
|
||||||
use crate::thumbnail::Thumbnail;
|
use crate::thumbnail::Thumbnail;
|
||||||
|
use crate::util::{Direction, Position};
|
||||||
use crate::widgets::{LpImage, LpImagePage, LpSlidingView};
|
use crate::widgets::{LpImage, LpImagePage, LpSlidingView};
|
||||||
|
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
|
|
@ -270,12 +271,11 @@ impl LpImageView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Move forward or backwards
|
/// 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() {
|
if let Some(current_path) = self.current_path() {
|
||||||
let new_path = match direction {
|
let new_path = match direction {
|
||||||
adw::NavigationDirection::Forward => self.model().after(¤t_path),
|
Direction::Forward => self.model().after(¤t_path),
|
||||||
adw::NavigationDirection::Back => self.model().before(¤t_path),
|
Direction::Back => self.model().before(¤t_path),
|
||||||
_ => unimplemented!("Navigation direction should only be back or forward."),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(new_path) = new_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
|
/// Used for drag and drop
|
||||||
fn navigate_to_path(&self, new_path: &Path) {
|
fn navigate_to_path(&self, new_path: &Path) {
|
||||||
let sliding_view = self.sliding_view();
|
let sliding_view = self.sliding_view();
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ use std::cell::RefCell;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::util;
|
use crate::util::{self, Direction, Position};
|
||||||
use crate::widgets::{LpImage, LpImagePage, LpImageView, LpPropertiesView};
|
use crate::widgets::{LpImage, LpImagePage, LpImageView, LpPropertiesView};
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
|
|
@ -99,15 +99,19 @@ mod imp {
|
||||||
});
|
});
|
||||||
|
|
||||||
klass.install_action("win.next", None, move |win, _, _| {
|
klass.install_action("win.next", None, move |win, _, _| {
|
||||||
win.imp()
|
win.imp().image_view.navigate(Direction::Forward);
|
||||||
.image_view
|
|
||||||
.navigate(adw::NavigationDirection::Forward);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
klass.install_action("win.previous", None, move |win, _, _| {
|
klass.install_action("win.previous", None, move |win, _, _| {
|
||||||
win.imp()
|
win.imp().image_view.navigate(Direction::Back);
|
||||||
.image_view
|
});
|
||||||
.navigate(adw::NavigationDirection::Back);
|
|
||||||
|
klass.install_action("win.first", None, move |win, _, _| {
|
||||||
|
win.imp().image_view.jump(Position::First);
|
||||||
|
});
|
||||||
|
|
||||||
|
klass.install_action("win.last", None, move |win, _, _| {
|
||||||
|
win.imp().image_view.jump(Position::Last);
|
||||||
});
|
});
|
||||||
|
|
||||||
klass.install_action("win.zoom-out", None, move |win, _, _| {
|
klass.install_action("win.zoom-out", None, move |win, _, _| {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue