How to save current path for NSOpenPanel and NSSavePanel
Duncan Champney
duncanc at aol.com
Sat May 5 10:26:53 PDT 2007
I posted this question back in March, and still don't have a solution
for it, so I am going to ask again.
My application is document based, and does the normal file load/save,
with little custom code from me.
I also have the option to load and save "color scheme" files, which
are applied to the current document.
When the user asks to load a color scheme file, I create an
NSOpenPanel and call runModalForDirectory, pointing it a directory
that contains a list of color scheme files, and specifying only the
type of file I want the user to select.
The problem has to do with the default path used for opening/saving
documents. I would like loading/saving color scheme files to take
place in my special color schemes directory, without disturbing the
directory the user last used to load/save a document.
After the user loads/saves a color scheme file, the next time they
try to load or save a document, the NSOpenPanel or NSSavePanel starts
out in my color schemes directory instead of remembering the last
place the user loaded/saved a file.
I tried using the NSFileManager's currentDirectoryPath to save the
current directory before invoking my load or save panel, and then
restoring the current directory with changeCurrentDirectoryPath, but
I gather the NSOpenPanel does not use the current directory as the
starting point for file loads.
Since my last post I discovered that the shared
NSDocumentController's method currentDirectory gives me half of the
solution, but only half. it would let me find out the current
directory that the document controller will use for a document
NSOpenPanel or NSSavePanel. However, I need an equivalent
NSDocumentController -setCurrentDirectory call that would let me
change the current directory, and there does not appear to be such a
call.
For document loads/saves, the NSDocumentController invokes
NSOpenPanel and NSSavePanel in response to my file menu's open and
save menu commands (which send the normal nil targeted actions
openDocument and saveDocument)
I've dug through the electronic documentation at length, and poured
through several print cocoa programming guides, but can't figure out
how to do this.
Can somebody help? Thanks in advance.
Duncan C
More information about the MacOSX-dev
mailing list