factor/basis/cocoa/dialogs/dialogs.factor

41 lines
1.2 KiB
Factor
Raw Normal View History

! Copyright (C) 2006, 2008 Slava Pestov
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
2014-12-13 19:25:48 -05:00
USING: cocoa cocoa.application cocoa.classes
core-foundation.strings kernel splitting ;
2007-09-20 18:09:08 -04:00
IN: cocoa.dialogs
: <NSOpenPanel> ( -- panel )
NSOpenPanel send\ openPanel
dup 1 send\ setCanChooseFiles:
dup 0 send\ setCanChooseDirectories:
dup 1 send\ setResolvesAliases:
dup 1 send\ setAllowsMultipleSelection: ;
2007-09-20 18:09:08 -04:00
: <NSDirPanel> ( -- panel ) <NSOpenPanel>
dup 1 send\ setCanChooseDirectories: ;
2007-09-20 18:09:08 -04:00
: <NSSavePanel> ( -- panel )
NSSavePanel send\ savePanel
dup 1 send\ setCanChooseFiles:
dup 0 send\ setCanChooseDirectories:
dup 0 send\ setAllowsMultipleSelection: ;
2007-09-20 18:09:08 -04:00
CONSTANT: NSOKButton 1
CONSTANT: NSCancelButton 0
2007-09-20 18:09:08 -04:00
: (open-panel) ( panel -- paths )
dup send\ runModal NSOKButton =
[ send\ filenames CF>string-array ] [ drop f ] if ;
2014-12-13 19:25:48 -05:00
: open-panel ( -- paths ) <NSOpenPanel> (open-panel) ;
2014-12-13 19:25:48 -05:00
: open-dir-panel ( -- paths ) <NSDirPanel> (open-panel) ;
2007-09-20 18:09:08 -04:00
: split-path ( path -- dir file )
"/" split1-last [ "" or <NSString> ] bi@ ;
2007-09-20 18:09:08 -04:00
: save-panel ( path -- path/f )
[ <NSSavePanel> dup ] dip
split-path send\ runModalForDirectory:file: NSOKButton =
[ send\ filename CF>string ] [ drop f ] if ;