mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-22 20:45:11 +00:00
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
4 changed files with 31 additions and 80 deletions
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 <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/* denotes UTF-8 char */
|
||||
typedef char nfdchar_t;
|
||||
|
@ -35,19 +37,19 @@ typedef enum {
|
|||
/* nfd_<targetplatform>.c */
|
||||
|
||||
/* 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,
|
||||
nfdchar_t **outPath,
|
||||
nfdselcallback_t selCallback = NULL );
|
||||
|
||||
/* 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,
|
||||
nfdpathset_t *outPaths,
|
||||
nfdselcallback_t selCallback = NULL );
|
||||
|
||||
/* save dialog */
|
||||
nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
|
||||
nfdresult_t NFD_SaveDialog( const std::vector<std::string>& filterList,
|
||||
const nfdchar_t *defaultPath,
|
||||
nfdchar_t **outPath,
|
||||
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++...
|
||||
|
||||
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
|
||||
|
||||
|
@ -56,7 +56,7 @@ static NSArray *BuildAllowedFileTypes( const char *filterList )
|
|||
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 )
|
||||
return;
|
||||
|
@ -130,7 +130,7 @@ static nfdresult_t AllocPathSet( NSArray *urls, nfdpathset_t *pathset )
|
|||
/* public */
|
||||
|
||||
|
||||
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
|
||||
nfdresult_t NFD_OpenDialog( const std::vector<std::string>& filterList,
|
||||
const nfdchar_t *defaultPath,
|
||||
nfdchar_t **outPath,
|
||||
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,
|
||||
nfdpathset_t *outPaths,
|
||||
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,
|
||||
nfdchar_t **outPath,
|
||||
nfdselcallback_t selCallback )
|
||||
|
|
89
extern/nfd-modified/src/nfd_win.cpp
vendored
89
extern/nfd-modified/src/nfd_win.cpp
vendored
|
@ -197,44 +197,19 @@ static void CopyNFDCharToWChar( const nfdchar_t *inStr, wchar_t **outStr )
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* 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 )
|
||||
static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileOpenDialog, const std::vector<std::string>& filterList )
|
||||
{
|
||||
const wchar_t WILDCARD[] = L"*.*";
|
||||
|
||||
if ( !filterList || strlen(filterList) == 0 )
|
||||
if (filterList.empty())
|
||||
return NFD_OKAY;
|
||||
|
||||
// list size has to be an even number (name/filter)
|
||||
if (filterList.size()&1)
|
||||
return NFD_ERROR;
|
||||
|
||||
// Count rows to alloc
|
||||
UINT filterCount = 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;
|
||||
}
|
||||
UINT filterCount = filterList.size()>>1; /* guaranteed to have one filter on a correct, non-empty parse */
|
||||
|
||||
assert(filterCount);
|
||||
if ( !filterCount )
|
||||
|
@ -256,43 +231,17 @@ static nfdresult_t AddFiltersToDialog( ::IFileDialog *fileOpenDialog, const char
|
|||
}
|
||||
|
||||
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];
|
||||
String spec=filterList[i+1];
|
||||
for (char& i: spec) {
|
||||
if (i==' ') i=',';
|
||||
}
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
if ( NFDi_IsFilterSegmentChar(*p_filterList) )
|
||||
{
|
||||
/* 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' )
|
||||
{
|
||||
/* 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;
|
||||
if ( specIdx == filterCount )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( !NFDi_IsFilterSegmentChar( *p_filterList ))
|
||||
{
|
||||
*p_typebuf = *p_filterList;
|
||||
++p_typebuf;
|
||||
}
|
||||
|
||||
++p_filterList;
|
||||
CopyNFDCharToWChar( name.c_str(), (wchar_t**)&specList[specIdx].pszName );
|
||||
CopyNFDCharToWChar( spec.c_str(), (wchar_t**)&specList[specIdx].pszSpec );
|
||||
++specIdx;
|
||||
}
|
||||
|
||||
/* Add wildcard */
|
||||
|
@ -450,7 +399,7 @@ static nfdresult_t SetDefaultPath( IFileDialog *dialog, const char *defaultPath
|
|||
/* public */
|
||||
|
||||
|
||||
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
|
||||
nfdresult_t NFD_OpenDialog( const std::vector<std::string>& filterList,
|
||||
const nfdchar_t *defaultPath,
|
||||
nfdchar_t **outPath,
|
||||
nfdselcallback_t selCallback )
|
||||
|
@ -558,7 +507,7 @@ end:
|
|||
return nfdResult;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
|
||||
nfdresult_t NFD_OpenDialogMultiple( const std::vector<std::string>& filterList,
|
||||
const nfdchar_t *defaultPath,
|
||||
nfdpathset_t *outPaths,
|
||||
nfdselcallback_t selCallback )
|
||||
|
@ -653,7 +602,7 @@ end:
|
|||
return nfdResult;
|
||||
}
|
||||
|
||||
nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
|
||||
nfdresult_t NFD_SaveDialog( const std::vector<std::string>& filterList,
|
||||
const nfdchar_t *defaultPath,
|
||||
nfdchar_t **outPath,
|
||||
nfdselcallback_t selCallback )
|
||||
|
|
|
@ -30,9 +30,9 @@ void _nfdThread(const NFDState state, std::atomic<bool>* ok, String* result) {
|
|||
nfdresult_t ret=NFD_CANCEL;
|
||||
|
||||
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 {
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue