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
|
|
@ -14,44 +14,162 @@
|
||||||
<property name="accelerator">F10</property>
|
<property name="accelerator">F10</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Toggle Image Properties</property>
|
||||||
|
<property name="action-name">win.toggle-properties</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Toggle Fullscreen</property>
|
||||||
|
<property name="action-name">win.toggle-fullscreen</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Leave Fullscreen</property>
|
||||||
|
<property name="action-name">win.leave-fullscreen</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkShortcutsShortcut">
|
<object class="GtkShortcutsShortcut">
|
||||||
<property name="title" translatable="yes" context="shortcut window">New Window</property>
|
<property name="title" translatable="yes" context="shortcut window">New Window</property>
|
||||||
<property name="accelerator"><Primary>n</property>
|
<property name="action-name">app.new-window</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkShortcutsShortcut">
|
<object class="GtkShortcutsShortcut">
|
||||||
<property name="title" translatable="yes" context="shortcut window">Open Help</property>
|
<property name="title" translatable="yes" context="shortcut window">Open Help</property>
|
||||||
<property name="accelerator">F1</property>
|
<property name="action-name">app.help</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkShortcutsShortcut">
|
<object class="GtkShortcutsShortcut">
|
||||||
<property name="title" translatable="yes" context="shortcut window">Show Keyboard Shortcuts</property>
|
<property name="title" translatable="yes" context="shortcut window">Show Keyboard Shortcuts</property>
|
||||||
<property name="accelerator"><Primary>question</property>
|
<property name="action-name">win.show-help-overlay</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Close Window</property>
|
||||||
|
<property name="action-name">window.close</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkShortcutsShortcut">
|
<object class="GtkShortcutsShortcut">
|
||||||
<property name="title" translatable="yes" context="shortcut window">Quit</property>
|
<property name="title" translatable="yes" context="shortcut window">Quit</property>
|
||||||
<property name="accelerator"><Primary>q</property>
|
<property name="action-name">app.quit</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsGroup">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Navigate Images</property>
|
||||||
|
<!-- TODO: All these need RTL support -->
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Next Image</property>
|
||||||
|
<property name="shortcut-type">gesture-two-finger-swipe-right</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkShortcutsShortcut">
|
<object class="GtkShortcutsShortcut">
|
||||||
<property name="title" translatable="yes" context="shortcut window">Show with orginal scale</property>
|
<property name="title" translatable="yes" context="shortcut window">Previous Image</property>
|
||||||
|
<property name="shortcut-type">gesture-two-finger-swipe-left</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Next Image</property>
|
||||||
|
<property name="accelerator">Right</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Previous Image</property>
|
||||||
|
<property name="accelerator">Left</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsGroup">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Zoom Image</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Zoom In</property>
|
||||||
|
<property name="shortcut-type">gesture-stretch</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Zoom Out</property>
|
||||||
|
<property name="shortcut-type">gesture-pinch</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Zoom In</property>
|
||||||
|
<property name="accelerator"><Ctrl>plus plus</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Zoom Out</property>
|
||||||
|
<property name="accelerator"><Ctrl>minus minus</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Best Fit</property>
|
||||||
|
<property name="action-name">win.zoom-best-fit</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Original Scale</property>
|
||||||
<property name="accelerator">1</property>
|
<property name="accelerator">1</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkShortcutsShortcut">
|
<object class="GtkShortcutsShortcut">
|
||||||
<property name="title" translatable="yes" context="shortcut window">Show with 200% of orginal scale</property>
|
<property name="title" translatable="yes" context="shortcut window">200% Scale</property>
|
||||||
<property name="accelerator">2</property>
|
<property name="accelerator">2</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsGroup">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Rotate Image</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Rotate Clockwise</property>
|
||||||
|
<property name="shortcut-type">gesture-rotate-clockwise</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Rotate Counterclockwise</property>
|
||||||
|
<property name="shortcut-type">gesture-rotate-counterclockwise</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Rotate Clockwise</property>
|
||||||
|
<property name="accelerator"><Ctrl>R</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Rotate Counterclockwise</property>
|
||||||
|
<property name="accelerator"><Ctrl><Shift>R</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
||||||
|
|
@ -121,11 +121,24 @@
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</property>
|
</property>
|
||||||
|
<child>
|
||||||
|
<!-- Set the shortcut here since it only makes sense if the button is visible -->
|
||||||
|
<object class="GtkShortcutController">
|
||||||
|
<property name="scope">managed</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcut">
|
||||||
|
<property name="trigger">F10</property>
|
||||||
|
<property name="action">activate</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child type="end">
|
<child type="end">
|
||||||
<object class="GtkToggleButton" id="properties_button">
|
<object class="GtkToggleButton" id="properties_button">
|
||||||
<property name="icon-name">help-about-symbolic</property>
|
<property name="icon-name">help-about-symbolic</property>
|
||||||
|
<property name="tooltip-text" translatable="yes">Image Properties</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
||||||
|
|
@ -131,16 +131,39 @@ impl LpApplication {
|
||||||
self.add_action_entries(actions).unwrap();
|
self.add_action_entries(actions).unwrap();
|
||||||
|
|
||||||
self.set_accels_for_action("app.help", &["F1"]);
|
self.set_accels_for_action("app.help", &["F1"]);
|
||||||
self.set_accels_for_action("app.quit", &["<Primary>Q"]);
|
self.set_accels_for_action("app.quit", &["<Ctrl>Q"]);
|
||||||
self.set_accels_for_action("app.new-window", &["<Primary>N"]);
|
self.set_accels_for_action("app.new-window", &["<Ctrl>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.open", &["<Ctrl>O"]);
|
||||||
self.set_accels_for_action("win.copy", &["<Primary>C"]);
|
self.set_accels_for_action("win.print", &["<Ctrl>P"]);
|
||||||
self.set_accels_for_action("win.show-help-overlay", &["<Primary>question"]);
|
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("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(1.0)", &["1"]);
|
||||||
self.set_accels_for_action("win.zoom-to(2.0)", &["2"]);
|
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) {
|
pub fn show_about(&self) {
|
||||||
|
|
|
||||||
|
|
@ -671,7 +671,6 @@ impl LpImage {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
animation.connect_done(glib::clone!(@weak self as obj => move |_| {
|
animation.connect_done(glib::clone!(@weak self as obj => move |_| {
|
||||||
dbg!("animation done");
|
|
||||||
obj.imp().zoom_hscrollbar_transition.set(false);
|
obj.imp().zoom_hscrollbar_transition.set(false);
|
||||||
obj.imp().zoom_vscrollbar_transition.set(false);
|
obj.imp().zoom_vscrollbar_transition.set(false);
|
||||||
}));
|
}));
|
||||||
|
|
@ -732,6 +731,13 @@ impl LpImage {
|
||||||
self.zoom_to(zoom);
|
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
|
/// Zoom to specific level with animation
|
||||||
pub fn zoom_to(&self, zoom: f64) {
|
pub fn zoom_to(&self, zoom: f64) {
|
||||||
log::debug!("Zoom to {zoom:.3}");
|
log::debug!("Zoom to {zoom:.3}");
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,8 @@ mod imp {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub headerbar: TemplateChild<gtk::HeaderBar>,
|
pub headerbar: TemplateChild<gtk::HeaderBar>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
|
pub properties_button: TemplateChild<gtk::ToggleButton>,
|
||||||
|
#[template_child]
|
||||||
pub menu_button: TemplateChild<gtk::MenuButton>,
|
pub menu_button: TemplateChild<gtk::MenuButton>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub toast_overlay: TemplateChild<adw::ToastOverlay>,
|
pub toast_overlay: TemplateChild<adw::ToastOverlay>,
|
||||||
|
|
@ -106,6 +108,20 @@ mod imp {
|
||||||
win.zoom_to(level.unwrap().get().unwrap());
|
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, _, _| {
|
klass.install_action("win.open", None, move |win, _, _| {
|
||||||
win.pick_file();
|
win.pick_file();
|
||||||
});
|
});
|
||||||
|
|
@ -284,6 +300,12 @@ impl LpWindow {
|
||||||
self.imp().image_view.zoom_to(level);
|
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) {
|
fn pick_file(&self) {
|
||||||
let chooser = gtk::FileChooserNative::new(
|
let chooser = gtk::FileChooserNative::new(
|
||||||
Some("Open Image"),
|
Some("Open Image"),
|
||||||
|
|
@ -403,6 +425,10 @@ impl LpWindow {
|
||||||
self.action_set_enabled("win.print", enabled);
|
self.action_set_enabled("win.print", enabled);
|
||||||
self.action_set_enabled("win.rotate", enabled);
|
self.action_set_enabled("win.rotate", enabled);
|
||||||
self.action_set_enabled("win.copy", 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
|
// 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