Skip to content

Commit

Permalink
Adds drag support for the preview image in Save dialog (#185)
Browse files Browse the repository at this point in the history
* It is now possible to grad the SaveDialog's preview image and drop it into targets that accept images.

* Lint.

* Update src/Widgets/SaveDialog.vala

Co-authored-by: Daniel Foré <[email protected]>

* Adds event box to grid to preserve box shadow effects.

* linting was failing.

Co-authored-by: Daniel Foré <[email protected]>
  • Loading branch information
igordsm and danirabbit authored Jul 13, 2020
1 parent 035f6dc commit 5eb496a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Widgets/SaveDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,20 @@ public class Screenshot.SaveDialog : Gtk.Dialog {
preview.gicon = pixbuf.scale_simple (width * scale, height * scale, Gdk.InterpType.BILINEAR);
preview.get_style_context ().set_scale (1);

var preview_event_box = new Gtk.EventBox ();
preview_event_box.add (preview);

Gtk.drag_source_set (preview_event_box, Gdk.ModifierType.BUTTON1_MASK, null, Gdk.DragAction.COPY);
Gtk.drag_source_add_image_targets (preview_event_box);
Gtk.drag_source_set_icon_gicon (preview_event_box, new ThemedIcon ("image-x-generic"));
preview_event_box.drag_data_get.connect ((widget, context, selection_data, info, time_) => {
selection_data.set_pixbuf (pixbuf);
});


var preview_box = new Gtk.Grid ();
preview_box.halign = Gtk.Align.CENTER;
preview_box.add (preview);
preview_box.add (preview_event_box);

unowned Gtk.StyleContext preview_box_context = preview_box.get_style_context ();
preview_box_context.add_class (Granite.STYLE_CLASS_CARD);
Expand Down

0 comments on commit 5eb496a

Please sign in to comment.