Linux showPlatformDialog messes up file names


#1

As the title says, the FileChooser returns true if cancel button is pressed with browseForFileToSave(true). Also when I want to save a file using FileChooser and browseForFileToSave function I get an additional character (") in the name textfield. Deleting the character and saving a file also results in having a character appended on the saved filename .I am using the native file chooser. On my Mac this does not happen only on Linux.

UPDATE:

Had to rename the title, because its not a FileChooser problem, its a Linux native showPlatformDialog problem. If I use the JUCE file dialog, I dont have any problems.

I debugged the showPlatformDialog and the strange thing is that somethings wrong with the escape character. The zenity command lokks like this:

and when I choose a file the result is:

Peter


#2

This seems to be two bugs in the Linux FileChooser::showPlatformDialog. The criticl part of the original looks like this:

    ChildProcess child;
    if (child.start (command))
    {
        const String result (child.readAllProcessOutput());
        StringArray tokens;

        if (selectMultipleFiles)
            tokens.addTokens (result, separator, "\"");
        else
            tokens.add (result);

        for (int i = 0; i < tokens.size(); i++)
            results.add (File (tokens[i]));

        child.waitForProcessToFinish (60 * 1000);
    }

It doesn’t check for “” returned from readAllProcessOutput(), so it doesn’t handle cancel. Also, if you capture the same zenity command line from a terminal, you will see that the \n at the end is also normal. So I tweaked the function to this:

    ChildProcess child;
    if (child.start (command))
    {
        const String result (child.readAllProcessOutput().trim());

        if (result.isNotEmpty())
        {
            StringArray tokens;

            if (selectMultipleFiles)
                tokens.addTokens (result, separator, "\"");
            else
                tokens.add (result);

            for (int i = 0; i < tokens.size(); i++)
                results.add (File (tokens[i]));
        }

        child.waitForProcessToFinish (60 * 1000);
    }

Basically, .trim() the results from readAllProcessOutput(), and then only add tokens if the string isn’t empty. This seemed to help a lot in getting the latest Introjucer to work as well. Module path and file open seemed to have corrupt (\n) file values from the native file chooser as well.


#3

Great, much appreciated!