pharo-spec / mars-gtk

The Gtk3 bindings for Pharo and Spec
14 stars 6 forks source link

Files drag&drop support #37

Open pavel-krivanek opened 4 years ago

pavel-krivanek commented 4 years ago

I created small example of drag&drop support of external files on a Gtk widget. We need to make it more robust.

dragAndDrop.st.txt

app := SpApplication new.
app useBackend: #Gtk.
p := SpButtonPresenter newApplication: app.
p label: 'label'.
p openWithSpec.
button := p adapter widget.
targetEntry := GtkTargetEntry newTarget: 'text/uri-list' flags: 0 info: 3.
button dragDestSetFlags: GtkDestDefaults GTK_DEST_DEFAULT_ALL targetsTypes: targetEntry getHandle targetsAmount: 1 actions: GdkDragAction GDK_ACTION_DEFAULT.

(GDragDataReceivedCallback do: [ :widget :dragContext :x :y :selectionData :info :time |
    | resutl pointers |
    result := GDragDataReceivedCallback gtk_selection_data_get_uris: selectionData.
    pointers := (result readArrayOf: (GObject resolveType: #gpointer)
        until: [ :each | each isNull ]).
    (pointers collect: [ :p | p readStringUTF8 ]) inspect.
    ]) connectTo: button
pavel-krivanek commented 4 years ago

the Strings are actually encoded in URL encoding (like file:///D:/Downloads/web/1%20-%20Copy%20%C5%BElu%C5%A5ou%C4%8Dk%C3%BD%20k%C5%AF%C5%88.html)