Note: If you got here using a web search engine, you can find the program here.
This code is not public domain, but may be freely used for any purpose. It is provided "as is". Use at your own risk. So there. You don't even have to give me (or Baylor University) credit but I won't complain if you do so anyway... :-) If you do use it in your program, please let me know so that I can notify you if there is an update.
This is a GetDirectory() routine (uses Standard File to choose a folder) that also allows the user to create new folders. This could be useful when trying to choose a folder where multiple documents are to be saved, etc.
Unlike PowerPlant's UStandardFile::GetDirectory() this returns the chosen folder's FSpec, not a StandardFileReply.
Rather than try to implement our own "new folder" button, we'll let the system do this for us by using a CustomPutFile dialog (which already has the button) instead of a CustomGetFile dialog. Essentially, the user is being asked to "save" a fake document somewhere but because the file name field is hidden in the DITL (outside the visible area) and is not active (ActivationOrderListPtr) the user will not be aware of the fact. One side-effect of using CustomPutFile is that you cannot just show folders, i.e., files will also be shown although the user will not be able to select one.
Pass in the resource ID of our copy of the CutstomPutFile dialog. There needs to be a button added to the DITL with itemNo of 13 (item_MySelectDirButton). The title of the button should be something like "Select Ò^Ó". The ^ (MyReplaceBy_dirName) will be replaced with the current folder's name. Unfortunately, there is no way to get the current selected folder in a PutFile dialog, like you can with GetFile. Instead, we just use the currently displayed folder. We could have the select button say something like "Select this folder" rather than deal with changing the button's title but this might confuse the user. But just in case, if the button doesn't contain a ^ the title won't change. Also, you should change the title of the "Save" button to "Select". Standard File will automagically switch between "Open" (if a folder is selected) and "Select" (if nothing is selected).
Included is a snippet to test this. The easiest way to use the snippet is to create a PP project with the "Basic PP DEBUG" stationery and call Test() when processing cmd_New. This will bring up two standard file dialogs (UStandardFile's ande UNonStandardFile's) that ask you to select a folder. Selecting a folder will use SignalPStr_ to list the files within that folder. The UNonStandardFile dialog will have the "New Folder" button.
If you have any questions, comments, (constructive) criticism, or bug reports please let me know. You can contact me at the address(es) below.
Carl Bell's Web Page
Stuff I've Written
Carl W. BellPhone:
Academic and Research Computing Services
Baylor University Electronic Library
One Bear Place #97148
Waco, TX 76798
(254) 710-4065Baylor's Fine Print:
This software, data and/or documentation contain trade secrets and confidential information which are proprietary to Baylor University. Their use or disclosure in whole or in part without the express written permission of Baylor University is prohibited.
This software, data and/or documentation are also unpublished works protected under the copyright laws of the United States of America. If these works become published, the following notice shall apply:
Copyright © 1998 Baylor UniversityThe name of Baylor University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE, DATA AND/OR DOCUMENTATION ARE PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
All Rights Reserved
When permission has been granted to make copies of this software, data and/or documentation, the above notices must be retained on all copies.
Permission is hereby granted for non-commercial use and distribution of UNonStandardFile.