edit_window: Add save and cancel shortcuts
This commit is contained in:
parent
11553bdab0
commit
8bb6f8da88
4 changed files with 70 additions and 11 deletions
|
|
@ -286,6 +286,30 @@
|
|||
<child>
|
||||
<object class="GtkShortcutsGroup">
|
||||
<property name="title" translatable="yes" context="shortcut window">Editing</property>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut">
|
||||
<property name="title" translatable="yes" context="shortcut window">Open Editing View</property>
|
||||
<property name="accelerator">E</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut">
|
||||
<property name="title" translatable="yes" context="shortcut window">Replace Original</property>
|
||||
<property name="accelerator"><Ctrl>S</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut">
|
||||
<property name="title" translatable="yes" context="shortcut window">Save As</property>
|
||||
<property name="accelerator"><Ctrl><Shift>S</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut">
|
||||
<property name="title" translatable="yes" context="shortcut window">Cancel</property>
|
||||
<property name="accelerator">Escape</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut">
|
||||
<property name="title" translatable="yes" context="shortcut window">Rotate Clockwise</property>
|
||||
|
|
|
|||
1
news.d/48.beta/added-edit-save-and-cancel-shortcuts
Normal file
1
news.d/48.beta/added-edit-save-and-cancel-shortcuts
Normal file
|
|
@ -0,0 +1 @@
|
|||
edit: `Ctrl+S` and `Ctrl+Shift+S` shortcuts save images and `Esc` to exit the editing view.
|
||||
|
|
@ -48,6 +48,8 @@ mod imp {
|
|||
saving_status: TemplateChild<gtk::Label>,
|
||||
#[template_child]
|
||||
saving_info: TemplateChild<gtk::Revealer>,
|
||||
#[template_child]
|
||||
shortcut_controller: TemplateChild<gtk::ShortcutController>,
|
||||
|
||||
#[property(get, construct_only)]
|
||||
original_image: OnceCell<LpImage>,
|
||||
|
|
@ -82,6 +84,10 @@ mod imp {
|
|||
async move { obj.imp().save_overwrite().await }
|
||||
));
|
||||
});
|
||||
|
||||
klass.install_action("edit.cancel", None, move |obj, _, _| {
|
||||
obj.imp().cancel();
|
||||
});
|
||||
}
|
||||
|
||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||
|
|
@ -96,17 +102,6 @@ mod imp {
|
|||
|
||||
let obj = self.obj();
|
||||
|
||||
self.cancel.connect_clicked(glib::clone!(
|
||||
#[weak]
|
||||
obj,
|
||||
move |_| {
|
||||
if let Some(cancellable) = obj.imp().save_cancellable.replace(None) {
|
||||
cancellable.cancel();
|
||||
}
|
||||
obj.window().show_image();
|
||||
}
|
||||
));
|
||||
|
||||
glib::spawn_future_local(glib::clone!(
|
||||
#[weak]
|
||||
obj,
|
||||
|
|
@ -115,6 +110,30 @@ mod imp {
|
|||
obj.action_set_enabled("edit.save-overwrite", can_trash);
|
||||
}
|
||||
));
|
||||
|
||||
self.shortcut_controller.add_shortcut(gtk::Shortcut::new(
|
||||
Some(gtk::KeyvalTrigger::new(
|
||||
gdk::Key::S,
|
||||
gdk::ModifierType::CONTROL_MASK,
|
||||
)),
|
||||
Some(gtk::NamedAction::new("edit.save-overwrite")),
|
||||
));
|
||||
|
||||
self.shortcut_controller.add_shortcut(gtk::Shortcut::new(
|
||||
Some(gtk::KeyvalTrigger::new(
|
||||
gdk::Key::S,
|
||||
gdk::ModifierType::CONTROL_MASK.union(gdk::ModifierType::SHIFT_MASK),
|
||||
)),
|
||||
Some(gtk::NamedAction::new("edit.save-copy")),
|
||||
));
|
||||
|
||||
self.shortcut_controller.add_shortcut(gtk::Shortcut::new(
|
||||
Some(gtk::KeyvalTrigger::new(
|
||||
gdk::Key::Escape,
|
||||
gdk::ModifierType::NO_MODIFIER_MASK,
|
||||
)),
|
||||
Some(gtk::NamedAction::new("edit.cancel")),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -136,6 +155,15 @@ mod imp {
|
|||
impl BinImpl for LpEditWindow {}
|
||||
|
||||
impl LpEditWindow {
|
||||
fn cancel(&self) {
|
||||
let obj = self.obj();
|
||||
|
||||
if let Some(cancellable) = obj.imp().save_cancellable.replace(None) {
|
||||
cancellable.cancel();
|
||||
}
|
||||
obj.window().show_image();
|
||||
}
|
||||
|
||||
async fn save_copy(&self) {
|
||||
let obj = self.obj();
|
||||
self.done.popdown();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="LpEditWindow" parent="AdwBin">
|
||||
<child>
|
||||
<object class="GtkShortcutController" id="shortcut_controller">
|
||||
<property name="scope">global</property>
|
||||
</object>
|
||||
</child>
|
||||
<property name="child">
|
||||
<object class="AdwToolbarView" id="toolbar_view">
|
||||
<property name="top-bar-style">raised</property>
|
||||
|
|
@ -58,6 +63,7 @@
|
|||
<object class="GtkButton" id="cancel">
|
||||
<property name="label" translatable="true">_Cancel</property>
|
||||
<property name="use-underline">true</property>
|
||||
<property name="action-name">edit.cancel</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="end">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue