Working on a Cocoa 'Run...' dialog

slava 2006-05-19 03:07:40 +00:00
parent 196c41e919
commit 31c429aabb
8 changed files with 51 additions and 11 deletions

View File

@ -6,6 +6,13 @@ namespaces sequences ;
TYPEDEF: int CFIndex TYPEDEF: int CFIndex
FUNCTION: void* CFArrayGetValueAtIndex ( void* array, CFIndex idx ) ;
FUNCTION: CFIndex CFArrayGetCount ( void* array ) ;
: CF>array ( alien -- array )
dup CFArrayGetCount [ CFArrayGetValueAtIndex ] map-with ;
! Core Foundation utilities -- will be moved elsewhere ! Core Foundation utilities -- will be moved elsewhere
: kCFURLPOSIXPathStyle 0 ; : kCFURLPOSIXPathStyle 0 ;

View File

@ -0,0 +1,20 @@
! Copyright (C) 2006 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
IN: cocoa
USING: kernel objc-NSObject objc-NSOpenPanel objc-NSSavePanel
sequences ;
: <NSOpenPanel> ( -- panel )
NSOpenPanel [openPanel]
dup 1 [setCanChooseFiles:]
dup 0 [setCanChooseDirectories:]
dup 1 [setResolvesAliases:]
dup 1 [setAllowsMultipleSelection:]
[autorelease] ;
: NSOKButton 1 ;
: NSCancelButton 0 ;
: open-panel ( -- paths )
<NSOpenPanel> dup f [runModalForTypes:] NSOKButton =
[ [filenames] CF>array [ CF>string ] map ] [ f ] if ;

View File

@ -19,6 +19,8 @@ USING: cocoa compiler io kernel objc sequences words ;
"NSObject" "NSObject"
"NSOpenGLContext" "NSOpenGLContext"
"NSOpenGLView" "NSOpenGLView"
"NSOpenPanel"
"NSSavePanel"
"NSView" "NSView"
"NSWindow" "NSWindow"
} [ } [

View File

@ -11,6 +11,7 @@ USING: compiler io parser sequences words ;
"/library/cocoa/application-utils.factor" "/library/cocoa/application-utils.factor"
"/library/cocoa/window-utils.factor" "/library/cocoa/window-utils.factor"
"/library/cocoa/view-utils.factor" "/library/cocoa/view-utils.factor"
"/library/cocoa/dialogs.factor"
"/library/cocoa/menu-bar.factor" "/library/cocoa/menu-bar.factor"
"/library/cocoa/ui.factor" "/library/cocoa/ui.factor"
} [ } [

View File

@ -82,6 +82,8 @@ DEFER: described-menu
! ------------------------------------------------------------------------- ! -------------------------------------------------------------------------
: menu-run-file ( -- )
open-panel [ listener-run-files ] when* ;
: default-main-menu : default-main-menu
{ {
@ -98,18 +100,19 @@ DEFER: described-menu
{ "Hide Others" "hideOtherApplications:" "h" [ and-option-equivalent-modifier ] } { "Hide Others" "hideOtherApplications:" "h" [ and-option-equivalent-modifier ] }
{ "Show All" "unhideAllApplications:" "" } { "Show All" "unhideAllApplications:" "" }
{ } { }
{ "Save Image" save "s" }
{ }
{ "Quit" "terminate:" "q" } { "Quit" "terminate:" "q" }
} [ NSApp over [setAppleMenu:] ] } } [ NSApp over [setAppleMenu:] ] }
{ { { {
! Tools is standing in for the File menu "File"
"Tools"
{ "Listener" listener-window "n" } { "Listener" listener-window "n" }
{ "Run..." menu-run-file "o" }
{ }
{ "Apropos" apropos-window "r" } { "Apropos" apropos-window "r" }
{ "Vocabularies" vocabs-window "y" } { "Vocabularies" vocabs-window "" }
{ "Globals" global-window "u" } { "Globals" global-window "" }
{ "Memory" memory-window "m" } { "Memory" memory-window "" }
{ }
{ "Save Image" save "s" }
} } } }
{ { { {
"Edit" "Edit"

View File

@ -120,7 +120,7 @@ DEFER: describe
] with-scope ; ] with-scope ;
: callstack. ( seq -- seq ) : callstack. ( seq -- seq )
3 swap group [ first2 callframe. ] each ; 3 swap group <reversed> [ first2 callframe. ] each ;
: .c callstack callstack. ; : .c callstack callstack. ;

View File

@ -47,7 +47,7 @@ TUPLE: listener-gadget pane stack ;
: <stack-bar> ( -- gadget ) <shelf> dup highlight-theme ; : <stack-bar> ( -- gadget ) <shelf> dup highlight-theme ;
: start-listener ( listener -- ) : start-listener ( listener -- )
[ >r clear r> listener-thread ] in-thread ; [ >r clear r> listener-thread ] in-thread drop ;
C: listener-gadget ( -- gadget ) C: listener-gadget ( -- gadget )
dup delegate>frame dup delegate>frame
@ -64,3 +64,10 @@ M: listener-gadget focusable-child* ( listener -- gadget )
: listener-window ( -- ) : listener-window ( -- )
<listener-gadget> "Listener" open-window ; <listener-gadget> "Listener" open-window ;
: listener-window* ( quot -- )
<listener-gadget> [ listener-gadget-pane pane-call ] keep
"Listener" open-window ;
: listener-run-files ( seq -- )
[ [ run-file ] each ] curry listener-window* ;

View File

@ -4,7 +4,7 @@ IN: gadgets-panes
USING: arrays gadgets gadgets-buttons gadgets-editors USING: arrays gadgets gadgets-buttons gadgets-editors
gadgets-labels gadgets-layouts gadgets-scrolling gadgets-theme gadgets-labels gadgets-layouts gadgets-scrolling gadgets-theme
generic hashtables io kernel line-editor math namespaces generic hashtables io kernel line-editor math namespaces
sequences strings styles threads ; prettyprint sequences strings styles threads ;
! A pane is an area that can display text. ! A pane is an area that can display text.
@ -38,7 +38,7 @@ continuation scrolls? ;
SYMBOL: structured-input SYMBOL: structured-input
: pane-call ( quot pane -- ) : pane-call ( quot pane -- )
"<< command >>" over stream-print dup [ "Command: " write over . ] with-stream*
>r structured-input set-global >r structured-input set-global
"\"structured-input\" \"gadgets-panes\" lookup get-global call" "\"structured-input\" \"gadgets-panes\" lookup get-global call"
r> pane-eval ; r> pane-eval ;