pass filter to NFD - DOES NOT BUILD
I am so lazy to adapt the macOS part
This commit is contained in:
parent
1b21d618b6
commit
deffd99503
8
extern/nfd-modified/src/include/nfd.h
vendored
8
extern/nfd-modified/src/include/nfd.h
vendored
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/* denotes UTF-8 char */
|
/* denotes UTF-8 char */
|
||||||
typedef char nfdchar_t;
|
typedef char nfdchar_t;
|
||||||
|
@ -35,19 +37,19 @@ typedef enum {
|
||||||
/* nfd_<targetplatform>.c */
|
/* nfd_<targetplatform>.c */
|
||||||
|
|
||||||
/* single file open dialog */
|
/* single file open dialog */
|
||||||
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
|
nfdresult_t NFD_OpenDialog( const std::vector<std::string>& filterList,
|
||||||
const nfdchar_t *defaultPath,
|
const nfdchar_t *defaultPath,
|
||||||
nfdchar_t **outPath,
|
nfdchar_t **outPath,
|
||||||
nfdselcallback_t selCallback = NULL );
|
nfdselcallback_t selCallback = NULL );
|
||||||
|
|
||||||
/* multiple file open dialog */
|
/* multiple file open dialog */
|
||||||
nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
|
nfdresult_t NFD_OpenDialogMultiple( const std::vector<std::string>& filterList,
|
||||||
const nfdchar_t *defaultPath,
|
const nfdchar_t *defaultPath,
|
||||||
nfdpathset_t *outPaths,
|
nfdpathset_t *outPaths,
|
||||||
nfdselcallback_t selCallback = NULL );
|
nfdselcallback_t selCallback = NULL );
|
||||||
|
|
||||||
/* save dialog */
|
/* save dialog */
|
||||||
nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
|
nfdresult_t NFD_SaveDialog( const std::vector<std::string>& filterList,
|
||||||
const nfdchar_t *defaultPath,
|
const nfdchar_t *defaultPath,
|
||||||
nfdchar_t **outPath,
|
nfdchar_t **outPath,
|
||||||
nfdselcallback_t selCallback = NULL );
|
nfdselcallback_t selCallback = NULL );
|
||||||
|
|
10
extern/nfd-modified/src/nfd_cocoa.mm
vendored
10
extern/nfd-modified/src/nfd_cocoa.mm
vendored
|
@ -14,7 +14,7 @@
|
||||||
//
|
//
|
||||||
// might as well make Objective-Ruswift++...
|
// might as well make Objective-Ruswift++...
|
||||||
|
|
||||||
static NSArray *BuildAllowedFileTypes( const char *filterList )
|
static NSArray *BuildAllowedFileTypes( const std::vector<std::string>& filterList )
|
||||||
{
|
{
|
||||||
// Commas and semicolons are the same thing on this platform
|
// Commas and semicolons are the same thing on this platform
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ static NSArray *BuildAllowedFileTypes( const char *filterList )
|
||||||
return returnArray;
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddFilterListToDialog( NSSavePanel *dialog, const char *filterList )
|
static void AddFilterListToDialog( NSSavePanel *dialog, const std::vector<std::string>& filterList )
|
||||||
{
|
{
|
||||||
if ( !filterList || strlen(filterList) == 0 )
|
if ( !filterList || strlen(filterList) == 0 )
|
||||||
return;
|
return;
|
||||||
|
@ -130,7 +130,7 @@ static nfdresult_t AllocPathSet( NSArray *urls, nfdpathset_t *pathset )
|
||||||
/* public */
|
/* public */
|
||||||
|
|
||||||
|
|
||||||
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
|
nfdresult_t NFD_OpenDialog( const std::vector<std::string>& filterList,
|
||||||
const nfdchar_t *defaultPath,
|
const nfdchar_t *defaultPath,
|
||||||
nfdchar_t **outPath,
|
nfdchar_t **outPath,
|
||||||
nfdselcallback_t selCallback )
|
nfdselcallback_t selCallback )
|
||||||
|
@ -173,7 +173,7 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
|
nfdresult_t NFD_OpenDialogMultiple( const std::vector<std::string>& filterList,
|
||||||
const nfdchar_t *defaultPath,
|
const nfdchar_t *defaultPath,
|
||||||
nfdpathset_t *outPaths,
|
nfdpathset_t *outPaths,
|
||||||
nfdselcallback_t selCallback )
|
nfdselcallback_t selCallback )
|
||||||
|
@ -218,7 +218,7 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
|
nfdresult_t NFD_SaveDialog( const std::vector<std::string>& filterList,
|
||||||
const nfdchar_t *defaultPath,
|
const nfdchar_t *defaultPath,
|
||||||
nfdchar_t **outPath,
|
nfdchar_t **outPath,
|
||||||
nfdselcallback_t selCallback )
|
nfdselcallback_t selCallback )
|
||||||
|
|
85
extern/nfd-modified/src/nfd_win.cpp
vendored
85
extern/nfd-modified/src/nfd_win.cpp
vendored
|
@ -197,44 +197,19 @@ static void CopyNFDCharToWChar( const nfdchar_t *inStr, wchar_t **outStr )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileOpenDialog, const std::vector<std::string>& filterList )
|
||||||
/* ext is in format "jpg", no wildcards or separators */
|
|
||||||
static int AppendExtensionToSpecBuf( const char *ext, char *specBuf, size_t specBufLen )
|
|
||||||
{
|
|
||||||
const char SEP[] = ";";
|
|
||||||
assert( specBufLen > strlen(ext)+3 );
|
|
||||||
|
|
||||||
if ( strlen(specBuf) > 0 )
|
|
||||||
{
|
|
||||||
strncat( specBuf, SEP, specBufLen - strlen(specBuf) - 1 );
|
|
||||||
specBufLen += strlen(SEP);
|
|
||||||
}
|
|
||||||
|
|
||||||
char extWildcard[NFD_MAX_STRLEN];
|
|
||||||
int bytesWritten = sprintf_s( extWildcard, NFD_MAX_STRLEN, "*.%s", ext );
|
|
||||||
assert( bytesWritten == (int)(strlen(ext)+2) );
|
|
||||||
_NFD_UNUSED(bytesWritten);
|
|
||||||
|
|
||||||
strncat( specBuf, extWildcard, specBufLen - strlen(specBuf) - 1 );
|
|
||||||
|
|
||||||
return NFD_OKAY;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileOpenDialog, const char *filterList )
|
|
||||||
{
|
{
|
||||||
const wchar_t WILDCARD[] = L"*.*";
|
const wchar_t WILDCARD[] = L"*.*";
|
||||||
|
|
||||||
if ( !filterList || strlen(filterList) == 0 )
|
if (filterList.empty())
|
||||||
return NFD_OKAY;
|
return NFD_OKAY;
|
||||||
|
|
||||||
|
// list size has to be an even number (name/filter)
|
||||||
|
if (filterList.size()&1)
|
||||||
|
return NFD_ERROR;
|
||||||
|
|
||||||
// Count rows to alloc
|
// Count rows to alloc
|
||||||
UINT filterCount = 1; /* guaranteed to have one filter on a correct, non-empty parse */
|
UINT filterCount = filterList.size()>>1; /* guaranteed to have one filter on a correct, non-empty parse */
|
||||||
const char *p_filterList;
|
|
||||||
for ( p_filterList = filterList; *p_filterList; ++p_filterList )
|
|
||||||
{
|
|
||||||
if ( *p_filterList == ';' )
|
|
||||||
++filterCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(filterCount);
|
assert(filterCount);
|
||||||
if ( !filterCount )
|
if ( !filterCount )
|
||||||
|
@ -256,43 +231,17 @@ static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileOpenDialog, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t specIdx = 0;
|
size_t specIdx = 0;
|
||||||
p_filterList = filterList;
|
|
||||||
char typebuf[NFD_MAX_STRLEN] = {0}; /* one per comma or semicolon */
|
|
||||||
char *p_typebuf = typebuf;
|
|
||||||
|
|
||||||
char specbuf[NFD_MAX_STRLEN] = {0}; /* one per semicolon */
|
for (size_t i=0; i<filterList.size(); i+=2) {
|
||||||
|
String name=filterList[i];
|
||||||
while ( 1 )
|
String spec=filterList[i+1];
|
||||||
{
|
for (char& i: spec) {
|
||||||
if ( NFDi_IsFilterSegmentChar(*p_filterList) )
|
if (i==' ') i=',';
|
||||||
{
|
|
||||||
/* append a type to the specbuf (pending filter) */
|
|
||||||
AppendExtensionToSpecBuf( typebuf, specbuf, NFD_MAX_STRLEN );
|
|
||||||
|
|
||||||
p_typebuf = typebuf;
|
|
||||||
memset( typebuf, 0, sizeof(char)*NFD_MAX_STRLEN );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( *p_filterList == ';' || *p_filterList == '\0' )
|
CopyNFDCharToWChar( name.c_str(), (wchar_t**)&specList[specIdx].pszName );
|
||||||
{
|
CopyNFDCharToWChar( spec.c_str(), (wchar_t**)&specList[specIdx].pszSpec );
|
||||||
/* end of filter -- add it to specList */
|
|
||||||
|
|
||||||
CopyNFDCharToWChar( specbuf, (wchar_t**)&specList[specIdx].pszName );
|
|
||||||
CopyNFDCharToWChar( specbuf, (wchar_t**)&specList[specIdx].pszSpec );
|
|
||||||
|
|
||||||
memset( specbuf, 0, sizeof(char)*NFD_MAX_STRLEN );
|
|
||||||
++specIdx;
|
++specIdx;
|
||||||
if ( specIdx == filterCount )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !NFDi_IsFilterSegmentChar( *p_filterList ))
|
|
||||||
{
|
|
||||||
*p_typebuf = *p_filterList;
|
|
||||||
++p_typebuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
++p_filterList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add wildcard */
|
/* Add wildcard */
|
||||||
|
@ -450,7 +399,7 @@ static nfdresult_t SetDefaultPath( IFileDialog *dialog, const char *defaultPath
|
||||||
/* public */
|
/* public */
|
||||||
|
|
||||||
|
|
||||||
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
|
nfdresult_t NFD_OpenDialog( const std::vector<std::string>& filterList,
|
||||||
const nfdchar_t *defaultPath,
|
const nfdchar_t *defaultPath,
|
||||||
nfdchar_t **outPath,
|
nfdchar_t **outPath,
|
||||||
nfdselcallback_t selCallback )
|
nfdselcallback_t selCallback )
|
||||||
|
@ -558,7 +507,7 @@ end:
|
||||||
return nfdResult;
|
return nfdResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
|
nfdresult_t NFD_OpenDialogMultiple( const std::vector<std::string>& filterList,
|
||||||
const nfdchar_t *defaultPath,
|
const nfdchar_t *defaultPath,
|
||||||
nfdpathset_t *outPaths,
|
nfdpathset_t *outPaths,
|
||||||
nfdselcallback_t selCallback )
|
nfdselcallback_t selCallback )
|
||||||
|
@ -653,7 +602,7 @@ end:
|
||||||
return nfdResult;
|
return nfdResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
|
nfdresult_t NFD_SaveDialog( const std::vector<std::string>& filterList,
|
||||||
const nfdchar_t *defaultPath,
|
const nfdchar_t *defaultPath,
|
||||||
nfdchar_t **outPath,
|
nfdchar_t **outPath,
|
||||||
nfdselcallback_t selCallback )
|
nfdselcallback_t selCallback )
|
||||||
|
|
|
@ -30,9 +30,9 @@ void _nfdThread(const NFDState state, std::atomic<bool>* ok, String* result) {
|
||||||
nfdresult_t ret=NFD_CANCEL;
|
nfdresult_t ret=NFD_CANCEL;
|
||||||
|
|
||||||
if (state.isSave) {
|
if (state.isSave) {
|
||||||
ret=NFD_SaveDialog(NULL,state.path.c_str(),&out,state.clickCallback);
|
ret=NFD_SaveDialog(state.filter,state.path.c_str(),&out,state.clickCallback);
|
||||||
} else {
|
} else {
|
||||||
ret=NFD_OpenDialog(NULL,state.path.c_str(),&out,state.clickCallback);
|
ret=NFD_OpenDialog(state.filter,state.path.c_str(),&out,state.clickCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
|
|
Loading…
Reference in a new issue