Commit c83dfbed authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

Add a keyboard shortcut to take & copy a screenshot

Fixes #21
parent ef2122ae
Pipeline #116665 passed with stage
in 2 minutes and 9 seconds
......@@ -81,6 +81,13 @@
<property name="title" translatable="yes" context="shortcut window">Take screenshot</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="accelerator">&lt;primary&gt;&lt;alt&gt;c</property>
<property name="title" translatable="yes" context="shortcut window">Copy a screenshot to clipboard</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
......
......@@ -83,6 +83,7 @@ namespace IconPreview {
set_accels_for_action ("win.export", { "<primary>E" });
set_accels_for_action ("win.shuffle", { "<primary>S" });
set_accels_for_action ("win.screenshot", { "<primary><alt>s" });
set_accels_for_action ("win.copy-screenshot", { "<primary><alt>c" });
set_accels_for_action ("win.menu", { "F10" });
set_accels_for_action ("win.fullscreen", { "F11" });
set_accels_for_action ("app.quit", { "<primary>Q" });
......
......@@ -40,7 +40,7 @@ namespace IconPreview {
destroy();
}
private void copy () {
public void copy () {
Clipboard.get_default(get_display()).set_image(pixbuf);
}
......
......@@ -21,6 +21,7 @@ namespace IconPreview {
{ "open", open },
{ "new-icon", new_icon, "s" },
{ "screenshot", screenshot },
{ "copy-screenshot", copy_screenshot },
{ "recents", open_recent },
{ "refresh", refresh },
{ "shuffle", shuffle },
......@@ -154,6 +155,7 @@ namespace IconPreview {
(lookup_action("shuffle") as SimpleAction).set_enabled(false);
(lookup_action("export") as SimpleAction).set_enabled(false);
(lookup_action("screenshot") as SimpleAction).set_enabled(false);
(lookup_action("copy-screenshot") as SimpleAction).set_enabled(false);
break;
case SYMBOLIC:
_mode_changed(new Symbolic(exporter));
......@@ -178,6 +180,7 @@ namespace IconPreview {
(lookup_action("shuffle") as SimpleAction).set_enabled(true);
(lookup_action("export") as SimpleAction).set_enabled(true);
(lookup_action("screenshot") as SimpleAction).set_enabled(true);
(lookup_action("copy-screenshot") as SimpleAction).set_enabled(true);
}
}
......@@ -218,6 +221,14 @@ namespace IconPreview {
s.show();
}
// Screenshot the previewer
private void copy_screenshot () requires (content.visible_child is Previewer) {
var buf = (content.visible_child as Previewer).screenshot();
var s = new ScreenshotSaver(this, buf);
s.copy();
}
// Open file chooser for exporting
private void save_export(GLib.Action _act, Variant? arg) {
string title = "";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment