source: trunk/source/cocoa-ide/app-delegate.lisp @ 9247

Last change on this file since 9247 was 9247, checked in by jaj, 12 years ago

Add a search-files dialog. If command key is held while selecting menu, a new window is created, otherwise the topmost search files dialog is brought to the front.

In inspector.nib set the window outlet.
Set inspector window titles.
Inspector sets @ @@ @@@ in the gui package to the last three items inspected, analogous to * * in the listener. Should these be in the ccl package, and exported?

In cocoa-utils add:
choose-directory-dialog
current-event-modifier-p
current-event-command-key-p
map-windows
first-window-satisfying-predicate
first-window-with-controller-type

File size: 5.3 KB
Line 
1;;;-*-Mode: LISP; Package: GUI -*-
2;;;
3;;;   Copyright (C) 2007 Clozure Associates
4
5(in-package "GUI")
6
7(defclass lisp-application-delegate (ns:ns-object)
8    ()
9  (:metaclass ns:+ns-object))
10
11;;; This method is a good place to:
12;;;  * register value transformer names
13;;;  * register default user defaults
14(objc:defmethod (#/initialize :void) ((self +lisp-application-delegate))
15  (#/setValueTransformer:forName: ns:ns-value-transformer
16                                  (make-instance 'font-to-name-transformer)
17                                  #@"FontToName")
18
19  (let* ((domain (#/standardUserDefaults ns:ns-user-defaults))
20         (initial-values (cocoa-defaults-initial-values))
21         (dict (#/mutableCopy initial-values)))
22    (#/registerDefaults: domain dict)
23    (#/release dict)
24    (update-cocoa-defaults)))
25
26(objc:defmethod (#/applicationWillFinishLaunching: :void)
27    ((self lisp-application-delegate) notification)
28  (declare (ignore notification))
29  (initialize-user-interface)
30  (let* ((c (#/init (#/alloc console-window))))
31    (unless (%null-ptr-p c)
32      (setf (console *nsapp*) c))))
33
34(objc:defmethod (#/applicationWillTerminate: :void)
35                ((self lisp-application-delegate) notification)
36  (declare (ignore notification))
37  ;; UI has decided to quit; terminate other lisp threads.
38  (ccl::prepare-to-quit))
39
40(defloadvar *preferences-window-controller* nil)
41
42(objc:defmethod (#/showPreferences: :void) ((self lisp-application-delegate)
43                                            sender)
44  (declare (ignore sender))
45  (when (null *preferences-window-controller*)
46    (setf *preferences-window-controller*
47          (make-instance 'preferences-window-controller)))
48  (#/showWindow: *preferences-window-controller* self))
49
50(defloadvar *processes-window-controller* nil)
51
52(objc:defmethod (#/showProcessesWindow: :void) ((self lisp-application-delegate)
53                                                sender)
54  (declare (ignore sender))
55  (when (null *processes-window-controller*)
56    (setf *processes-window-controller*
57          (make-instance 'processes-window-controller)))
58  (#/showWindow: *processes-window-controller* self))
59
60(defloadvar *apropos-window-controller* nil)
61
62(objc:defmethod (#/showAproposWindow: :void) ((self lisp-application-delegate)
63                                                sender)
64  (declare (ignore sender))
65  (when (null *apropos-window-controller*)
66    (setf *apropos-window-controller*
67          (make-instance 'apropos-window-controller)))
68  (#/showWindow: *apropos-window-controller* self))
69
70(objc:defmethod (#/showSearchFiles: :void) ((self lisp-application-delegate)
71                                            sender)
72  ;;If command key is pressed, always make a new window
73  ;;otherwise bring frontmost search files window to the front
74  (declare (ignore sender))
75  (let ((w nil))
76    (if (or (current-event-command-key-p)
77            (null (setf w (first-window-with-controller-type 'search-files-window-controller))))
78      (let* ((wc (make-instance 'search-files-window-controller)))
79        (setf w (#/window wc))
80        (#/setWindowController: w wc))
81      (#/makeKeyAndOrderFront: w self))))
82
83(objc:defmethod (#/newListener: :void) ((self lisp-application-delegate)
84                                        sender)
85  (declare (ignore sender))
86  (#/openUntitledDocumentOfType:display:
87   (#/sharedDocumentController ns:ns-document-controller) #@"Listener" t))
88
89(objc:defmethod (#/showListener: :void) ((self lisp-application-delegate)
90                                        sender)
91  (declare (ignore sender))
92  (let* ((all-windows (#/orderedWindows *NSApp*))
93         (key-window (#/keyWindow *NSApp*))
94         (listener-windows ())
95         (top-listener nil))
96    (dotimes (i (#/count all-windows))
97      (let* ((w (#/objectAtIndex: all-windows i))
98             (wc (#/windowController w)))
99        (when (eql (#/class wc) hemlock-listener-window-controller)
100          (push w listener-windows))))
101    (setq listener-windows (nreverse listener-windows))
102    (setq top-listener (car listener-windows))
103    (cond 
104     ((null listener-windows)
105      (#/newListener: self +null-ptr+))
106     ((eql key-window top-listener)
107      ;; The current window is a listener.  If there is more than
108      ;; one listener, bring the rear-most forward.
109      (let* ((w (car (last listener-windows))))
110        (if (eql top-listener w)
111          (#_NSBeep)
112          (#/makeKeyAndOrderFront: w +null-ptr+))))
113     (t
114      (#/makeKeyAndOrderFront: top-listener +null-ptr+)))))
115
116(objc:defmethod (#/ensureListener: :void) ((self lisp-application-delegate)
117                                           sender)
118  (declare (ignore sender))
119  (let ((top-listener-document (#/topListener hemlock-listener-document)))
120    (when (eql top-listener-document +null-ptr+)
121      (let* ((dc (#/sharedDocumentController ns:ns-document-controller))
122             (wc nil))
123        (setq top-listener-document
124              (#/makeUntitledDocumentOfType:error: dc #@"Listener" +null-ptr+))
125        (#/addDocument: dc top-listener-document)
126        (#/makeWindowControllers top-listener-document)
127        (setq wc (#/lastObject (#/windowControllers top-listener-document)))
128        (#/orderFront: (#/window wc) +null-ptr+)))))
129
130(defvar *cocoa-application-finished-launching* (make-semaphore)
131  "Semaphore that's signaled when the application's finished launching ...")
132
133(objc:defmethod (#/applicationDidFinishLaunching: :void)
134    ((self lisp-application-delegate) notification)
135  (declare (ignore notification))
136  (signal-semaphore *cocoa-application-finished-launching*))
137
138(objc:defmethod (#/applicationOpenUntitledFile: :<BOOL>)
139    ((self lisp-application-delegate) app)
140  (when (zerop *cocoa-listener-count*)
141    (#/newListener: self app)
142    t))
Note: See TracBrowser for help on using the repository browser.