File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,8 @@ public class CanvasToolbar : Box {
6969 create_color();
7070 create_stroke();
7171 create_fonts();
72+ create_separator();
73+ create_drag_label();
7274
7375 /* If the selection changes, update the toolbar */
7476 _canvas. items. selection_changed. connect( selection_changed );
@@ -724,6 +726,33 @@ public class CanvasToolbar : Box {
724726
725727 }
726728
729+ // -------------------------------------------------------------
730+ // Creates a label that we can drag an image from.
731+ private void create_drag_label() {
732+
733+ var drag_label = new Label ( " PNG" ) {
734+ tooltip_text = _ ( "Drag PNG Image " ),
735+ margin_start = 20
736+ };
737+
738+ var drag = new DragSource () {
739+ actions = Gdk . DragAction . MOVE
740+ };
741+ drag_label.add_controller ( drag );
742+
743+ drag.prepare.connect ((d ) => {
744+ var val = Value ( typeof (GLib . File ) );
745+ var fname = Utils . create_temp_filename( " png" );
746+ _canvas. win. editor. canvas. image. export_image( " png" , fname );
747+ val = File . new_for_path( fname );
748+ var cp = new Gdk .ContentProvider .for_value( val );
749+ return ( cp );
750+ });
751+
752+ append ( drag_label );
753+
754+ }
755+
727756 private Image make_color_icon() {
728757
729758 var snapshot = new Snapshot ();
Original file line number Diff line number Diff line change @@ -274,4 +274,16 @@ public class Utils {
274274 return ( str );
275275 }
276276
277+ // -------------------------------------------------------------
278+ // Creates a temporary filename.
279+ public static string ? create_temp_filename ( string extension ) {
280+ try {
281+ string filename = " " ;
282+ var fd = FileUtils . open_tmp( " annotator_XXXXXX.%s " . printf( extension ), out filename );
283+ FileUtils . close( fd );
284+ return ( filename );
285+ } catch ( FileError e ) {}
286+ return ( null );
287+ }
288+
277289}
You can’t perform that action at this time.
0 commit comments