1 ! Copyright (C) 2006, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.accessors arrays kernel cocoa.messages
4 cocoa.classes cocoa.application sequences cocoa core-foundation
5 core-foundation.strings core-foundation.arrays ;
8 : NSStringPboardType "NSStringPboardType" ;
10 : pasteboard-string? ( pasteboard -- ? )
11 NSStringPboardType swap -> types CF>string-array member? ;
13 : pasteboard-string ( pasteboard -- str )
14 NSStringPboardType <NSString> -> stringForType:
15 dup [ CF>string ] when ;
17 : set-pasteboard-types ( seq pasteboard -- )
18 swap <NSArray> f -> declareTypes:owner: drop ;
20 : set-pasteboard-string ( str pasteboard -- )
21 NSStringPboardType <NSString>
22 dup 1array pick set-pasteboard-types
23 [ swap <NSString> ] dip -> setString:forType: drop ;
25 : pasteboard-error ( error -- f )
26 "Pasteboard does not hold a string" <NSString>
29 : ?pasteboard-string ( pboard error -- str/f )
30 over pasteboard-string? [
31 swap pasteboard-string [ ] [ pasteboard-error ] ?if