[squeak-dev] Extended Clipboard

Juan Vuletich juan at jvuletich.org
Wed Jan 19 15:31:49 UTC 2011


Bert Freudenberg wrote:
>
> However, there is one major issue: When pasting, we have not found a way to determine which clipboard should take precedence - Squeak's text clipboard, Morphic's object clipboard, the system's string clipboard, or the extended Text/Bitmap/Etc. clipboard. In Sophie I guess you used the extended clipboard exclusively, but for Squeak it's not quite as clear-cut ...
>
> - Bert -
>   

I found a solution for this. The trick is to always store something in 
the OS clipboard when doing 'copy'. If the object to be stored in the 
clipboard is not supported by the OS clipboard, then store and id. The 
id is a string that includes the class name and hash. So, the method to 
read the clipboard becomes:

Clipboard >> retrieveObject
    "Answer whatever was last stored in the clipboard"
    | stringOrNil |
    "If the OS clipboard has the id for our contents, or the same 
characters, then answer the richer Smalltalk object."
    stringOrNil := self retrieveStringFromOS.
    stringOrNil = (self stringOrIdFor: contents)
        ifTrue: [ ^contents ].

    "If we have the ExtendedClipboardInterface, try to get an RTF or Form"
    Smalltalk at: #ExtendedClipboardInterface ifPresent: [ 
:clipboardInterface |
        clipboardInterface current retrieveText ifNotNil: [ :text | ^text ].
        clipboardInterface current retrieveForm ifNotNil: [ :form | 
^form ]].

    "Otherwise answer the string brought by ExtendedClipboardInterface 
or by clipboard primitives"
    ^stringOrNil

And you get whatever was last copied into the clipboard, regardless of 
being copied from Squeak or from other application, without losing the 
ability to store Smalltalk objects in the Squeak clipboard.

(RTF support is not yet done)

Cheers,
Juan Vuletich



More information about the Squeak-dev mailing list