Changeset 12125


Ignore:
Timestamp:
May 24, 2009, 8:29:38 AM (10 years ago)
Author:
gb
Message:

#/replaceCharactersAtPosition:length:withString: UNWIND-PROTECT
around #/beginEditing / #/endEditing.

Try to support :NATIVE quote-next-char behavior. Doesn't work yet.

If our clip-view (the contentview of a scroll view) gets asked to
#/scrollToPoint: while live resize is active, don't do it. (This
seems to prevent the unwanted scrolling that occurs during resize,
which seems to have to do with NSTextView wanting to center the
selection.)

When a Hemlock Frame (window) closes, set its autosave name to #@"".
(This allows previously used names - including listener document
names - to be reused.)

In GET-DEFAULT-ENCODING, only bother if CCL:*DEFAULT-CHARACTER-ENCODING*
is a keyword for which CCL::LOOKUP-CHARACTER-ENCODING returns non-nil.
(This increases the chance that GET-DEFAULT-ENCODING may return NIL.)

Don't expect an :INITFORM to take effect for a foreign slot in
the DEFCLASS for HEMLOCK-EDITOR-DOCUMENT; set the slot in the #/init
method instead.

In UPDATE-BUFFER-PACKAGE, fall back to the (new) default package if
there's no IN-PACKAGE form before point.

For now, the encodings popup menu in Open and Save dialogs only lists
the ~2 dozen encodings that CCL actually supports.

File:
1 edited

