Ignore:
Timestamp:
Aug 31, 2009, 12:14:29 PM (10 years ago)
Author:
cater
Message:

Use threadsafe gui package functions for easygui choose-file-dialog &c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/examples/cocoa/easygui/dialogs.lisp

    r12405 r12718  
    2020(defvar *beepnsleep* t)
    2121
    22 (defun choose-file-dialog (&key button-string)
    23   (gui::with-autorelease-pool
    24       (let* ((panel (dcc (#/autorelease (dcc (#/openPanel ns:ns-open-panel)))))) ; allocate an NSOpenPanel
    25         (dcc (#/setAllowsMultipleSelection: panel nil)) ; return at most one filename
    26         (when button-string
    27           (setf button-string (ccl::%make-nsstring button-string))
    28           (dcc (#/setPrompt: panel button-string)))
    29         (when (eql #$NSOKButton
    30                    (dcc (#/runModalForDirectory:file:types: panel
    31                            +null-ptr+ ; default to last dir used
    32                            +null-ptr+ ; no preselected file
    33                            ;; If not NIL below then an ObjC array containing NSStrings could be used
    34                            ;; to restrict the file types we're interested in
    35                            nil)))
    36           ;; Because we told the panel to disallow multiple selection,
    37           ;; there should be exactly one object in this array, an
    38           ;; NSString describing the selected file.
    39           (let* ((files (dcc (#/filenames panel))) thing)
    40             (if (eql 1 (dcc (#/count files)))
    41               (progn
    42                 (setf thing (dcc (#/objectAtIndex: files 0)))
    43                 (gui::lisp-string-from-nsstring thing))
    44               "Don't know why we didn't get an NSArray containing exactly 1 file here."))))))
     22(defun choose-file-dialog (&key directory file-types file button-string)
     23  (gui::cocoa-choose-file-dialog :directory directory :file-types file-types :file file :button-string button-string))
    4524
    46 (defun choose-new-file-dialog (&key button-string)
    47   (declare (ignorable button-string))
    48   (gui::with-autorelease-pool
    49       (let* ((panel (dcc (#/autorelease (dcc (#/savePanel ns:ns-save-panel)))))) ; allocate an NSSavePanel
    50         (when button-string (dcc (#/setPrompt: panel (ccl::%make-nsstring button-string))))
    51         (when (eql #$NSOKButton
    52                    (dcc (#/runModalForDirectory:file: panel
    53                       +null-ptr+ ; default to last dir used
    54                       +null-ptr+)))
    55           ;; Because we told the panel to disallow multiple selection,
    56           ;; there should be exactly one object in this array, an
    57           ;; NSString describing the selected file.
    58           (let* ((files (dcc (#/filenames panel))))
    59             (if (eql 1 (dcc (#/count files)))
    60               (gui::lisp-string-from-nsstring (dcc (#/objectAtIndex: files 0)))
    61               (error "Don't know why we didn't get an NSArray containing exactly 1 file here.")))))))
     25(defun choose-new-file-dialog (&key directory file-types file button-string)
     26  (declare (ignore button-string))
     27  (gui::cocoa-choose-new-file-dialog :directory directory :file-types file-types :file file))
     28
     29(defun cocoa-choose-directory-dialog (&key directory button-string)
     30  (declare (ignore button-string))
     31  (cocoa-choose-directory-dialog :directory directory))
    6232
    6333(objc:defmethod (#/NSWindowWillCloseNotification :void) ((self ns:ns-color-panel))
Note: See TracChangeset for help on using the changeset viewer.