Changeset 6709


Ignore:
Timestamp:
Jun 12, 2007, 12:56:02 PM (17 years ago)
Author:
Gary Byers
Message:

Mostly commented-out debugging stuff. listener windows have their
own class (for cmd-L), hyperspec lookup.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ide-1.0/ccl/examples/cocoa-editor.lisp

    r6687 r6709  
    418418  (let* ((pos (#/longValue (#/objectAtIndex: params 0)))
    419419         (n (#/longValue (#/objectAtIndex: params 1))))
    420     #+debug
     420    #+debug 0
    421421    (#_NSLog #@"Note modification: pos = %d, n = %d" :int pos :int n)
    422422    (#/edited:range:changeInLength: self (logior #$NSTextStorageEditedCharacters
     
    430430
    431431(objc:defmethod (#/beginEditing :void) ((self hemlock-text-storage))
    432   #+debug
    433   (#_NSLog #@"begin-editing")
    434   (incf (slot-value self 'edit-count))
    435   #+debug
    436   (#_NSLog #@"after beginEditing edit-count now = %d" :int (slot-value self 'edit-count))
    437   (call-next-method))
     432  (with-slots (edit-count) self
     433    #+debug
     434    (#_NSLog #@"begin-editing")
     435    (incf edit-count)
     436    #+debug
     437    (#_NSLog #@"after beginEditing on %@ edit-count now = %d" :id self :int edit-count)
     438    (call-next-method)))
    438439
    439440(objc:defmethod (#/endEditing :void) ((self hemlock-text-storage))
    440   #+debug
    441   (#_NSLog #@"end-editing")
    442   (call-next-method)
    443   (decf (slot-value self 'edit-count))
    444   #+debug
    445   (#_NSLog #@"after endEditing edit-count now = %d" :int (slot-value self 'edit-count)))
     441  (with-slots (edit-count) self
     442    #+debug
     443    (#_NSLog #@"end-editing")
     444    (call-next-method)
     445    (decf edit-count)
     446    #+debug
     447    (#_NSLog #@"after endEditing on %@, edit-count now = %d" :id self :int edit-count)))
    446448
    447449;;; Return true iff we're inside a "beginEditing/endEditing" pair
     
    499501    ((self hemlock-text-storage) (index :<NSUI>nteger) (rangeptr (* :<NSR>ange)))
    500502  #+debug
    501   (#_NSLog #@"Attributes at index: %d" :unsigned index)
     503  (#_NSLog #@"Attributes at index: %d storage %@" :unsigned index :id self)
    502504  (with-slots (cache) self
    503505    (let* ((attrs (#/attributesAtIndex:effectiveRange: cache index rangeptr)))
     
    513515(objc:defmethod (#/replaceCharactersInRange:withString: :void)
    514516    ((self hemlock-text-storage) (r :<NSR>ange) string)
    515   #+debug  (#_NSLog #@"Replace in range %ld/%ld with %@"
     517  #+debug (#_NSLog #@"Replace in range %ld/%ld with %@"
    516518                    :<NSI>nteger (pref r :<NSR>ange.location)
    517519                    :<NSI>nteger (pref r :<NSR>ange.length)
     
    598600         (hi::delete-string (hi::buffer-name buffer) hi::*buffer-names*))))))
    599601
    600      
     602
     603
     604;;; Mostly experimental, so that we can see what happens when a
     605;;; real typesetter is used.
     606(defclass hemlock-ats-typesetter (ns:ns-ats-typesetter)
     607    ()
     608  (:metaclass ns:+ns-object))
     609
     610(objc:defmethod (#/layoutGlyphsInLayoutManager:startingAtGlyphIndex:maxNumberOfLineFragments:nextGlyphIndex: :void)
     611    ((self hemlock-ats-typesetter)
     612     layout-manager
     613     (start-index :<NSUI>nteger)
     614     (max-lines :<NSUI>nteger)
     615     (next-index (:* :<NSUI>nteger)))
     616  (#_NSLog #@"layoutGlyphs: start = %d, maxlines = %d" :int start-index :int max-lines)
     617  (call-next-method layout-manager start-index max-lines next-index))
    601618
    602619
     
    728745
    729746
     747
    730748;;; Access the underlying buffer in one swell foop.
    731749(defmethod text-view-buffer ((self hemlock-text-view))
    732750  (buffer-cache-buffer (hemlock-buffer-string-cache (#/hemlockString (#/textStorage self)))))
     751
    733752
    734753
     
    11091128    (#/setAutoresizesSubviews: (#/contentView scrollview) t)
    11101129    (let* ((layout (make-instance 'ns:ns-layout-manager)))
     1130      #+suffer
     1131      (#/setTypesetter: layout (make-instance 'hemlock-ats-typesetter))
    11111132      (#/addLayoutManager: textstorage layout)
    11121133      (#/setUsesScreenFonts: layout t)
     
    11341155                (#/setTypingAttributes: tv (aref *styles* style))
    11351156                (#/setSmartInsertDeleteEnabled: tv nil)
    1136                 (#/setAllowsUndo: tv t)
     1157                (#/setAllowsUndo: tv nil) ; don't want NSTextView undo
    11371158                (#/setUsesFindPanel: tv t)
    11381159                (#/setWidthTracksTextView: container tracks-width)
     
    11671188  (let* ((the-hemlock-frame (#/window view))
    11681189         (text-view (text-pane-text-view view)))
     1190    #+debug (#_NSLog #@"Activating text pane")
    11691191    (#/makeFirstResponder: the-hemlock-frame text-view)))
    11701192
     
    12801302  (:metaclass ns:+ns-object))
    12811303
    1282 
    12831304(defun double-%-in (string)
    12841305  ;; Replace any % characters in string with %%, to keep them from
     
    14041425  (call-next-method))
    14051426 
    1406 (defun new-hemlock-document-window ()
    1407   (let* ((w (new-cocoa-window :class hemlock-frame
     1427(defun new-hemlock-document-window (class)
     1428  (let* ((w (new-cocoa-window :class class
    14081429                              :activate nil)))
    14091430      (values w (add-pane-to-window w :reserve-below 20.0))))
     
    14191440        pane))))
    14201441
    1421 (defun textpane-for-textstorage (ts ncols nrows container-tracks-text-view-width color style)
     1442(defun textpane-for-textstorage (class ts ncols nrows container-tracks-text-view-width color style)
    14221443  (let* ((pane (nth-value
    14231444                1
    1424                 (new-hemlock-document-window))))
     1445                (new-hemlock-document-window class))))
    14251446    (make-scrolling-textview-for-pane pane ts container-tracks-text-view-width color style)
    14261447    (multiple-value-bind (height width)
     
    14791500
    14801501;;; This function must run in the main event thread.
    1481 (defun %hemlock-frame-for-textstorage (ts ncols nrows container-tracks-text-view-width color style)
    1482   (let* ((pane (textpane-for-textstorage ts ncols nrows container-tracks-text-view-width color style))
     1502(defun %hemlock-frame-for-textstorage (class ts ncols nrows container-tracks-text-view-width color style)
     1503  (let* ((pane (textpane-for-textstorage class ts ncols nrows container-tracks-text-view-width color style))
    14831504         (frame (#/window pane))
    14841505         (buffer (text-view-buffer (text-pane-text-view pane))))
     
    14991520
    15001521
    1501 (defun hemlock-frame-for-textstorage (ts ncols nrows container-tracks-text-view-width color style)
     1522(defun hemlock-frame-for-textstorage (class ts ncols nrows container-tracks-text-view-width color style)
    15021523  (process-interrupt *cocoa-event-process*
    15031524                     #'%hemlock-frame-for-textstorage
    1504                      ts  ncols nrows container-tracks-text-view-width color style))
     1525                     class ts  ncols nrows container-tracks-text-view-width color style))
    15051526
    15061527
     
    16101631          (adjust-buffer-cache-for-insertion display pos n)
    16111632          (update-line-cache-for-index display pos)
    1612           (#/replaceCharactersInRange:withString:
    1613            cache (ns:make-ns-range pos 0)
    1614            (#/substringWithRange: hemlock-string (ns:make-ns-range pos n)))
     1633          (let* ((replacestring (#/substringWithRange: hemlock-string (ns:make-ns-range pos n))))
     1634            (ns:with-ns-range (replacerange pos 0)
     1635              (#/replaceCharactersInRange:withString:
     1636               cache replacerange replacestring)))
    16151637          (#/setAttributes:range: cache font (ns:make-ns-range pos n))
    16161638          #-all-in-cocoa-thread
     
    17541776  (:metaclass ns:+ns-object))
    17551777
     1778
     1779(objc:defmethod (#/validateMenuItem: :<BOOL>)
     1780    ((self hemlock-editor-document) item)
     1781  (let* ((action (#/action item)))
     1782    (#_NSLog #@"action = %s" :address action)
     1783    (if (eql action (@selector #/hyperSpecLookUp:))
     1784      ;;; For now, demand a selection.
     1785      (not (eql 0 (ns:ns-range-length (#/selectedRange self))))
     1786      (call-next-method item))))
    17561787
    17571788(defmethod user-input-style ((doc hemlock-editor-document))
     
    20062037  (#_NSLog #@"Make window controllers")
    20072038  (let* ((textstorage  (slot-value self 'textstorage))
    2008          (window (%hemlock-frame-for-textstorage
     2039         (window (%hemlock-frame-for-textstorage
     2040                  hemlock-frame
    20092041                  textstorage
    20102042                  *editor-columns*
     
    22432275        (#/replaceCharactersInRange:withString: textstorage selectedrange string)))))
    22442276
     2277(objc:defmethod (#/hyperSpecLookUp: :void)
     2278    ((self hemlock-text-view) sender)
     2279  (declare (ignore sender))
     2280  (let* ((range (#/selectedRange self)))
     2281    (unless (eql 0 (ns:ns-range-length range))
     2282      (let* ((string (nstring-upcase (lisp-string-from-nsstring (#/substringWithRange: (#/string (#/textStorage self)) range)))))
     2283        (multiple-value-bind (symbol win) (find-symbol string "CL")
     2284          (when win
     2285            (lookup-hyperspec-symbol symbol self)))))))
     2286
     2287
    22452288(defun hi::edit-definition (name)
    22462289  (let* ((info (get-source-files-with-types&classes name)))
     
    23102353                 :result-callback #'(lambda (info)
    23112354                                      (edit-single-definition name info))
    2312                  :key #'car
     2355                 :display #'(lambda (item stream)
     2356                              (prin1 (car item) stream))
    23132357                 :title (format nil "Definitions of ~s" name)))
    23142358
    23152359                                       
    2316  
     2360(objc:defmethod (#/documentClassForType: :<C>lass) ((self hemlock-document-controller)
     2361                                         type)
     2362  (if (#/isEqualToString: type #@"html")
     2363    display-document
     2364    (call-next-method type)))
    23172365     
    2318  
     2366
     2367(objc:defmethod #/newDisplayDocumentWithTitle:content:
     2368    ((self hemlock-document-controller)
     2369     title
     2370     string)
     2371  (let* ((doc (#/makeUntitledDocumentOfType:error: self #@"html" +null-ptr+)))
     2372    (unless (%null-ptr-p doc)
     2373      (#/addDocument: self doc)
     2374      (#/makeWindowControllers doc)
     2375      (let* ((window (#/window (#/objectAtIndex: (#/windowControllers doc) 0))))
     2376        (#/setTitle: window title)
     2377        (let* ((tv (slot-value doc 'text-view))
     2378               (lm (#/layoutManager tv))
     2379               (ts (#/textStorage lm)))
     2380          (#/beginEditing ts)
     2381          (#/replaceCharactersInRange:withAttributedString:
     2382           ts
     2383           (ns:make-ns-range 0 (#/length ts))
     2384           string)
     2385          (#/endEditing ts))
     2386        (#/makeKeyAndOrderFront:
     2387         window
     2388         self)))))
     2389
     2390
     2391
    23192392(provide "COCOA-EDITOR")
Note: See TracChangeset for help on using the changeset viewer.