I need to screen the filenames chosen by users to make sure that there aren’t any characters that are invalid on Mac or Windows or Dropbox. (There have been quite a few issues on this lately, particularly with files contained within compressed folders.)
I’ve seen one Mac app that replaces invalid characters typed by the user in the SaveAs dialog, while they are typing. This seems like a much better approach than rejecting the filename after the user has closed the SaveAs dialog, but I don’t see any way to do this in Xojo.
Does anyone know of declares or plugins (Mac & Windows) that would make this possible?
On Mac the SaveAsDialog should be replacing illegal characters with
- for you.
I am not sure about Windows.
It filters out illegal Mac characters, but not illegal Windows and Dropbox characters, I need it to do both…
OS X doesn’t care about Windows or DropBox characters
And I know of no way to hook into the name entry pane in a SaveAsDialog from Xojo (with or without a plugin)
GetSaveFolderItem on Windows lets you enter anything, but it won’t confirm names containing illegal characters.
The only way would be to use a TextField first to enter the name, so you can replace, and then pass the result as default file name to GetSaveFolderItem.
I am guessing you meant, “i know of no way to hook…”
Ah well, it was worth a shot. Thanks!
Depends if you are sandboxes.
If not we may be able to do something.
No, the app isn’t sandboxed. What do you have in mind?
It looks like Dropbox doesn’t care beyond the limitations of the OS’s. Without using a plugin, I’d get the name from the Save As dialog, filter/correct it and, if different, show a dialog warning the user and asking them if they want to fix it. If so, show the Save As dialog again with the new name for approval. Not ideal, but keep in mind that most users probably won’t see this.
This regular expression code will replace the “bad” characters with underscores:
dim rx as new RegEx
rx.SearchPattern = "[\\\\/<>:""|?*]+|[. ]+$"
rx.ReplacementPattern = "_"
rx.Options.ReplaceAllMatches = true
dim newName as string = rx.Replace( saveAsItem.Name )
if newName <> saveAsItem.Name then
Once again, in Windows, the Save as dialog won’t accept a name that contains illegal characters. So filtering after the fact is not possible.
My assumption is that his cross-platform app will filter to keep compatibility with Windows.
[quote=310165:@Christian Schmitz]I have already an event for that:
Way beyond my level of competence…
I’m just going to get the filename after they choose it, tell them why it doesn’t work, filter out the illegal characters, and give them a chance to save again. Not ideal, but it’ll work.
Thank you everyone!