Mods suggestions


#1

Auto complete file extension in save dialog
When specifying one file extension in filechoser, if the user just write a file name without extension, auto complete name with extension. Useful for system overwrite warning .

juce_win32_FileChooser.cpp

        of.hwndOwner = (HWND) parentWindow.getWindowHandle();
        of.lpstrFilter = filters.getData();
        of.nFilterIndex = 1;
        of.lpstrFile = files;
        of.nMaxFile = (DWORD) charsAvailableForResult;
        of.lpstrInitialDir = localPath.toWideCharPointer();
        of.lpstrTitle = title.toWideCharPointer();
        of.Flags = flags;
        of.lCustData = (LPARAM) &info;

//-----------------------------------------------------------------------------------
+		if (isSaveDialogue)
+		{
+			StringArray tokens;
+			tokens.addTokens (filter, ";,", "\"'");
+			tokens.trim();
+			tokens.removeEmptyStrings();
+
+			if (tokens.size() == 1 && tokens[0] != "*.*" && tokens[0] != "*")
+			{
+				of.lpstrDefExt = tokens[0].fromFirstOccurrenceOf(".",false,false).toUTF16();
+			}
+		}
//-----------------------------------------------------------------------------------
         if (extraInfoComponent != nullptr)
             of.lpfnHook = &openCallback;

juce_mac_FileChooser.mm

    if (currentFileOrDirectory.isDirectory())
    {
        directory = currentFileOrDirectory.getFullPathName();
    }
    else
    {
        directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
        filename = currentFileOrDirectory.getFileName();
    }
//---------------------------------------------------------------------------------------------------
+    if (isSaveDialogue)
+    {
+        if (filters->size() && filters->getReference(0) != "*.*" && filters->getReference(0) != "*")
+        {
+            [panel setRequiredFileType:juceStringToNS(filters->getReference(0).fromFirstOccurrenceOf(".",false,false))];
+        }                
+	  }  
//---------------------------------------------------------------------------------------------------
   #if defined (MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
    [panel setDirectoryURL: [NSURL fileURLWithPath: juceStringToNS (directory)]];
    [panel setNameFieldStringValue: juceStringToNS (filename)];

Support for x86 application directory on windows 64bits system.

juce_win32_Files.cpp

[code] case userApplicationDataDirectory: csidlType = CSIDL_APPDATA; break;
case commonApplicationDataDirectory: csidlType = CSIDL_COMMON_APPDATA; break;
case globalApplicationsDirectory: csidlType = CSIDL_PROGRAM_FILES; break;

  •   case globalApplicationsDirectoryx86:       csidlType = CSIDL_PROGRAM_FILESX86; break;
       case userMusicDirectory:                csidlType = 0x0d /*CSIDL_MYMUSIC*/; break;
       case userMoviesDirectory:               csidlType = 0x0e /*CSIDL_MYVIDEO*/; break;[/code]
    

juce_mac_Files.mm

[code] case userMoviesDirectory: resultPath = “~/Movies”; break;
case userApplicationDataDirectory: resultPath = “~/Library”; break;
case commonApplicationDataDirectory: resultPath = “/Library”; break;

  •    case globalApplicationsDirectory:       resultPath = "/Applications"; break;
    
  •    case globalApplicationsDirectory:
    
  •    case globalApplicationsDirectoryx86:     resultPath = "/Applications"; break;
    
       case invokedExecutableFile:
           if (juce_Argv0 != 0)       [/code] 
    

juce_File.h

[code] Mac “/Applications”, or “/usr” on linux.
*/
globalApplicationsDirectory,

  •   globalApplicationsDirectoryx86,
       /** The most likely place where a user might store their music files.
       */
       userMusicDirectory,[/code]

#2

Thanks… Good idea about the save extensions thing, in fact I just hit that myself and was thinking along the same lines.

But windows-specific enums in a generic class like File…? No way, sorry!


#3

BTW, just had a look at this - did you notice that on OSX I added code some time ago to do exactly the same thing? This line:

[panel setAllowedFileTypes: createAllowedTypesArray (*filters)];

??

Also, on windows you need to be careful with your strings - you’re passing a dangling pointer to the file dialog, and must have been lucky not to have it crash. I’ll sort that out and check something in later today.


#4

Yeah I know, those modifications were really not clean one. Made in a rush some years ago and never bother about changing them.

I know this is something specific to windows but there is no real reason to return the 64bits directory over the 32bit, there is still many 32bits applications running. So there should be possible to have access to both.