Ask file: can I force the user to use an extension?

Graham Samuel livfoss at mac.com
Tue Feb 28 09:41:10 EST 2012


Consider a statement like this (on Windows):

ask file "Save it" with myPath with filter "JPEG file, .JPG"

my user sees a default name (it's the string after the last "/" in myPath). By convention I propose a name ending with an extension like:

 File-extract.JPG

I do this because when I do the actual save, I want to ensure that there is a .JPG extension on the file name. This is needed for all sorts of reasons. However the user can just ignore me and rename the file in the conventional 'Save' dialog box, e.g. he/she can type:

 MyOwnFile

Now comes the tricky bit. The Save dialog (which AFAIK is part of the OS, not part of the engine) can detect attempts at duplication and warn the user about them, inviting the user to rename or cancel. But in a directory consisting exclusively of files with extensions, there never will be a file "MyOwnFile", because by the time I actually write the file, I will have tacked on an extension, so it will be

 MyOwnFile.JPG

Now say there is already such a file in the directory. Of course I can detect it (by 'there is a') and warn the user, but only in a separate, home-grown dialog (an 'ask' dialog) after the Save dialog has been dismissed. This is clumsy and odd as a user experience. Is there any way I can hack into the conventional Save dialog so that it thinks it is being asked to save a file with an extension in spite of my user not typing one?

I haven't thought of a workaround but maybe it will be obvious to someone on the list.

Graham





More information about the use-livecode mailing list