[Openmcl-devel] default directory

Gary Byers gb at clozure.com
Sun May 3 13:15:26 PDT 2009


(#/runModalForTypes: panel <possibly null NSArray of file types>)

is equivalent to:

(#/runModalForDirectory:file:types: panel +null-ptr+ +null-ptr+ <possibly-null-types-array>)

As one would guess from the method name, the two extra arguments accepted by the
second function are an NSString denoting an absolute directory name and an NSString
denoting a file in that directory.  So the general idea is:

(defun choose-directory-dialog (&optional default-directory)
   (execute-in-gui #'(lambda ()
                       ...
                       (let* ((dirname (if default-directory
                                         (#/autorelease
                                           (ccl::%make-nsstring
                                            (namestring (truename default-directory))))
                                         +null-ptr+)))
                              ...
                              (when (eql (#/runModalForDirectory:file:types:
                                           panel
                                           dirname
                                           +null-pointer+
                                           +null-pointer+)
                                         #$NSOKButton)
                                ...)))))

<http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSOpenPanel_Class/Reference/Reference.html>
is actually a good description of the functionality that NSOpenPanel offers; if
you have Xcode installed, a local copy of the reference documentation is buried
somewhere inside the Xcode installation directory (usually /Developer) someplace,
and you may be able to find it ...

Since it hasn't been plugged for a while, this seems like a good time to mention
AppKido (<http://homepage.mac.com/aglee/downloads/appkido.html>), which is a good,
free (well, the author accepts donations via PayPal now) tool for browsing a local
copy of the Cocoa documentation.

On Sun, 3 May 2009, Joakim Sandgren wrote:

> Hi, and thank you all for helping so much with my questions.
> here's another:
> based on the function  choose-directory-dialog in the GUI package I have done 
> another function adding some title strings, one for the panel one for the 
> button.
> Now I would like to add the functionality that the panel opens in a default 
> directory choosen by me.
> How do I do that?
>
> Sincerely
>
> Joakim
>
>
> (defun choose-directory-dialog ()
> (execute-in-gui #'(lambda ()
>                     (let ((op (#/openPanel ns:ns-open-panel)))
>                       (#/setAllowsMultipleSelection: op nil)
>                       (#/setCanChooseDirectories: op t)
>                       (#/setCanChooseFiles: op nil)
>                       (when (eql (#/runModalForTypes: op +null-ptr+) 
> #$NSOKButton)
>                         ;; #/stringByStandardizingPath seems to strip 
> trailing slashes
>                        (let* ((path (#/retain (#/stringByAppendingString:
>                                       (#/stringByStandardizingPath
>                                        (#/objectAtIndex: (#/filenames op) 
> 0))
>                                       #@"/"))))
>                           path))))))
>
> (defmethod choose-directory-dialog-with-strings ((dialogtitle string) 
> (buttonstring string))
> (gui::lisp-string-from-nsstring
>  (gui::execute-in-gui #'(lambda ()
>                           (let ((op (#/openPanel ns:ns-open-panel)))
>                             (#/setAllowsMultipleSelection: op nil)
>                             (#/setCanChooseDirectories: op t)
>                             (#/setCanChooseFiles: op nil)
>                             (#/setPrompt: op (ccl::%make-nsstring 
> buttonstring))
>                             (#/setTitle: op (ccl::%make-nsstring 
> dialogtitle))
>                             (when (eql (#/runModalForTypes: op +null-ptr+) 
> #$NSOKButton)
>                               ;; #/stringByStandardizingPath seems to strip 
> trailing slashes
>                               (let* ((path (#/retain 
> (#/stringByAppendingString:
>                                                       (#/stringByStandardizingPath
>                                                        (#/objectAtIndex: 
> (#/filenames op) 0))
>                                                       #@"/"))))
>                                 path)))))))
>
>
> Joakim Sandgren
> joakim sandgren musik
> 42, rue de Maubeuge
> 75009 Paris
> France
> +33 (0)1 45 26 43 90
> info at joakimsandgren.com
> http://www.joakimsandgren.com
>



More information about the Openmcl-devel mailing list