window: Move Ctrl+C (copy) handler here

Closes #583
This commit is contained in:
Sophie Herold 2026-04-26 23:19:20 +02:00
parent c2bffbc686
commit c3410943b8
2 changed files with 21 additions and 20 deletions

View file

@ -125,26 +125,8 @@ mod imp {
}
fn class_init(klass: &mut Self::Class) {
// bind_template() is a function generated by the
// CompositeTemplate macro to bind all children at once.
Self::bind_template(klass);
klass.add_binding(gdk::Key::c, gdk::ModifierType::CONTROL_MASK, |window| {
if window.has_metadata_selected() {
// Pass on to normal copy handler to copy selected metadata
glib::Propagation::Proceed
} else {
window.copy_image();
glib::Propagation::Stop
}
});
klass.add_binding_action(
gdk::Key::question,
gdk::ModifierType::CONTROL_MASK,
"app.shortcuts",
);
// Set up actions
Action::init_actions(klass);
}
@ -607,7 +589,7 @@ impl LpImageWindow {
}
/// Returns true if some text in metadata is currently selected
fn has_metadata_selected(&self) -> bool {
pub fn has_metadata_selected(&self) -> bool {
let Some(window) = self.try_window() else {
return false;
};
@ -623,7 +605,7 @@ impl LpImageWindow {
}
/// Copy image to clipboard or metadata text if selected
fn copy_image(&self) {
pub fn copy_image(&self) {
let imp = self.imp();
if let Err(e) = imp.image_view.copy() {