Changeset 6709
- Timestamp:
- Jun 12, 2007, 12:56:02 PM (17 years ago)
- File:
-
- 1 edited
-
branches/ide-1.0/ccl/examples/cocoa-editor.lisp (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ide-1.0/ccl/examples/cocoa-editor.lisp
r6687 r6709 418 418 (let* ((pos (#/longValue (#/objectAtIndex: params 0))) 419 419 (n (#/longValue (#/objectAtIndex: params 1)))) 420 #+debug 420 #+debug 0 421 421 (#_NSLog #@"Note modification: pos = %d, n = %d" :int pos :int n) 422 422 (#/edited:range:changeInLength: self (logior #$NSTextStorageEditedCharacters … … 430 430 431 431 (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))) 438 439 439 440 (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))) 446 448 447 449 ;;; Return true iff we're inside a "beginEditing/endEditing" pair … … 499 501 ((self hemlock-text-storage) (index :<NSUI>nteger) (rangeptr (* :<NSR>ange))) 500 502 #+debug 501 (#_NSLog #@"Attributes at index: %d " :unsigned index)503 (#_NSLog #@"Attributes at index: %d storage %@" :unsigned index :id self) 502 504 (with-slots (cache) self 503 505 (let* ((attrs (#/attributesAtIndex:effectiveRange: cache index rangeptr))) … … 513 515 (objc:defmethod (#/replaceCharactersInRange:withString: :void) 514 516 ((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 %@" 516 518 :<NSI>nteger (pref r :<NSR>ange.location) 517 519 :<NSI>nteger (pref r :<NSR>ange.length) … … 598 600 (hi::delete-string (hi::buffer-name buffer) hi::*buffer-names*)))))) 599 601 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)) 601 618 602 619 … … 728 745 729 746 747 730 748 ;;; Access the underlying buffer in one swell foop. 731 749 (defmethod text-view-buffer ((self hemlock-text-view)) 732 750 (buffer-cache-buffer (hemlock-buffer-string-cache (#/hemlockString (#/textStorage self))))) 751 733 752 734 753 … … 1109 1128 (#/setAutoresizesSubviews: (#/contentView scrollview) t) 1110 1129 (let* ((layout (make-instance 'ns:ns-layout-manager))) 1130 #+suffer 1131 (#/setTypesetter: layout (make-instance 'hemlock-ats-typesetter)) 1111 1132 (#/addLayoutManager: textstorage layout) 1112 1133 (#/setUsesScreenFonts: layout t) … … 1134 1155 (#/setTypingAttributes: tv (aref *styles* style)) 1135 1156 (#/setSmartInsertDeleteEnabled: tv nil) 1136 (#/setAllowsUndo: tv t)1157 (#/setAllowsUndo: tv nil) ; don't want NSTextView undo 1137 1158 (#/setUsesFindPanel: tv t) 1138 1159 (#/setWidthTracksTextView: container tracks-width) … … 1167 1188 (let* ((the-hemlock-frame (#/window view)) 1168 1189 (text-view (text-pane-text-view view))) 1190 #+debug (#_NSLog #@"Activating text pane") 1169 1191 (#/makeFirstResponder: the-hemlock-frame text-view))) 1170 1192 … … 1280 1302 (:metaclass ns:+ns-object)) 1281 1303 1282 1283 1304 (defun double-%-in (string) 1284 1305 ;; Replace any % characters in string with %%, to keep them from … … 1404 1425 (call-next-method)) 1405 1426 1406 (defun new-hemlock-document-window ( )1407 (let* ((w (new-cocoa-window :class hemlock-frame1427 (defun new-hemlock-document-window (class) 1428 (let* ((w (new-cocoa-window :class class 1408 1429 :activate nil))) 1409 1430 (values w (add-pane-to-window w :reserve-below 20.0)))) … … 1419 1440 pane)))) 1420 1441 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) 1422 1443 (let* ((pane (nth-value 1423 1444 1 1424 (new-hemlock-document-window ))))1445 (new-hemlock-document-window class)))) 1425 1446 (make-scrolling-textview-for-pane pane ts container-tracks-text-view-width color style) 1426 1447 (multiple-value-bind (height width) … … 1479 1500 1480 1501 ;;; 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)) 1483 1504 (frame (#/window pane)) 1484 1505 (buffer (text-view-buffer (text-pane-text-view pane)))) … … 1499 1520 1500 1521 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) 1502 1523 (process-interrupt *cocoa-event-process* 1503 1524 #'%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)) 1505 1526 1506 1527 … … 1610 1631 (adjust-buffer-cache-for-insertion display pos n) 1611 1632 (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))) 1615 1637 (#/setAttributes:range: cache font (ns:make-ns-range pos n)) 1616 1638 #-all-in-cocoa-thread … … 1754 1776 (:metaclass ns:+ns-object)) 1755 1777 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)))) 1756 1787 1757 1788 (defmethod user-input-style ((doc hemlock-editor-document)) … … 2006 2037 (#_NSLog #@"Make window controllers") 2007 2038 (let* ((textstorage (slot-value self 'textstorage)) 2008 (window (%hemlock-frame-for-textstorage 2039 (window (%hemlock-frame-for-textstorage 2040 hemlock-frame 2009 2041 textstorage 2010 2042 *editor-columns* … … 2243 2275 (#/replaceCharactersInRange:withString: textstorage selectedrange string))))) 2244 2276 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 2245 2288 (defun hi::edit-definition (name) 2246 2289 (let* ((info (get-source-files-with-types&classes name))) … … 2310 2353 :result-callback #'(lambda (info) 2311 2354 (edit-single-definition name info)) 2312 :key #'car 2355 :display #'(lambda (item stream) 2356 (prin1 (car item) stream)) 2313 2357 :title (format nil "Definitions of ~s" name))) 2314 2358 2315 2359 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))) 2317 2365 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 2319 2392 (provide "COCOA-EDITOR")
Note:
See TracChangeset
for help on using the changeset viewer.