Legend:

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

    r12110 r12125  
    763763      (unwind-protect
    764764           (#/replaceCharactersInRange:withString: self r string)
    765       (#/endEditing self)))))
     765        (#/endEditing self)))))
    766766
    767767;; In theory (though not yet in practice) we allow for a buffer to be shown in multiple
     
    916916
    917917(objc:defmethod (#/keyDown: :void) ((self hemlock-textstorage-text-view) event)
    918   #+debug (#_NSLog #@"Key down event = %@" :address event)
     918  #+debug (#_NSLog #@"Key down event in %@  = %@" :id self :address event)
    919919  (let* ((view (hemlock-view self))
    920920         ;; quote-p means handle characters natively
     
    923923         (flags (#/modifierFlags event)))
    924924    #+debug (log-debug "~&quote-p ~s event ~s" quote-p event)
    925     (when (and has-marked-text quote-p)
     925    (when (and has-marked-text quote-p (not (eq quote-p :native)))
    926926      (setf (hi::hemlock-view-quote-next-p view) nil)
    927927      (setq quote-p nil))
    928     (cond ((and (not *option-is-meta*)
    929                 (logtest #$NSAlternateKeyMask flags))
     928    (cond ((or (eq quote-p :native)
     929               (and (not *option-is-meta*)
     930                    (logtest #$NSAlternateKeyMask flags)))
    930931           (call-next-method event))
    931932          ;; If a standalone dead key (e.g., ^ on a French keyboard)
     
    16671668
    16681669
    1669 ;;; A clip view subclass, which exists mostlu so that we can track origin changes.
     1670 
     1671
     1672;;; A clip view subclass, which exists mostly so that we can track origin changes.
    16701673(defclass text-pane-clip-view (ns:ns-clip-view)
    16711674  ()
     
    16741677(objc:defmethod (#/scrollToPoint: :void) ((self text-pane-clip-view)
    16751678                                           (origin #>NSPoint))
    1676   (call-next-method origin)
    1677   (compute-temporary-attributes (#/documentView self)))
     1679  (unless (#/inLiveResize self)
     1680    (call-next-method origin)
     1681    (compute-temporary-attributes (#/documentView self))))
    16781682
    16791683;;; Text-pane
     
    20112015      (#/close echo-doc)))
    20122016  (release-canonical-nsobject self)
     2017  (#/setFrameAutosaveName: self #@"")
    20132018  (call-next-method))
    20142019 
     
    23192324;;; Map *default-file-character-encoding* to an :<NSS>tring<E>ncoding
    23202325(defun get-default-encoding ()
    2321   (let* ((string (string (or *default-file-character-encoding*
    2322                                  "ISO-8859-1")))
    2323          (len (length string)))
    2324     (with-cstrs ((cstr string))
    2325       (with-nsstr (nsstr cstr len)
    2326         (let* ((cf (#_CFStringConvertIANACharSetNameToEncoding nsstr)))
    2327           (if (= cf #$kCFStringEncodingInvalidId)
    2328             (setq cf (#_CFStringGetSystemEncoding)))
    2329           (let* ((ns (#_CFStringConvertEncodingToNSStringEncoding cf)))
    2330             (if (= ns #$kCFStringEncodingInvalidId)
    2331               (#/defaultCStringEncoding ns:ns-string)
    2332               ns)))))))
     2326  (let* ((file-encoding *default-file-character-encoding*))
     2327    (when (and (typep file-encoding 'keyword)
     2328               (lookup-character-encoding file-encoding))
     2329      (let* ((string (string file-encoding))
     2330             (len (length string)))
     2331        (with-cstrs ((cstr string))
     2332          (with-nsstr (nsstr cstr len)
     2333            (let* ((cf (#_CFStringConvertIANACharSetNameToEncoding nsstr)))
     2334              (if (= cf #$kCFStringEncodingInvalidId)
     2335                (setq cf (#_CFStringGetSystemEncoding)))
     2336              (let* ((ns (#_CFStringConvertEncodingToNSStringEncoding cf)))
     2337                (if (= ns #$kCFStringEncodingInvalidId)
     2338                  (#/defaultCStringEncoding ns:ns-string)
     2339                  ns)))))))))
    23332340
    23342341(defclass hemlock-document-controller (ns:ns-document-controller)
     
    23482355(defclass hemlock-editor-document (ns:ns-document)
    23492356    ((textstorage :foreign-type :id)
    2350      (encoding :foreign-type :<NSS>tring<E>ncoding :initform (get-default-encoding)))
     2357     (encoding :foreign-type :<NSS>tring<E>ncoding))
    23512358  (:metaclass ns:+ns-object))
    23522359
     
    23682375
    23692376(defmethod update-buffer-package ((doc hemlock-editor-document) buffer)
    2370   (let* ((name (hemlock::package-at-mark (hi::buffer-point buffer))))
     2377  (let* ((name (or (hemlock::package-at-mark (hi::buffer-point buffer))
     2378                   (hi::variable-value 'hemlock::default-package :buffer buffer))))
    23712379    (when name
    23722380      (let* ((pkg (find-package name)))
     
    24932501                                (#/displayName doc))
    24942502                               :modes '("Lisp" "Editor")))))
     2503    (with-slots (encoding) doc
     2504      (setq encoding (or (get-default-encoding) #$NSISOLatin1StringEncoding)))
    24952505    (setq *last-document-created* doc)
    24962506    doc))
     
    25302540          (progn
    25312541            (if (zerop selected-encoding)
    2532               (setq selected-encoding (get-default-encoding)))
     2542              (setq selected-encoding (or (get-default-encoding) #$NSISOLatin1StringEncoding)))
    25332543            (setq string (#/stringWithContentsOfURL:encoding:error:
    25342544                          ns:ns-string
     
    28832893                           (#/localizedNameOfStringEncoding: ns:ns-string ns))
    28842894      iana)))
    2885      
     2895
     2896;;; Return T if the specified #>NSStringEncoding names something that
     2897;;; CCL supports.  (Could also have a set of other encoding names that
     2898;;; the user is interested in, maintained by preferences.
     2899
     2900(defun supported-string-encoding-p (ns-string-encoding)
     2901  (let* ((cfname (#_CFStringConvertEncodingToIANACharSetName
     2902                  (#_CFStringConvertNSStringEncodingToEncoding ns-string-encoding)))
     2903         (name (unless (%null-ptr-p cfname)
     2904                 (nstring-upcase (ccl::lisp-string-from-nsstring cfname))))
     2905         (keyword (when (and name (find-symbol name "KEYWORD"))
     2906                    (intern name "KEYWORD"))))
     2907    (or (and keyword (not (null (lookup-character-encoding keyword))))
     2908        ;; look in other table maintained by preferences
     2909        )))
     2910   
     2911         
     2912
     2913
     2914 
    28862915;;; Return a list of :<NSS>tring<E>ncodings, sorted by the
    28872916;;; (localized) name of each encoding.
     
    29002929                                    (nsstring-for-nsstring-encoding x)
    29012930                                    (nsstring-for-nsstring-encoding y))))))
    2902               (ids id))))))))
     2931              (when (supported-string-encoding-p id)             
     2932                (ids id)))))))))
    29032933
    29042934
Note: See TracChangeset for help on using the changeset viewer.