image: Implement Copy to clipboard
This commit is contained in:
parent
7b760f85f4
commit
be09d49756
5 changed files with 36 additions and 0 deletions
|
|
@ -164,6 +164,7 @@ impl LpApplication {
|
|||
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("win.toggle-fullscreen", &["F11"]);
|
||||
self.set_accels_for_action("window.close", &["<Primary>W"]);
|
||||
|
|
|
|||
|
|
@ -205,4 +205,9 @@ impl LpImage {
|
|||
let imp = self.imp();
|
||||
imp.image_height.get()
|
||||
}
|
||||
|
||||
pub fn texture(&self) -> Option<gdk::Texture> {
|
||||
let imp = self.imp();
|
||||
imp.texture.borrow().clone()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -342,6 +342,19 @@ impl LpImageView {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn copy(&self) -> anyhow::Result<()> {
|
||||
let clipboard = self.clipboard();
|
||||
let imp = self.imp();
|
||||
|
||||
if let Some(texture) = imp.picture.texture() {
|
||||
clipboard.set_texture(&texture);
|
||||
} else {
|
||||
anyhow::bail!("No Image displayed.");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn uri(&self) -> Option<String> {
|
||||
let imp = self.imp();
|
||||
imp.uri.borrow().to_owned()
|
||||
|
|
|
|||
|
|
@ -107,6 +107,10 @@ mod imp {
|
|||
win.print();
|
||||
});
|
||||
|
||||
klass.install_action("win.copy", None, move |win, _, _| {
|
||||
win.copy();
|
||||
});
|
||||
|
||||
klass.install_action("win.show-toast", Some("(si)"), move |win, _, var| {
|
||||
if let Some((ref toast, i)) = var.map(|v| v.get::<(String, i32)>()).flatten() {
|
||||
win.show_toast(toast, adw::ToastPriority::__Unknown(i));
|
||||
|
|
@ -303,6 +307,14 @@ impl LpWindow {
|
|||
}
|
||||
}
|
||||
|
||||
fn copy(&self) {
|
||||
let imp = self.imp();
|
||||
|
||||
if let Err(e) = imp.image_view.copy() {
|
||||
log::error!("Failed to copy to clipboard: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn show_toast(&self, text: &impl AsRef<str>, priority: adw::ToastPriority) {
|
||||
let imp = self.imp();
|
||||
|
||||
|
|
@ -335,6 +347,7 @@ impl LpWindow {
|
|||
self.action_set_enabled("win.set-wallpaper", enabled);
|
||||
self.action_set_enabled("win.toggle-fullscreen", enabled);
|
||||
self.action_set_enabled("win.print", enabled);
|
||||
self.action_set_enabled("win.copy", 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