]> gitweb.factorcode.org Git - factor.git/blob - library/ui/cocoa/services.factor
cf24e1d94158d1cf53f9075f0e65b2257c4a65b0
[factor.git] / library / ui / cocoa / services.factor
1 ! Copyright (C) 2006 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: objc-classes
4 DEFER: FactorServiceProvider
5
6 IN: cocoa
7 USING: alien io kernel namespaces objc
8 parser prettyprint styles gadgets-listener gadgets-workspace ;
9
10 : pasteboard-error ( error -- f )
11     "Pasteboard does not hold a string" <NSString>
12     0 swap rot set-void*-nth f ;
13
14 : ?pasteboard-string ( pboard error -- str/f )
15     over pasteboard-string? [
16         swap pasteboard-string [ ] [ pasteboard-error ] ?if
17     ] [
18         nip pasteboard-error
19     ] if ;
20
21 : do-service ( pboard error quot -- )
22     pick >r >r
23     ?pasteboard-string dup [ r> call ] [ r> 2drop f ] if
24     dup [ r> set-pasteboard-string ] [ r> 2drop ] if ;
25
26 "NSObject" "FactorServiceProvider" {
27     {
28         "evalInListener:userData:error:" "void"
29         { "id" "SEL" "id" "id" "void*" }
30         [
31             nip
32             [ call-listener f ]
33             do-service
34             2drop
35         ]
36     }
37     {
38         "evalToString:userData:error:" "void"
39         { "id" "SEL" "id" "id" "void*" }
40         [ nip [ eval>string ] do-service 2drop ]
41     }
42 } { } define-objc-class
43
44 : register-services ( -- )
45     NSApp
46     FactorServiceProvider -> alloc -> init
47     -> setServicesProvider: ;