[squeak-dev] Extended Clipboard

Juan Vuletich juan at jvuletich.org
Wed Jan 19 15:45:14 UTC 2011


Bert Freudenberg wrote:
> On 19.01.2011, at 16:31, Juan Vuletich wrote:
>
>   
>> 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
>>     
>
> This is better than our current solution but not perfect yet. E.g. when copying a morph we put a bitmap in the OS clipboard and the morph in the Morphic clipboard. When pasting, how do we know we should prefer the Morphic clipboard over the OS bitmap? Is it possible to store a text id and a bitmap at the same time? 
>
> - Bert -
>   

Yes, it can be done. That's why you usually send #clearClipboard prior 
to storing suff. I haven't done this yet because I haven't implemented 
copy Morph to OS clipboard.

Cheers,
Juan Vuletich



More information about the Squeak-dev mailing list