Friday, March 28, 2008

Filenames from Clipboard and via native Drag&Drop

I just found two tiny packages which might help you to improve the native integration of your app with Windows. Both deal with getting file(names) from the user.

1) Clipboard (US Clipboard Extensions)
You can get filenames from the Clipboard using #getFilenamesIfNone: or simply using #getFilenames:

filenames := Clipboard current getFilenamesIfNone: [].
filenames := Clipboard current getFilenames.

2) (Native) Drag&Drop (US DragAndDrop Extensions)
This package allows you to get filenames from a Drag&Drop Session using #dragFilenames::

filenames := aDragDropSession dragFilenames

E.g. you can use it in the following D&D code:

onDragOverList: aDragDropSession
| filenames |
filenames := self
filterFilenames: aDragDropSession dragFilenames.
aDragDropSession
operation: (filenames notEmpty
ifTrue: [#copy]
ifFalse: [#none])

onDropOverList: aDragDropSession
| filenames |
filenames := self
filterFilenames: aDragDropSession dragFilenames.
filenames notEmpty
ifTrue:
[self addFiles: filenames]


#filterFilenames: is one of my methods which selects only extensions acceptable for the Application.

Both packages are part of my goodies which are available on this site.

No comments: