window: Add missing shortcuts
Add shortcuts - F9 Image properties - F10 Main menu - Ctrl +/- for zoom - Ctrl 0 for best fit - Ctrl [Shift] R for rotate - Escape to leave fullscrenen Updated help overlay accordingly.
This commit is contained in:
parent
583794a3ec
commit
f1593203a0
5 changed files with 200 additions and 14 deletions
|
|
@ -131,16 +131,39 @@ impl LpApplication {
|
|||
self.add_action_entries(actions).unwrap();
|
||||
|
||||
self.set_accels_for_action("app.help", &["F1"]);
|
||||
self.set_accels_for_action("app.quit", &["<Primary>Q"]);
|
||||
self.set_accels_for_action("app.new-window", &["<Primary>N"]);
|
||||
self.set_accels_for_action("win.open", &["<Primary>O"]);
|
||||
self.set_accels_for_action("win.print", &["<Primary>P"]);
|
||||
self.set_accels_for_action("win.copy", &["<Primary>C"]);
|
||||
self.set_accels_for_action("win.show-help-overlay", &["<Primary>question"]);
|
||||
self.set_accels_for_action("app.quit", &["<Ctrl>Q"]);
|
||||
self.set_accels_for_action("app.new-window", &["<Ctrl>N"]);
|
||||
|
||||
self.set_accels_for_action("win.open", &["<Ctrl>O"]);
|
||||
self.set_accels_for_action("win.print", &["<Ctrl>P"]);
|
||||
self.set_accels_for_action("win.copy", &["<Ctrl>C"]);
|
||||
self.set_accels_for_action("win.show-help-overlay", &["<Ctrl>question"]);
|
||||
self.set_accels_for_action("win.leave-fullscreen", &["Escape"]);
|
||||
self.set_accels_for_action("win.toggle-properties", &["F9"]);
|
||||
self.set_accels_for_action("win.toggle-fullscreen", &["F11"]);
|
||||
self.set_accels_for_action("window.close", &["<Primary>W"]);
|
||||
|
||||
self.set_accels_for_action("win.zoom-to(1.0)", &["1"]);
|
||||
self.set_accels_for_action("win.zoom-to(2.0)", &["2"]);
|
||||
self.set_accels_for_action("win.zoom-best-fit", &["<Ctrl>0", "0"]);
|
||||
self.set_accels_for_action(
|
||||
"win.zoom-in",
|
||||
&[
|
||||
"<Ctrl>plus",
|
||||
"plus",
|
||||
"<Ctrl>equal",
|
||||
"equal",
|
||||
"<Ctrl>KP_Add",
|
||||
"KP_Add",
|
||||
],
|
||||
);
|
||||
self.set_accels_for_action(
|
||||
"win.zoom-out",
|
||||
&["<Ctrl>minus", "minus", "<Ctrl>KP_Subtract", "KP_Subtract"],
|
||||
);
|
||||
self.set_accels_for_action("win.rotate(90.0)", &["<Ctrl>R"]);
|
||||
self.set_accels_for_action("win.rotate(-90.0)", &["<Ctrl><Shift>R"]);
|
||||
|
||||
self.set_accels_for_action("window.close", &["<Ctrl>W"]);
|
||||
}
|
||||
|
||||
pub fn show_about(&self) {
|
||||
|
|
|
|||
|
|
@ -671,7 +671,6 @@ impl LpImage {
|
|||
.build();
|
||||
|
||||
animation.connect_done(glib::clone!(@weak self as obj => move |_| {
|
||||
dbg!("animation done");
|
||||
obj.imp().zoom_hscrollbar_transition.set(false);
|
||||
obj.imp().zoom_vscrollbar_transition.set(false);
|
||||
}));
|
||||
|
|
@ -732,6 +731,13 @@ impl LpImage {
|
|||
self.zoom_to(zoom);
|
||||
}
|
||||
|
||||
/// Zoom to best fit
|
||||
///
|
||||
/// Used by shortcut
|
||||
pub fn zoom_best_fit(&self) {
|
||||
self.zoom_to(self.zoom_level_best_fit());
|
||||
}
|
||||
|
||||
/// Zoom to specific level with animation
|
||||
pub fn zoom_to(&self, zoom: f64) {
|
||||
log::debug!("Zoom to {zoom:.3}");
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ mod imp {
|
|||
#[template_child]
|
||||
pub headerbar: TemplateChild<gtk::HeaderBar>,
|
||||
#[template_child]
|
||||
pub properties_button: TemplateChild<gtk::ToggleButton>,
|
||||
#[template_child]
|
||||
pub menu_button: TemplateChild<gtk::MenuButton>,
|
||||
#[template_child]
|
||||
pub toast_overlay: TemplateChild<adw::ToastOverlay>,
|
||||
|
|
@ -106,6 +108,20 @@ mod imp {
|
|||
win.zoom_to(level.unwrap().get().unwrap());
|
||||
});
|
||||
|
||||
klass.install_action("win.zoom-best-fit", None, move |win, _, _| {
|
||||
win.zoom_best_fit();
|
||||
});
|
||||
|
||||
klass.install_action("win.leave-fullscreen", None, move |win, _, _| {
|
||||
win.toggle_fullscreen(false);
|
||||
});
|
||||
|
||||
klass.install_action("win.toggle-properties", None, move |win, _, _| {
|
||||
win.imp()
|
||||
.properties_button
|
||||
.set_active(!win.imp().properties_button.is_active());
|
||||
});
|
||||
|
||||
klass.install_action("win.open", None, move |win, _, _| {
|
||||
win.pick_file();
|
||||
});
|
||||
|
|
@ -284,6 +300,12 @@ impl LpWindow {
|
|||
self.imp().image_view.zoom_to(level);
|
||||
}
|
||||
|
||||
fn zoom_best_fit(&self) {
|
||||
if let Some(page) = self.imp().image_view.current_page() {
|
||||
page.image().zoom_best_fit();
|
||||
}
|
||||
}
|
||||
|
||||
fn pick_file(&self) {
|
||||
let chooser = gtk::FileChooserNative::new(
|
||||
Some("Open Image"),
|
||||
|
|
@ -403,6 +425,10 @@ impl LpWindow {
|
|||
self.action_set_enabled("win.print", enabled);
|
||||
self.action_set_enabled("win.rotate", enabled);
|
||||
self.action_set_enabled("win.copy", enabled);
|
||||
self.action_set_enabled("win.zoom-best-fit", enabled);
|
||||
self.action_set_enabled("win.zoom-in", enabled);
|
||||
self.action_set_enabled("win.zoom-to", enabled);
|
||||
self.action_set_enabled("win.toggle-properties", enabled);
|
||||
}
|
||||
|
||||
// Adapted from https://gitlab.gnome.org/GNOME/eog/-/blob/master/src/eog-window.c:eog_window_obtain_desired_size
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue