window: Copy metadata instead of image if selected

This commit is contained in:
Sophie Herold 2023-11-30 01:20:13 +01:00
parent b56d650086
commit 307c864c6e
4 changed files with 38 additions and 10 deletions

View file

@ -16,7 +16,7 @@
</item>
<item>
<attribute name="label" translatable="yes">_Copy</attribute>
<attribute name="action">win.copy</attribute>
<attribute name="action">win.copy-image</attribute>
</item>
</section>
<section>

View file

@ -122,6 +122,21 @@ mod imp {
Self::bind_template(klass);
Self::Type::bind_template_callbacks(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
false
} else {
window.copy_image();
true
}
},
None,
);
// Set up actions
klass.install_action("win.toggle-fullscreen", None, move |win, _, _| {
win.toggle_fullscreen(!win.is_fullscreened());
@ -225,8 +240,8 @@ mod imp {
win.print();
});
klass.install_action("win.copy", None, move |win, _, _| {
win.copy();
klass.install_action("win.copy-image", None, move |win, _, _| {
win.copy_image();
});
klass.install_action_async("win.trash", None, |win, _, _| async move {
@ -561,7 +576,21 @@ impl LpWindow {
}
}
fn copy(&self) {
/// Returns true if some text in metadata is currently selected
fn has_metadata_selected(&self) -> bool {
if let Some(focus_widget) = self.focus_widget() {
if focus_widget.is_ancestor(&*self.imp().properties_view) {
if let Ok(label) = focus_widget.downcast::<gtk::Label>() {
return label.selection_bounds().is_some();
}
}
}
false
}
/// Copy image to clipboard or metadata text if selected
fn copy_image(&self) {
let imp = self.imp();
if let Err(e) = imp.image_view.copy() {
@ -685,7 +714,7 @@ impl LpWindow {
self.action_set_enabled("win.print", enabled);
self.action_set_enabled("win.rotate_cw", enabled);
self.action_set_enabled("win.rotate_ccw", enabled);
self.action_set_enabled("win.copy", enabled);
self.action_set_enabled("win.copy-image", enabled);
self.action_set_enabled("win.zoom-best-fit", enabled);
self.action_set_enabled("win.zoom-to-exact", enabled);
self.action_set_enabled("win.toggle-properties", enabled);

View file

@ -105,7 +105,7 @@
<child type="start">
<object class="GtkButton">
<property name="icon-name">edit-copy-symbolic</property>
<property name="action-name">win.copy</property>
<property name="action-name">win.copy-image</property>
<property name="tooltip-text" translatable="yes">Copy to Clipboard</property>
</object>
</child>