2007-09-20 18:09:08 -04:00
|
|
|
! Copyright (C) 2006, 2007 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: alien.c-types arrays kernel cocoa.messages
|
|
|
|
cocoa.classes cocoa.application cocoa core-foundation
|
|
|
|
sequences ;
|
|
|
|
IN: cocoa.pasteboard
|
|
|
|
|
|
|
|
: NSStringPboardType "NSStringPboardType" ;
|
|
|
|
|
|
|
|
: pasteboard-string? ( pasteboard -- ? )
|
|
|
|
NSStringPboardType swap -> types CF>string-array member? ;
|
|
|
|
|
|
|
|
: pasteboard-string ( pasteboard -- str )
|
|
|
|
NSStringPboardType <NSString> -> stringForType:
|
|
|
|
dup [ CF>string ] when ;
|
|
|
|
|
|
|
|
: set-pasteboard-types ( seq pasteboard -- )
|
|
|
|
swap <NSArray> f -> declareTypes:owner: drop ;
|
|
|
|
|
|
|
|
: set-pasteboard-string ( str pasteboard -- )
|
|
|
|
NSStringPboardType <NSString>
|
|
|
|
dup 1array pick set-pasteboard-types
|
2008-11-30 19:28:15 -05:00
|
|
|
[ swap <NSString> ] dip -> setString:forType: drop ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: pasteboard-error ( error -- f )
|
|
|
|
"Pasteboard does not hold a string" <NSString>
|
2007-12-29 11:36:20 -05:00
|
|
|
0 spin set-void*-nth f ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: ?pasteboard-string ( pboard error -- str/f )
|
|
|
|
over pasteboard-string? [
|
|
|
|
swap pasteboard-string [ ] [ pasteboard-error ] ?if
|
|
|
|
] [
|
|
|
|
nip pasteboard-error
|
|
|
|
] if ;
|