Adds handling for if the user cancels out of the file dialog, and adds support for proper multi-filters.

This commit is contained in:
Areloch 2016-05-17 12:46:39 -05:00
parent 5958e86e9a
commit c0a96c908f

View file

@ -184,33 +184,56 @@ static const U32 convertUTF16toUTF8DoubleNULL(const UTF16 *unistring, UTF8 *out
// //
bool FileDialog::Execute() bool FileDialog::Execute()
{ {
String suffix; String strippedFilters;
U32 filtersCount = StringUnit::getUnitCount(mData.mFilters, "|"); U32 filtersCount = StringUnit::getUnitCount(mData.mFilters, "|");
for (U32 i = 1; i < filtersCount; ++i) for (U32 i = 1; i < filtersCount; ++i)
{ {
//The first of each pair is the name, which we'll skip because NFD doesn't support named filters atm //The first of each pair is the name, which we'll skip because NFD doesn't support named filters atm
const char *filter = StringUnit::getUnit(mData.mFilters, i, "|"); String filter = StringUnit::getUnit(mData.mFilters, i, "|");
if (!dStrcmp(filter, "*.*")) if (!dStrcmp(filter.c_str(), "*.*"))
continue; continue;
U32 c = 2; U32 subFilterCount = StringUnit::getUnitCount(filter, ";");
const char* tmpchr = &filter[c];
String tString = String(tmpchr); //if we have a 'super filter', break it down to sub-options as well
tString.ToLower(tString); if (subFilterCount > 1)
suffix += tString; {
suffix += String(","); String suffixFilter;
suffix += tString.ToUpper(tString); String subFilters;
for (U32 f = 0; f < subFilterCount; ++f)
{
String subFilter = StringUnit::getUnit(filter, f, ";");
suffixFilter += String::ToLower(subFilter) + "," + String::ToUpper(subFilter) + ",";
subFilters += String::ToLower(subFilter) + "," + String::ToUpper(subFilter) + ";";
}
suffixFilter = suffixFilter.substr(0, suffixFilter.length() - 1);
suffixFilter += ";";
strippedFilters += suffixFilter + subFilters;
}
else //otherwise, just add the filter
{
strippedFilters += String::ToLower(filter) + "," + String::ToUpper(filter) + ";";
}
++i; ++i;
if (i < filtersCount-2) if (i < filtersCount - 2)
suffix += String(";"); strippedFilters += String(";");
} }
String strippedFilters = suffix;
strippedFilters.replace(";",","); //strip the last character, if it's unneeded
strippedFilters += String(";") + suffix; if (strippedFilters.endsWith(";"))
{
strippedFilters = strippedFilters.substr(0, strippedFilters.length() - 1);
}
strippedFilters.replace("*.", "");
// Get the current working directory, so we can back up to it once Windows has // Get the current working directory, so we can back up to it once Windows has
// done its craziness and messed with it. // done its craziness and messed with it.
@ -236,11 +259,15 @@ bool FileDialog::Execute()
else if (mData.mStyle & FileDialogData::FDS_MULTIPLEFILES) else if (mData.mStyle & FileDialogData::FDS_MULTIPLEFILES)
result = NFD_OpenDialogMultiple(strippedFilters.c_str(), defaultPath.c_str(), &pathSet); result = NFD_OpenDialogMultiple(strippedFilters.c_str(), defaultPath.c_str(), &pathSet);
if (result == NFD_CANCEL)
{
return false;
}
String resultPath = String(outPath).replace(rootDir, String("")); String resultPath = String(outPath).replace(rootDir, String(""));
resultPath = resultPath.replace(0, 1, String("")).c_str(); //kill '\\' prefix resultPath = resultPath.replace(0, 1, String("")).c_str(); //kill '\\' prefix
resultPath = resultPath.replace(String("\\"), String("/")); resultPath = resultPath.replace(String("\\"), String("/"));
// Did we select a file? // Did we select a file?
if (result != NFD_OKAY) if (result != NFD_OKAY)
{ {
@ -278,7 +305,6 @@ bool FileDialog::Execute()
// Return success. // Return success.
return true; return true;
} }
DefineEngineMethod(FileDialog, Execute, bool, (), , DefineEngineMethod(FileDialog, Execute, bool, (), ,