Changeset 12364


Ignore:
Timestamp:
Jul 4, 2009, 10:12:48 PM (10 years ago)
Author:
mikel
Message:

Ticket #462: we were using the default drop-handling for NSTextView, which handles dropped files in the way described in the bug report. The fix adds to cocoa-editor.lisp an implementation of #/performDragOperation: that tries to find NSFilenamesPboardType in the pasteboard, and, if successful, canonicalizes the pathnames so that directory pathnames end in a "/"

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

Legend:

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

    r12324 r12364  
    880880  (:metaclass ns:+ns-object))
    881881(declaim (special hemlock-textstorage-text-view))
     882
     883(objc:defmethod (#/performDragOperation: :boolean)
     884    ((self hemlock-textstorage-text-view)
     885     (sender :id))
     886  (let* ((pboard (#/draggingPasteboard sender))
     887         (pbTypes (#/arrayWithObjects: ns:ns-array #&NSFilenamesPboardType
     888                                       +null-ptr+))
     889         (available-type (#/availableTypeFromArray: pboard pbTypes)))
     890    (if (%null-ptr-p available-type)
     891        (progn (log-debug "No data available of type NSFilenamesPboardType")
     892               (call-next-method sender))
     893        (let* ((plist (#/propertyListForType: pboard #&NSFilenamesPboardType)))
     894          (cond
     895            ;; we found NSFilenamesPboardType and it's an array of pathnames
     896            ((#/isKindOfClass: plist ns:ns-array)
     897             (with-autorelease-pool
     898               (let* ((strings-for-dropped-objects
     899                       (mapcar (lambda (d)
     900                                 (if (#/isKindOfClass: d ns:ns-string)
     901                                     (ccl::lisp-string-from-nsstring d)
     902                                     (#/description d)))
     903                               (list-from-ns-array plist)))
     904                      (canonical-dropped-strings
     905                       (mapcar (lambda (s)
     906                                 (if (and (probe-file s)
     907                                          (directoryp s))
     908                                     (ccl::ensure-directory-namestring s)
     909                                     s))
     910                               strings-for-dropped-objects))
     911                      (dropstr (with-output-to-string (out)
     912                                 (dolist (s canonical-dropped-strings)
     913                                   (format out "~A~%" s)))))
     914                 ;; TODO: insert them in the window
     915                 (let* ((hview (hemlock-view self))
     916                        (buf (hi:hemlock-view-buffer hview))
     917                        (point (hi::buffer-point buf)))
     918                   (hi::insert-string point dropstr)))))
     919            ;; we found NSFilenamesPboardType, but didn't get an array of pathnames; huh???
     920            (t (log-debug "hemlock-textstorage-text-view received an unrecognized data type in a drag operation: '~S'"
     921                          (#/description plist))
     922               (call-next-method sender)))))))
    882923
    883924(defmethod hemlock-view ((self hemlock-textstorage-text-view))
  • trunk/source/cocoa-ide/cocoa-utils.lisp

    r12136 r12364  
    22
    33(in-package "GUI")
     4
     5(defmethod list-from-ns-array (thing) (error "~S is not an instance of NS:NS-ARRAY" thing))
     6(defmethod list-from-ns-array ((nsa ns:ns-array))
     7  (let ((result (list))
     8        (c (#/count nsa)))
     9    (dotimes (i c) (setf result (push (#/objectAtIndex: nsa i) result)))
     10    (reverse result)))
    411
    512(defclass sequence-window-controller (ns:ns-window-controller)
Note: See TracChangeset for help on using the changeset viewer.