Changeset 6162


Ignore:
Timestamp:
Apr 8, 2007, 1:34:58 AM (12 years ago)
Author:
gb
Message:

Convert to the new order.
Should probably try to avoid nsstringptr, since it makes a (non-GCable)
NSConstantString.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/objc-gf/ccl/examples/cocoa-inspector.lisp

    r6130 r6162  
    5757(require "COCOA")
    5858
    59 ; This is useful when @ won't work, dynamically creating a NSString pointer from a string
     59;;; This is useful when @ won't work, dynamically creating a NSString
     60;;; pointer from a string.
     61
    6062(defun nsstringptr (string)
    6163  (objc-constant-string-nsstringptr
     
    231233(defclass inspector-table-view-data-source (ns:ns-object)
    232234    ((inspector-browser :foreign-type :id :reader inspector-browser)
    233      (inspector-window :foreign-type :id :reader inspector-browser))
     235     (inspector-window :foreign-type :id :reader inspector-window))
    234236  (:metaclass ns:+ns-object))
    235237
     
    245247;;; left doing it remains to be seen. The only other time this is
    246248;;; called AFAICT is when loadColumnZero or reloadColumn is called
    247 (define-objc-method ((:int :browser browser
    248                            :number-of-rows-in-column (:int column))
    249                            inspector-browser-delegate)
     249(objc:defmethod (#/browser:numberOfRowsInColumn: :<NSI>nteger)
     250    ((self inspector-browser-delegate)
     251     browser
     252     (column :<NSI>nteger))
    250253  (or (let* ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*))
    251               (selected-column (send browser 'selected-column)) ; probably always (1- column), when a column is selected
    252               (cinspector-column (1- selected-column)) ; 2nd column of nsbrowser <-> 1st column of cinspector
    253               (row (send browser :selected-row-in-column selected-column)))
    254         #+ignore
    255         (format t "getting length of column ~d based on row ~d in column ~d~%" column row selected-column)
    256         (cond ((not cinspector) 0)
    257                ((= column 0) 1)         ; just displaying the printed representaiton of the top inspected object
    258                ((= selected-column 0) ; selected the printed rep of the inspected object (column should = 1)
    259                 (setf (max-column cinspector) 0) ; crop object-vector in cinspector
    260                 (let ((inspector (nth-inspector cinspector 0))) ; inspector for top object
    261                   (inspector::inspector-line-count inspector)))
    262                ((>= selected-column 1) ; (-1 is the N/A column)
    263                 (setf (max-column cinspector) cinspector-column) ; crop object-vector in cinspector
    264                 (push-object (nth-object-nth-value cinspector cinspector-column row) cinspector)
    265                 (let ((inspector (nth-inspector cinspector (1+ cinspector-column)))) ; inspector for object just pushed
    266                   (inspector::inspector-line-count inspector)))))
     254             (selected-column (#/selectedColumn browser)) ; probably always (1- column), when a column is selected
     255             (cinspector-column (1- selected-column)) ; 2nd column of nsbrowser <-> 1st column of cinspector
     256             (row (#/selectedRowInColumn: browser selected-column)))
     257        #+ignore
     258        (format t "getting length of column ~d based on row ~d in column ~d~%" column row selected-column)
     259        (cond ((not cinspector) 0)
     260              ((= column 0) 1)          ; just displaying the printed representaiton of the top inspected object
     261              ((= selected-column 0)    ; selected the printed rep of the inspected object (column should = 1)
     262               (setf (max-column cinspector) 0) ; crop object-vector in cinspector
     263               (let ((inspector (nth-inspector cinspector 0))) ; inspector for top object
     264                 (inspector::inspector-line-count inspector)))
     265              ((>= selected-column 1)  ; (-1 is the N/A column)
     266               (setf (max-column cinspector) cinspector-column) ; crop object-vector in cinspector
     267               (push-object (nth-object-nth-value cinspector cinspector-column row) cinspector)
     268               (let ((inspector (nth-inspector cinspector (1+ cinspector-column)))) ; inspector for object just pushed
     269                 (inspector::inspector-line-count inspector)))))
    267270      0))
    268271
     
    282285;; In the following method defn this is unnecessary, the Browser can tell this for itself
    283286;; [cell "setLoaded:" :<BOOL> #$YES]
    284 (define-objc-method ((:void :browser browser
    285                             :will-display-cell cell
    286                             :at-row (:int row)
    287                             :column (:int column))
    288                      inspector-browser-delegate)
     287(objc:defmethod (#/browser:willDisplayCell:atRow:column: :void)
     288    ((self inspector-browser-delegate)
     289     browser
     290     cell
     291     (row :<NSI>nteger)
     292     (column :<NSI>nteger))
    289293  (declare (ignorable browser column))
    290   (handler-case-for-cocoa 2
    291    (let ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*))
     294     (let ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*))
    292295         (cinspector-column (1- column))) ; 2nd column of nsbrowser <-> 1st column of cinspector
    293296     #+ignore
     
    295298     (cond ((not cinspector) nil)
    296299           ((= column 0)
    297             (send cell :set-string-value  (nsstringptr (format nil "~s" (nth-object cinspector 0))))
    298             (send cell :set-leaf nil))
     300            (#/setStringValue: cell  (nsstringptr (format nil "~s" (nth-object cinspector 0))))
     301            (#/setLeaf: cell nil))
    299302           (t
    300303            ;; when switching between widgets to the browser, we can
    301304            ;; have reloaded a column and need to drill down a row
    302305            ;; from where we are at the moment
    303             (send cell :set-string-value  (nsstringptr (nth-object-nth-line cinspector cinspector-column row)))
     306            (#/setStringValue: cell  (nsstringptr (nth-object-nth-line cinspector cinspector-column row)))
    304307            ;; leaf-p should really consider the type of the object in
    305308            ;; question (eventually taking into account whether we're
    306             ;; brousing the class heirarchy or into objc or whatever)
    307             (send cell :set-leaf (or (leaf-node-p (nth-object cinspector cinspector-column)) ; i.e. no fields drill down
     309            ;; browsing the class heirarchy or into objc or whatever)
     310            (#/setLeaf: cell (or (leaf-node-p (nth-object cinspector cinspector-column)) ; i.e. no fields drill down
    308311                                                    (leaf-field-p (nth-object cinspector cinspector-column) row)
    309312                                                    ;; for now...
    310313                                                    (= row 0)
    311                                                     (not (nth-object-nth-value-editable cinspector cinspector-column row)))))))))
     314                                                    (not (nth-object-nth-value-editable cinspector cinspector-column row))))))))
    312315
    313316;;; when all is said and done and once the cinspector is properly
     
    320323
    321324;;; change the focus of the the table view to be the selected object
    322 (define-objc-method ((:void :browser-action sender)
    323                      inspector-browser-delegate) ; don't know why I'd want to, but could use a separate IBTarget class
     325(objc:defmethod (#/browserAction: :void)
     326    ((self inspector-browser-delegate)
     327     sender); don't know why I'd want to, but could use a separate IBTarget class
    324328  #+ignore (format t "browserAction~%")
    325     (handler-case-for-cocoa 5
    326       (let* ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*))
    327              (column (send sender 'selected-column)))
    328         (when (<= 0 column)
    329           (setf (focal-point cinspector) column)
    330           (send (inspector-table-view self) 'reload-data)
    331           #+ignore
    332           (format t "      responding to selection in column ~d~%" column)))))
     329  (let* ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*))
     330         (column (#/selectedColumn sender)))
     331    (when (<= 0 column)
     332      (setf (focal-point cinspector) column)
     333      (#/reloadData (inspector-table-view self))
     334      #+ignore
     335      (format t "      responding to selection in column ~d~%" column))))
    333336
    334337;; open a new inspector on the selected object
    335 (define-objc-method ((:void :browser-double-action sender)
    336                      inspector-browser-delegate)
     338(objc:defmethod (#/browserDoubleAction: :void)
     339    ((self inspector-browser-delegate)
     340     sender)
    337341  #+ignore (format t "browserDoubleAction~%")
    338   (handler-case-for-cocoa 6
    339     (let* ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*))
    340            (column (send sender 'selected-column)))
    341       (when (<= 0 column)
    342         ; this seems to work, but I'm not really paying attention to thread stuff...
    343         (cinspect (nth-object cinspector column))))))
    344 
    345 (define-objc-method ((:int :number-of-rows-in-table-view table-view)
    346                      inspector-table-view-data-source)
     342  (let* ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*))
     343         (column (#/selectedColumn sender)))
     344    (when (<= 0 column)
     345      ;; this seems to work, but I'm not really paying attention to
     346      ;; thread stuff...
     347      (cinspect (nth-object cinspector column)))))
     348
     349(objc:defmethod (#/numberOfRowsInTableView: :<NSI>nteger)
     350    ((self inspector-table-view-data-source)
     351     table-view)
    347352  (declare (ignore table-view))
    348   (or (handler-case-for-cocoa 3
    349       (let ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*)))
    350         (if cinspector
    351              (let ((inspector (inspector cinspector)))
    352                (inspector::inspector-line-count inspector))
    353            0)))
     353 
     354  (or (let ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*)))
     355        (if cinspector
     356          (let ((inspector (inspector cinspector)))
     357            (inspector::inspector-line-count inspector))
     358          0))
    354359      0))
    355360
    356 
    357 
    358 
    359 (define-objc-method ((:id :table-view table-view
    360                           :object-value-for-table-column table-column
    361                           :row (:int row))
    362                      inspector-table-view-data-source)
     361(objc:defmethod #/tableView:objectValueForTableColumn:row:
     362    ((self inspector-table-view-data-source)
     363     table-view
     364     table-column
     365     (row :<NSI>nteger))
    363366  (declare (ignore table-view))
    364367  (let ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*)))
    365368    (cond ((not cinspector)
    366369           #@"")
    367           ((send (send table-column 'identifier) :is-equal #@"property")
     370          ((#/isEqual: (#/identifier table-column) #@"property")
    368371           (nsstringptr (focus-nth-property cinspector row)))
    369           ((send (send table-column 'identifier) :is-equal #@"value")
     372          ((#/isEqual: (#/identifier table-column) #@"value")
    370373           (nsstringptr (focus-nth-value cinspector row))))))
    371374
    372375;; I'm hoping that the delegate will prevent this from being called willy-nilly
    373 (define-objc-method ((:void :table-view table-view
    374                             :set-object-value object
    375                             :for-table-column table-column
    376                             :row (:int row))
    377                      inspector-table-view-data-source)
     376(objc:defmethod (#/tableView:setObjectValue:forTableColumn:row: :void)
     377    ((self inspector-table-view-data-source)
     378     table-view object table-column (row :<NSI>nteger))
    378379  (declare (ignore table-column))
    379   (handler-case-for-cocoa 4
    380380   (let ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*)))
    381381     ;; without any formatters, object appears to be an NSCFString
     
    386386       (setf (focus-nth-value cinspector row)
    387387             (let ((*package* (find-package :cl-user)))
    388                ;; with-autorelease-pool could possibly be needed to autorelease the cString we're handling (I think)
    389                (eval (read-from-string (%get-cstring (send object 'c-string))))))
    390        (send table-view 'reload-data) ; really could just reload that one cell, but don't know how...
    391        ;; changing the focused object may effect the browser's path, reload its column and keep the cinspector consistent
    392        ;; Here we have to make sure that the column we're reloading and the column after both have values to display,
    393        ;; for when reloadColumn: invokes browser:willDisplayCell:atRow:column:
    394        (send (inspector-browser self) :reload-column (focal-point cinspector))
     388               ;; with-autorelease-pool could possibly be needed to
     389               ;; autorelease the cString we're handling (I think)
     390               (eval (read-from-string (lisp-string-from-nsstring object)))))
     391       (#/reloadData table-view) ; really could just reload that one cell, but don't know how...
     392       ;; changing the focused object may effect the browser's path,
     393       ;; reload its column and keep the cinspector consistent Here we
     394       ;; have to make sure that the column we're reloading and the
     395       ;; column after both have values to display, for when
     396       ;; reloadColumn: invokes browser:willDisplayCell:atRow:column:
     397       (#/reloadColumn: (inspector-browser self) (focal-point cinspector))
    395398       ;; [inspector-browser "scrollColumnToVisible:" :int (focal-point cinspector)] ; maybe need this, too
    396        ))))
    397 
    398 ; In the table view, the properties are not editable, but the
    399 ; values (if editable) allow lisp forms to be entered that are
    400 ; read and evaluated to determine the new property value.
    401 (define-objc-method ((:<BOOL> :table-view table-view
    402                               :should-edit-table-column table-column
    403                               :row (:int row))
    404                      inspector-table-view-delegate)
     399       )))
     400
     401;;; In the table view, the properties are not editable, but the
     402;;; values (if editable) allow lisp forms to be entered that are
     403;;; read and evaluated to determine the new property value.
     404(objc:defmethod (#/tableView:shouldEditTableColumn:row: :<BOOL>)
     405    ((self inspector-table-view-delegate)
     406     table-view table-column (row :<NSI>nteger))
    405407  (declare (ignore table-view))
    406408  (let ((cinspector (gethash (inspector-window self) *cocoa-inspector-nswindows-table*)))
    407409    (and cinspector
    408           (send (send table-column 'identifier) :is-equal #@"value")
    409           (/= row 0) ; in practice the reference to the object isn't editable, and the GUI semantics aren't clear anyway,
    410                      ; possibly there will come a time when I put row 0 in the table title, but I need to maintain
    411                      ; the 0-indexed focus-nth-whatever API here and elsewhere if I do that
    412           (focus-nth-value-editable cinspector row))))
     410         (#/isEqual: (#/identifier table-column) #@"value")
     411         (/= row 0)                     ; in practice the reference to
     412                                        ; the object isn't editable, and
     413                                        ; the GUI semantics aren't clear anyway,
     414                                        ; possibly there will come a
     415                                        ; time when I put row 0 in the
     416                                        ; table title, but I need to
     417                                        ; maintain the 0-indexed
     418                                        ; focus-nth-whatever API here
     419                                        ; and elsewhere if I do that
     420         (focus-nth-value-editable cinspector row))))
    413421
    414422;; the inspectorwindowcontroller is set up as the delegate of the window...
    415423;; we now eliminate the dangling pointer to the window from the hash table
    416 (define-objc-method ((:void :window-will-close notification)
    417                      inspector-window-controller)
    418   (let ((nswindow (send notification 'object)))
     424(objc:defmethod (#/windowWillClose: :void)
     425    ((self inspector-window-controller) notification)
     426  (let ((nswindow (#/object notification)))
    419427    (remhash nswindow *cocoa-inspector-nswindows-table*)))
    420428
     
    432440  (with-autorelease-pool
    433441      (let* ((windowcontroller (load-windowcontroller-from-nib 'inspector-window-controller *default-inspector-nib-pathname*))
    434              (window (send windowcontroller 'window))
     442             (window (#/window windowcontroller))
    435443             (cinspector (make-instance 'cocoa-inspector)))
    436444        ;; set up the window's initial "focused" object -- this may change as
     
    441449        (setf (gethash window *cocoa-inspector-nswindows-table*) cinspector)
    442450        (push-object object cinspector)
    443         ;; is this working? it isn't breaking, but double-clicking is being handled as two single actions
     451        ;; is this working? it isn't breaking, but double-clicking is
     452        ;; being handled as two single actions
    444453        (let* ((browser (inspector-browser windowcontroller)))
    445           (send browser
    446                 :set-double-action (@SELECTOR "browserDoubleAction:"))
    447           (send browser :set-ignores-multi-click t))
    448         (send windowcontroller :show-window window)
     454          (#/setDoubleAction: browser (@selector #/browserDoubleAction:))
     455          (#/setIgnoresMultiClick: browser t))
     456        (#/showWindow: windowcontroller window)
    449457        window)))
    450458
Note: See TracChangeset for help on using the changeset viewer.