factor/library/ui/cocoa/services.factor

43 lines
1.2 KiB
Factor
Raw Normal View History

! Copyright (C) 2006 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
IN: objc-classes
DEFER: FactorServiceProvider
IN: cocoa
2006-05-24 19:34:30 -04:00
USING: alien gadgets-presentations io kernel namespaces objc
parser prettyprint styles ;
: pasteboard-error ( error str -- f )
"Pasteboard does not hold a string" <NSString>
2006-05-24 19:34:30 -04:00
0 swap rot set-void*-nth f ;
: ?pasteboard-string ( pboard error -- str/f )
2006-05-24 19:34:30 -04:00
over pasteboard-string? [
swap pasteboard-string [ ] [ pasteboard-error ] ?if
] [
nip pasteboard-error
] if ;
: do-service ( pboard error quot -- | quot: str -- str/f )
2006-05-24 19:34:30 -04:00
pick >r >r
?pasteboard-string dup [ r> call ] [ r> 2drop f ] if
dup [ r> set-pasteboard-string ] [ r> 2drop ] if ;
"NSObject" "FactorServiceProvider" {
2006-05-24 19:34:30 -04:00
{
"evalInListener:userData:error:" "void"
{ "id" "SEL" "id" "id" "void*" }
[ nip [ <input> show f ] do-service 2drop ]
}
2006-05-24 19:34:30 -04:00
{
"evalToString:userData:error:" "void"
{ "id" "SEL" "id" "id" "void*" }
[ nip [ eval>string ] do-service 2drop ]
}
} { } define-objc-class
: register-services ( -- )
NSApp
FactorServiceProvider -> alloc -> init
-> setServicesProvider: ;