2006-03-12 23:21:01 -05:00
|
|
|
! Copyright (C) 2006 Slava Pestov.
|
2006-03-17 02:50:16 -05:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2006-05-29 05:19:51 -04:00
|
|
|
IN: objc-classes
|
2006-05-24 18:40:54 -04:00
|
|
|
DEFER: FactorApplicationDelegate
|
2006-03-14 21:09:25 -05:00
|
|
|
|
2006-05-24 18:40:54 -04:00
|
|
|
IN: cocoa
|
2006-10-13 22:49:14 -04:00
|
|
|
USING: arrays gadgets gadgets-listener gadgets-help
|
|
|
|
gadgets-workspace hashtables kernel memory namespaces objc
|
|
|
|
sequences errors freetype help ;
|
2006-03-17 02:50:16 -05:00
|
|
|
|
2006-05-24 18:40:54 -04:00
|
|
|
: finder-run-files ( alien -- )
|
2006-07-02 18:51:57 -04:00
|
|
|
#! We filter out the image name since that might be there on
|
|
|
|
#! first launch.
|
|
|
|
CF>string-array [ image = not ] subset listener-run-files
|
2006-05-24 18:40:54 -04:00
|
|
|
NSApp NSApplicationDelegateReplySuccess
|
2006-05-29 05:19:51 -04:00
|
|
|
-> replyToOpenOrPrint: ;
|
2006-03-12 23:21:01 -05:00
|
|
|
|
2006-10-13 22:49:14 -04:00
|
|
|
: menu-run-files ( -- )
|
|
|
|
open-panel [ listener-run-files ] when* ;
|
|
|
|
|
2006-10-13 23:06:33 -04:00
|
|
|
: menu-save-image ( -- )
|
|
|
|
image save-panel [ save-image ] when* ;
|
|
|
|
|
2006-05-24 18:40:54 -04:00
|
|
|
! Handle Open events from the Finder
|
|
|
|
"NSObject" "FactorApplicationDelegate" {
|
|
|
|
{ "application:openFiles:" "void" { "id" "SEL" "id" "id" }
|
|
|
|
[ >r 3drop r> finder-run-files ]
|
2006-04-10 15:03:41 -04:00
|
|
|
}
|
2006-10-13 22:49:14 -04:00
|
|
|
|
2006-10-13 23:06:33 -04:00
|
|
|
{ "newFactorWorkspace:" "id" { "id" "SEL" "id" }
|
|
|
|
[ 3drop workspace-window f ]
|
|
|
|
}
|
|
|
|
|
2006-10-13 22:49:14 -04:00
|
|
|
{ "runFactorFile:" "id" { "id" "SEL" "id" }
|
|
|
|
[ 3drop menu-run-files f ]
|
|
|
|
}
|
|
|
|
|
2006-10-13 23:06:33 -04:00
|
|
|
{ "saveFactorImage:" "id" { "id" "SEL" "id" }
|
|
|
|
[ 3drop save f ]
|
|
|
|
}
|
|
|
|
|
|
|
|
{ "saveFactorImageAs:" "id" { "id" "SEL" "id" }
|
|
|
|
[ 3drop menu-save-image f ]
|
2006-10-13 22:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{ "showFactorHelp:" "id" { "id" "SEL" "id" }
|
|
|
|
[ 3drop "handbook" <link> help-gadget call-tool f ]
|
|
|
|
}
|
2006-10-13 20:37:14 -04:00
|
|
|
} define-objc-class
|
2006-04-10 15:03:41 -04:00
|
|
|
|
2006-05-24 18:40:54 -04:00
|
|
|
: install-app-delegate ( -- )
|
2006-05-28 20:28:26 -04:00
|
|
|
NSApp FactorApplicationDelegate install-delegate ;
|
2006-04-10 15:03:41 -04:00
|
|
|
|
2006-10-13 22:49:14 -04:00
|
|
|
: load-nib ( -- )
|
|
|
|
NSBundle
|
|
|
|
"Factor.nib" <NSString> NSApp -> loadNibNamed:owner:
|
|
|
|
drop ;
|
|
|
|
|
2006-06-02 16:28:57 -04:00
|
|
|
: init-cocoa ( -- )
|
2006-10-13 22:49:14 -04:00
|
|
|
load-nib
|
2006-05-24 19:34:30 -04:00
|
|
|
install-app-delegate
|
|
|
|
register-services
|
2006-10-13 21:45:55 -04:00
|
|
|
init-clipboard ;
|
2006-05-24 19:34:30 -04:00
|
|
|
|
2006-05-27 17:39:38 -04:00
|
|
|
: rect>NSRect
|
|
|
|
dup world-loc first2 rot rect-dim first2 <NSRect> ;
|
|
|
|
|
2006-05-26 02:29:44 -04:00
|
|
|
: gadget-window ( world -- )
|
|
|
|
[
|
2006-05-27 17:39:38 -04:00
|
|
|
dup <FactorView>
|
|
|
|
dup rot rect>NSRect <ViewWindow>
|
2006-05-26 02:29:44 -04:00
|
|
|
dup install-window-delegate
|
2006-05-29 05:19:51 -04:00
|
|
|
over -> release
|
2006-05-26 02:29:44 -04:00
|
|
|
2array
|
|
|
|
] keep set-world-handle ;
|
|
|
|
|
2006-03-18 02:23:57 -05:00
|
|
|
IN: gadgets
|
2006-05-26 02:29:44 -04:00
|
|
|
|
|
|
|
: set-title ( string world -- )
|
2006-05-29 05:19:51 -04:00
|
|
|
world-handle second swap <NSString> -> setTitle: ;
|
2006-03-18 02:23:57 -05:00
|
|
|
|
2006-05-26 02:29:44 -04:00
|
|
|
: open-window* ( world -- )
|
2006-05-27 17:39:38 -04:00
|
|
|
dup gadget-window
|
|
|
|
dup start-world
|
2006-05-29 05:19:51 -04:00
|
|
|
world-handle second f -> makeKeyAndOrderFront: ;
|
2006-03-18 02:23:57 -05:00
|
|
|
|
2006-06-29 00:25:35 -04:00
|
|
|
: raise-window ( world -- )
|
2006-06-29 01:53:55 -04:00
|
|
|
world-handle second dup f -> orderFront: -> makeKeyWindow ;
|
2006-06-29 00:25:35 -04:00
|
|
|
|
2006-03-21 03:04:36 -05:00
|
|
|
: select-gl-context ( handle -- )
|
2006-05-29 05:19:51 -04:00
|
|
|
first -> openGLContext -> makeCurrentContext ;
|
2006-03-21 03:04:36 -05:00
|
|
|
|
|
|
|
: flush-gl-context ( handle -- )
|
2006-05-29 05:19:51 -04:00
|
|
|
first -> openGLContext -> flushBuffer ;
|
2006-03-21 03:04:36 -05:00
|
|
|
|
2006-08-28 04:03:09 -04:00
|
|
|
: running.app? ( -- ? )
|
|
|
|
#! Test if we're running Factor.app.
|
|
|
|
"Factor.app"
|
|
|
|
NSBundle -> mainBundle -> bundlePath CF>string
|
|
|
|
subseq? ;
|
|
|
|
|
2006-03-15 01:20:59 -05:00
|
|
|
IN: shells
|
2006-03-15 00:57:02 -05:00
|
|
|
|
2006-03-14 21:09:25 -05:00
|
|
|
: ui
|
2006-03-19 15:43:40 -05:00
|
|
|
running.app? [
|
|
|
|
"The Factor UI requires you to run the supplied Factor.app." throw
|
|
|
|
] unless
|
2006-03-13 00:41:59 -05:00
|
|
|
[
|
2006-03-14 21:09:25 -05:00
|
|
|
[
|
2006-06-02 16:28:57 -04:00
|
|
|
init-timers
|
|
|
|
init-cocoa
|
2006-05-27 17:39:38 -04:00
|
|
|
restore-windows? [
|
|
|
|
restore-windows
|
|
|
|
] [
|
2006-06-02 16:28:57 -04:00
|
|
|
init-ui
|
2006-08-26 17:13:24 -04:00
|
|
|
workspace-window
|
2006-08-27 19:02:16 -04:00
|
|
|
drop
|
2006-05-27 17:39:38 -04:00
|
|
|
] if
|
2006-03-17 02:50:16 -05:00
|
|
|
finish-launching
|
2006-03-14 21:09:25 -05:00
|
|
|
event-loop
|
|
|
|
] with-cocoa
|
|
|
|
] with-freetype ;
|
2006-03-19 18:00:07 -05:00
|
|
|
|
2006-08-25 00:40:39 -04:00
|
|
|
IN: command-line
|
2006-03-19 18:00:07 -05:00
|
|
|
|
|
|
|
: default-shell running.app? "ui" "tty" ? ;
|