FileChooser, filter problems and fix for Windows and Linux/Zanity


#1

File filters still don't work correctly. Here is fix for problems. 


For Windows:
juce_win32_FileChooser.cpp line: 225
Remove those two lines:

        filter.copyToUTF16 (filters + (bytesWritten / sizeof (WCHAR)),
                            ((filterSpaceNumChars - 1) * sizeof (WCHAR) - bytesWritten));


For Linux/Zanity:
juce_linux_FileChooser.cpp line: 132
Remove those four lines:

StringArray tokens;
tokens.addTokens (filters, ";,|", "\"");
for (int i = 0; i < tokens.size(); ++i)
    args.add ("--file-filter=" + tokens[i]);

Put these four lines instead:

StringArray tokens;
tokens.addTokens(filters.replaceCharacter(';', ' '), "|", "\"");
for (int i = 0; i < tokens.size(); i += 2)
    args.add("--file-filter=" + tokens[i] + "|" + tokens[i + 1] + "");

I use this string to set filter:


juce::String filters("All Files|*|G-Code Files|*.nc;*.tap;*.cnc;*.iso;*.gcode;*.ncf;*.txt|DXF Files|*.dxf|PLT/HPGL Files|*.plt;*.plo;*.hg;*.hgl;*.hpg;*.hpgl;*.hpgl2|Gerber Files|*.gbr;*.gbl;*.gtl;*.gko;*.grb;*.cmp;*.sol;*.plc;*.pls;*.stc;*.sts;*.smc;*.sms;*.ssc;*.sss|NC Drill Files|*.ncd;*.nc;*.drl;*.drd|CSV Files|*.csv|Image Files|*.bmp;*.jpg;*.png");

Please add this fixes to Juce. Thank you.


#2

Hi Kroko, I can see the value of the "|" syntax and I think this is a real useful addition to JUCE. As far as I can see this syntax isn't officially documented anywhere in JUCE. So we would need to add proper support for this. For example, JUCE's non-native file choosers do not support this functionality at all currently. We would need to add a pop-menu to them. Additionally, the mac file chooser does not currently support this syntax either. I'll add this to the back log. If you have any code for mac or for the non-native dialog boxes then that would be great as well.


#3

I'm used to "|" syntax from C# and Delphi.

I check what can be done with non-native dialogs. But I can not help with Mac.

But regardless - Current Windows native code uses "|" syntax. Bug that I found is not related to "|". Linux/Zanity code also parses "|" character. But it is not done correctly and current implementation does not work.

It is true that my proposition is not complete (yet) but it is better than current state where filters in native dialogs are not useful at all.

And if we agree on "|" syntax then I can also update non-native dialogs.

 

 

 


#4

I checked non-native dialogs. Non-native dialogs do not have combo box with selectable filter like native dialogs have. Therefore this filter change that I proposed does not apply.

I'm not familiar with Mac but checked how showPlatformDialog is implemented and it seems that "setAllowedFileTypes" works similar to Juce non-native dialog. This means that "|" syntax also does not apply.