Changeset 7363


Ignore:
Timestamp:
Oct 5, 2007, 5:10:32 PM (12 years ago)
Author:
gz
Message:

add assume-cocoa-thread and assume-not-editing fns, sprinkle calls around, by default these are noops but one can turn them on to try to debug ticket #41.

Location:
trunk/ccl/cocoa-ide
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/cocoa-ide/cocoa-editor.lisp

    r7269 r7363  
    385385;;; Return true iff we're inside a "beginEditing/endEditing" pair
    386386(objc:defmethod (#/editingInProgress :<BOOL>) ((self hemlock-text-storage))
     387  ;; This is meaningless outside the event thread, since you can't tell what
     388  ;; other edit-count changes have already been queued up for execution on
     389  ;; the event thread before it gets to whatever you might queue up next.
     390  (assume-cocoa-thread)
    387391  (> (slot-value self 'edit-count) 0))
     392
     393(defmethod assume-not-editing ((ts hemlock-text-storage))
     394  #+debug (assert (eql (slot-value ts 'edit-count) 0)))
    388395
    389396(defun textstorage-note-insertion-at-position (self pos n)
     
    401408                                                                  (extra :<NSI>nteger))
    402409  (declare (ignorable extra))
     410  (assume-cocoa-thread)
    403411  (let* ((mirror (#/mirror self))
    404412         (hemlock-string (#/hemlockString self))
     
    487495         
    488496(objc:defmethod (#/beginEditing :void) ((self hemlock-text-storage))
     497  (assume-cocoa-thread)
    489498  (with-slots (edit-count) self
    490499    #+debug
     
    496505
    497506(objc:defmethod (#/endEditing :void) ((self hemlock-text-storage))
     507  (assume-cocoa-thread)
    498508  (with-slots (edit-count) self
    499509    #+debug
    500510    (#_NSLog #@"end-editing")
    501511    (call-next-method)
     512    (assert (> edit-count 0))
    502513    (decf edit-count)
    503514    #+debug
     
    608619           (document (if buffer (hi::buffer-document buffer)))
    609620           (textstorage (if document (slot-value document 'textstorage))))
    610       (when textstorage (#/beginEditing textstorage))
     621      #+gz (unless (eql textstorage self) (break "why is self.ne.textstorage?"))
     622      (when textstorage
     623        (assume-cocoa-thread)
     624        (#/beginEditing textstorage))
    611625      (setf (hi::buffer-region-active buffer) nil)
    612626      (hi::with-mark ((start point :right-inserting))
     
    654668;;; This needs to happen on the main thread.
    655669(objc:defmethod (#/ensureSelectionVisible :void) ((self hemlock-text-storage))
     670  (assume-cocoa-thread)
    656671  (for-each-textview-using-storage
    657672   self
    658673   #'(lambda (tv)
     674       (assume-not-editing tv)
    659675       (#/scrollRangeToVisible: tv (#/selectedRange tv)))))
    660676
     
    713729     (peer :foreign-type :id))
    714730  (:metaclass ns:+ns-object))
     731
     732
     733(defmethod assume-not-editing ((tv hemlock-textstorage-text-view))
     734  (assume-not-editing (#/textStorage tv)))
    715735
    716736(objc:defmethod (#/changeColor: :void) ((self hemlock-textstorage-text-view)
     
    829849                 (length :int)
    830850                 (affinity :<NSS>election<A>ffinity))
     851  (assume-cocoa-thread)
    831852  (when (eql length 0)
    832853    (update-blink self))
     
    839860                                affinity
    840861                                nil)
     862        (assume-not-editing self)
    841863        (#/scrollRangeToVisible: self range)
    842864        (when (> length 0)
     
    14401462
    14411463(objc:defmethod (#/activateHemlockView :void) ((self echo-area-view))
     1464  (assume-cocoa-thread)
    14421465  (let* ((the-hemlock-frame (#/window self)))
    14431466    #+debug
     
    14561479
    14571480(defmethod deactivate-hemlock-view ((self echo-area-view))
     1481  (assume-cocoa-thread)
    14581482  #+debug (#_NSLog #@"deactivating echo area")
    14591483  (let* ((ts (#/textStorage self)))
     
    17811805;;; This function must run in the main event thread.
    17821806(defun %hemlock-frame-for-textstorage (class ts ncols nrows container-tracks-text-view-width color style)
     1807  (assume-cocoa-thread)
    17831808  (let* ((pane (textpane-for-textstorage class ts ncols nrows container-tracks-text-view-width color style))
    17841809         (frame (#/window pane))
     
    18221847(defun hi::unlock-buffer (b)
    18231848  (release-lock (hi::buffer-gap-context-lock (hi::buffer-gap-context b))))
    1824  
     1849
    18251850(defun hi::document-begin-editing (document)
    18261851  (#/performSelectorOnMainThread:withObject:waitUntilDone:
     
    18311856
    18321857(defun document-edit-level (document)
     1858  (assume-cocoa-thread) ;; see comment in #/editingInProgress
    18331859  (slot-value (slot-value document 'textstorage) 'edit-count))
    18341860
     
    20252051  (#/updateChangeCount: self #$NSChangeCleared))
    20262052
     2053(defmethod assume-not-editing ((doc hemlock-editor-document))
     2054  (assume-not-editing (slot-value doc 'textstorage)))
    20272055
    20282056(defmethod update-buffer-package ((doc hemlock-editor-document) buffer)
     
    20882116    ((self hemlock-editor-document) filename filetype)
    20892117  (declare (ignore filetype))
     2118  (assume-cocoa-thread)
    20902119  #+debug
    20912120  (#_NSLog #@"revert to saved from file %@ of type %@"
     
    25532582;;; This needs to run on the main thread.
    25542583(objc:defmethod (#/updateHemlockSelection :void) ((self hemlock-text-storage))
     2584  (assume-cocoa-thread)
    25552585  (let* ((string (#/hemlockString self))
    25562586         (buffer (buffer-cache-buffer (hemlock-buffer-string-cache string)))
     
    27292759                 title
    27302760                 string)
     2761  (assume-cocoa-thread)
    27312762  (let* ((doc (#/makeUntitledDocumentOfType:error: self #@"html" +null-ptr+)))
    27322763    (unless (%null-ptr-p doc)
  • trunk/ccl/cocoa-ide/cocoa-utils.lisp

    r7291 r7363  
    9696      (push (#/objectAtIndex: win-arr i) ret))
    9797    (nreverse ret)))
     98
     99(defun assume-cocoa-thread ()
     100  #+debug (assert (eq *current-process* *initial-process*)))
     101
     102(defmethod assume-not-editing ((whatever t)))
     103
Note: See TracChangeset for help on using the changeset viewer.