Skip to content

Commit 4307769

Browse files
committed
Adding PNG drag point.
1 parent 70eafcf commit 4307769

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/CanvasToolbar.vala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff 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();

src/Utils.vala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)