Switch to tinyfiledialogs, implement unicode on Windows
This commit is contained in:
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -40,6 +40,6 @@
|
||||
[submodule "project/lib/lzma"]
|
||||
path = project/lib/lzma
|
||||
url = https://github.com/native-toolkit/lzma
|
||||
[submodule "project/lib/nfd"]
|
||||
path = project/lib/nfd
|
||||
url = https://github.com/native-toolkit/nfd
|
||||
[submodule "project/lib/tinyfiledialogs"]
|
||||
path = project/lib/tinyfiledialogs
|
||||
url = https://github.com/native-toolkit/tinyfiledialogs
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
<set name="LIME_HARFBUZZ" value="1" />
|
||||
<set name="LIME_LZMA" value="1" />
|
||||
<!-- <set name="LIME_NEKO" value="1" if="linux" /> -->
|
||||
<set name="LIME_NFD" value="1" if="windows || mac" />
|
||||
<set name="LIME_OGG" value="1" />
|
||||
<set name="LIME_OPENALSOFT" value="1" if="windows || linux || android" unless="static_link" />
|
||||
<set name="LIME_OPENAL" value="1" if="mac || iphone || emscripten || tvos" />
|
||||
@@ -27,6 +26,7 @@
|
||||
<set name="LIME_SDL" value="1" />
|
||||
<!-- <set name="LIME_SDL_ANGLE" value="1" if="windows" unless="static_link" /> -->
|
||||
<set name="LIME_SDL_ANGLE" value="1" if="windows LIME_SDL_ANGLE" unless="static_link" />
|
||||
<set name="LIME_TINYFILEDIALOGS" value="1" if="windows || mac || linux" />
|
||||
<set name="LIME_VORBIS" value="1" />
|
||||
<set name="LIME_ZLIB" value="1" />
|
||||
|
||||
@@ -117,15 +117,6 @@
|
||||
|
||||
</section>
|
||||
|
||||
<section if="LIME_NFD">
|
||||
|
||||
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/nfd/src/include/" />
|
||||
<compilerflag value="-DLIME_NFD" />
|
||||
|
||||
<file name="src/ui/FileDialog.cpp" />
|
||||
|
||||
</section>
|
||||
|
||||
<section if="LIME_OGG">
|
||||
|
||||
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/ogg/include/" />
|
||||
@@ -206,6 +197,15 @@
|
||||
|
||||
</section>
|
||||
|
||||
<section if="LIME_TINYFILEDIALOGS">
|
||||
|
||||
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/tinyfiledialogs/" />
|
||||
<compilerflag value="-DLIME_TINYFILEDIALOGS" />
|
||||
|
||||
<file name="src/ui/FileDialog.cpp" />
|
||||
|
||||
</section>
|
||||
|
||||
<section if="LIME_ZLIB">
|
||||
|
||||
<compilerflag value="-DSTATIC_LINK" if="emscripten" />
|
||||
@@ -256,12 +256,12 @@
|
||||
<include name="lib/jpeg/files.xml" />
|
||||
<include name="lib/lzma/files.xml" />
|
||||
<include name="lib/neko/files.xml" />
|
||||
<include name="lib/nfd/files.xml" />
|
||||
<include name="lib/ogg/files.xml" />
|
||||
<include name="lib/openal/files.xml" />
|
||||
<include name="lib/pixman/files.xml" />
|
||||
<include name="lib/png/files.xml" />
|
||||
<include name="lib/sdl/files.xml" />
|
||||
<include name="lib/tinyfiledialogs/files.xml" />
|
||||
<include name="lib/vorbis/files.xml" />
|
||||
<include name="lib/zlib/files.xml" />
|
||||
|
||||
@@ -282,12 +282,12 @@
|
||||
<files id="native-toolkit-harfbuzz" if="LIME_HARFBUZZ" />
|
||||
<files id="native-toolkit-lzma" if="LIME_LZMA" />
|
||||
<files id="native-toolkit-neko" if="LIME_NEKO" />
|
||||
<files id="native-toolkit-nfd" if="LIME_NFD" />
|
||||
<files id="native-toolkit-ogg" if="LIME_OGG" />
|
||||
<files id="native-toolkit-openal" if="LIME_OPENALSOFT" />
|
||||
<files id="native-toolkit-pixman" if="LIME_PIXMAN" />
|
||||
<files id="native-toolkit-png" if="LIME_PNG" />
|
||||
<files id="native-toolkit-sdl" if="LIME_SDL" unless="emscripten" />
|
||||
<files id="native-toolkit-tinyfiledialogs" if="LIME_TINYFILEDIALOGS" />
|
||||
<files id="native-toolkit-vorbis" if="LIME_VORBIS" />
|
||||
<files id="native-toolkit-zlib" if="LIME_ZLIB" />
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define LIME_UI_FILE_DIALOG_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -12,10 +13,10 @@ namespace lime {
|
||||
|
||||
public:
|
||||
|
||||
static const char* OpenDirectory (const char* filter = 0, const char* defaultPath = 0);
|
||||
static const char* OpenFile (const char* filter = 0, const char* defaultPath = 0);
|
||||
static void OpenFiles (std::vector<const char*>* files, const char* filter = 0, const char* defaultPath = 0);
|
||||
static const char* SaveFile (const char* filter = 0, const char* defaultPath = 0);
|
||||
static std::wstring* OpenDirectory (std::wstring* filter = 0, std::wstring* defaultPath = 0);
|
||||
static std::wstring* OpenFile (std::wstring* filter = 0, std::wstring* defaultPath = 0);
|
||||
static void OpenFiles (std::vector<std::wstring*>* files, std::wstring* filter = 0, std::wstring* defaultPath = 0);
|
||||
static std::wstring* SaveFile (std::wstring* filter = 0, std::wstring* defaultPath = 0);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Submodule project/lib/nfd deleted from e9e3636b03
1
project/lib/tinyfiledialogs
Submodule
1
project/lib/tinyfiledialogs
Submodule
Submodule project/lib/tinyfiledialogs added at 9e9fc169a1
@@ -98,6 +98,22 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
std::wstring* hxstring_to_wstring (HxString val) {
|
||||
|
||||
if (val.c_str ()) {
|
||||
|
||||
std::string _val = std::string (val.c_str ());
|
||||
return new std::wstring (_val.begin (), _val.end ());
|
||||
|
||||
} else {
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_application_create (value callback) {
|
||||
|
||||
Application* application = CreateApplication ();
|
||||
@@ -318,63 +334,89 @@ namespace lime {
|
||||
|
||||
value lime_file_dialog_open_directory (HxString filter, HxString defaultPath) {
|
||||
|
||||
#ifdef LIME_NFD
|
||||
const char* path = FileDialog::OpenDirectory (filter.c_str (), defaultPath.c_str ());
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
std::wstring* path = FileDialog::OpenDirectory (_filter, _defaultPath);
|
||||
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
if (path) {
|
||||
|
||||
value _path = alloc_string (path);
|
||||
free ((char*) path);
|
||||
value _path = alloc_wstring (path->c_str ());
|
||||
delete path;
|
||||
return _path;
|
||||
|
||||
} else {
|
||||
|
||||
delete path;
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
value lime_file_dialog_open_file (HxString filter, HxString defaultPath) {
|
||||
|
||||
#ifdef LIME_NFD
|
||||
const char* path = FileDialog::OpenFile (filter.c_str (), defaultPath.c_str ());
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
std::wstring* path = FileDialog::OpenFile (_filter, _defaultPath);
|
||||
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
if (path) {
|
||||
|
||||
value _path = alloc_string (path);
|
||||
free ((char*) path);
|
||||
value _path = alloc_wstring (path->c_str ());
|
||||
delete path;
|
||||
return _path;
|
||||
|
||||
} else {
|
||||
|
||||
delete path;
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_file_dialog_open_files (HxString filter, HxString defaultPath) {
|
||||
|
||||
#ifdef LIME_NFD
|
||||
std::vector<const char*> files;
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
FileDialog::OpenFiles (&files, filter.c_str (), defaultPath.c_str ());
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
std::vector<std::wstring*> files;
|
||||
|
||||
FileDialog::OpenFiles (&files, _filter, _defaultPath);
|
||||
value result = alloc_array (files.size ());
|
||||
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
for (int i = 0; i < files.size (); i++) {
|
||||
|
||||
val_array_set_i (result, i, alloc_string (files[i]));
|
||||
free ((char*)files[i]);
|
||||
val_array_set_i (result, i, alloc_wstring (files[i]->c_str ()));
|
||||
delete files[i];
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
value result = alloc_array (0);
|
||||
#endif
|
||||
@@ -386,23 +428,32 @@ namespace lime {
|
||||
|
||||
value lime_file_dialog_save_file (HxString filter, HxString defaultPath) {
|
||||
|
||||
#ifdef LIME_NFD
|
||||
const char* path = FileDialog::SaveFile (filter.c_str (), defaultPath.c_str ());
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
std::wstring* path = FileDialog::SaveFile (_filter, _defaultPath);
|
||||
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
if (path) {
|
||||
|
||||
value _path = alloc_string (path);
|
||||
free ((char*) path);
|
||||
value _path = alloc_wstring (path->c_str ());
|
||||
delete path;
|
||||
return _path;
|
||||
|
||||
} else {
|
||||
|
||||
delete path;
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
@@ -413,7 +464,7 @@ namespace lime {
|
||||
Font *font = (Font*)val_data (fontHandle);
|
||||
return font->GetAscender ();
|
||||
#else
|
||||
return 0;
|
||||
return alloc_null ();
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -425,7 +476,7 @@ namespace lime {
|
||||
Font *font = (Font*)val_data (fontHandle);
|
||||
return font->GetDescender ();
|
||||
#else
|
||||
return 0;
|
||||
return alloc_null ();
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -440,7 +491,7 @@ namespace lime {
|
||||
delete name;
|
||||
return result;
|
||||
#else
|
||||
return 0;
|
||||
return alloc_null ();
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -488,7 +539,7 @@ namespace lime {
|
||||
Font *font = (Font*)val_data (fontHandle);
|
||||
return font->GetHeight ();
|
||||
#else
|
||||
return 0;
|
||||
return alloc_null ();
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -512,7 +563,7 @@ namespace lime {
|
||||
Font *font = (Font*)val_data (fontHandle);
|
||||
return font->GetUnderlinePosition ();
|
||||
#else
|
||||
return 0;
|
||||
return alloc_null ();
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -524,7 +575,7 @@ namespace lime {
|
||||
Font *font = (Font*)val_data (fontHandle);
|
||||
return font->GetUnderlineThickness ();
|
||||
#else
|
||||
return 0;
|
||||
return alloc_null ();
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -536,7 +587,7 @@ namespace lime {
|
||||
Font *font = (Font*)val_data (fontHandle);
|
||||
return font->GetUnitsPerEM ();
|
||||
#else
|
||||
return 0;
|
||||
return alloc_null ();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -1,124 +1,207 @@
|
||||
#include <ui/FileDialog.h>
|
||||
#include <nfd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <tinyfiledialogs.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
const char* FileDialog::OpenDirectory (const char* filter, const char* defaultPath) {
|
||||
std::wstring* FileDialog::OpenDirectory (std::wstring* filter, std::wstring* defaultPath) {
|
||||
|
||||
nfdchar_t *savePath = 0;
|
||||
nfdresult_t result = NFD_OpenDirectoryDialog (filter, defaultPath, &savePath);
|
||||
// TODO: Filters
|
||||
|
||||
switch (result) {
|
||||
#ifdef HX_WINDOWS
|
||||
|
||||
case NFD_OKAY:
|
||||
const wchar_t* path = tinyfd_selectFolderDialogW (L"", defaultPath ? defaultPath->c_str () : 0);
|
||||
|
||||
return savePath;
|
||||
break;
|
||||
if (path) {
|
||||
|
||||
case NFD_CANCEL:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
printf ("Error: %s\n", NFD_GetError ());
|
||||
break;
|
||||
std::wstring* _path = new std::wstring (path);
|
||||
return _path;
|
||||
|
||||
}
|
||||
|
||||
return savePath;
|
||||
#else
|
||||
|
||||
char* _defaultPath = 0;
|
||||
|
||||
if (defaultPath) {
|
||||
|
||||
int size = std::wcslen (defaultPath->c_str ());
|
||||
char* _defaultPath = (char*)malloc (size);
|
||||
std::wcstombs (_defaultPath, defaultPath->c_str (), size);
|
||||
|
||||
}
|
||||
|
||||
const char* path = tinyfd_selectFolderDialog ("", _defaultPath);
|
||||
|
||||
if (_defaultPath) free (_defaultPath);
|
||||
|
||||
if (path) {
|
||||
|
||||
std::string _path = std::string (path);
|
||||
std::wstring* __path = new std::wstring (_path.begin (), _path.end ());
|
||||
return __path;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
const char* FileDialog::OpenFile (const char* filter, const char* defaultPath) {
|
||||
std::wstring* FileDialog::OpenFile (std::wstring* filter, std::wstring* defaultPath) {
|
||||
|
||||
nfdchar_t *savePath = 0;
|
||||
nfdresult_t result = NFD_OpenDialog (filter, defaultPath, &savePath);
|
||||
// TODO: Filters
|
||||
|
||||
switch (result) {
|
||||
#ifdef HX_WINDOWS
|
||||
|
||||
case NFD_OKAY:
|
||||
const wchar_t* path = tinyfd_openFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, 0, NULL, NULL, 0);
|
||||
|
||||
return savePath;
|
||||
break;
|
||||
if (path) {
|
||||
|
||||
case NFD_CANCEL:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
printf ("Error: %s\n", NFD_GetError ());
|
||||
break;
|
||||
std::wstring* _path = new std::wstring (path);
|
||||
return _path;
|
||||
|
||||
}
|
||||
|
||||
return savePath;
|
||||
#else
|
||||
|
||||
char* _defaultPath = 0;
|
||||
|
||||
if (defaultPath) {
|
||||
|
||||
int size = std::wcslen (defaultPath->c_str ());
|
||||
char* _defaultPath = (char*)malloc (size);
|
||||
std::wcstombs (_defaultPath, defaultPath->c_str (), size);
|
||||
|
||||
}
|
||||
|
||||
const char* path = tinyfd_openFileDialog ("", _defaultPath, 0, NULL, NULL, 0);
|
||||
|
||||
if (_defaultPath) free (_defaultPath);
|
||||
|
||||
if (path) {
|
||||
|
||||
std::string _path = std::string (path);
|
||||
std::wstring* __path = new std::wstring (_path.begin (), _path.end ());
|
||||
return __path;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FileDialog::OpenFiles (std::vector<const char*>* files, const char* filter, const char* defaultPath) {
|
||||
void FileDialog::OpenFiles (std::vector<std::wstring*>* files, std::wstring* filter, std::wstring* defaultPath) {
|
||||
|
||||
nfdpathset_t pathSet;
|
||||
nfdresult_t result = NFD_OpenDialogMultiple (filter, defaultPath, &pathSet);
|
||||
// TODO: Filters
|
||||
|
||||
switch (result) {
|
||||
std::wstring* __paths = 0;
|
||||
|
||||
case NFD_OKAY:
|
||||
{
|
||||
for (int i = 0; i < NFD_PathSet_GetCount (&pathSet); i++) {
|
||||
#ifdef HX_WINDOWS
|
||||
|
||||
files->push_back (NFD_PathSet_GetPath (&pathSet, i));
|
||||
const wchar_t* paths = tinyfd_openFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, 0, NULL, NULL, 1);
|
||||
|
||||
}
|
||||
if (paths) {
|
||||
|
||||
__paths = new std::wstring (paths);
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
char* _defaultPath = 0;
|
||||
|
||||
if (defaultPath) {
|
||||
|
||||
int size = std::wcslen (defaultPath->c_str ());
|
||||
char* _defaultPath = (char*)malloc (size);
|
||||
std::wcstombs (_defaultPath, defaultPath->c_str (), size);
|
||||
|
||||
}
|
||||
|
||||
const char* paths = tinyfd_openFileDialog ("", _defaultPath, 0, NULL, NULL, 1);
|
||||
|
||||
if (_defaultPath) free (_defaultPath);
|
||||
|
||||
if (paths) {
|
||||
|
||||
std::string _paths = std::string (paths);
|
||||
__paths = new std::wstring (_paths.begin (), _paths.end ());
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (__paths) {
|
||||
|
||||
std::wstring sep = L"|";
|
||||
|
||||
std::size_t start = 0, end = 0;
|
||||
|
||||
while ((end = __paths->find (sep, start)) != std::wstring::npos) {
|
||||
|
||||
files->push_back (new std::wstring (__paths->substr (start, end - start).c_str ()));
|
||||
start = end + 1;
|
||||
|
||||
NFD_PathSet_Free (&pathSet);
|
||||
break;
|
||||
}
|
||||
|
||||
case NFD_CANCEL:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
printf ("Error: %s\n", NFD_GetError ());
|
||||
break;
|
||||
files->push_back (new std::wstring (__paths->substr (start).c_str ()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
const char* FileDialog::SaveFile (const char* filter, const char* defaultPath) {
|
||||
std::wstring* FileDialog::SaveFile (std::wstring* filter, std::wstring* defaultPath) {
|
||||
|
||||
nfdchar_t *savePath = 0;
|
||||
nfdresult_t result = NFD_SaveDialog (filter, defaultPath, &savePath);
|
||||
// TODO: Filters
|
||||
|
||||
switch (result) {
|
||||
#ifdef HX_WINDOWS
|
||||
|
||||
case NFD_OKAY:
|
||||
const wchar_t* path = tinyfd_saveFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, 0, NULL, NULL);
|
||||
|
||||
return savePath;
|
||||
break;
|
||||
if (path) {
|
||||
|
||||
case NFD_CANCEL:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
printf ("Error: %s\n", NFD_GetError ());
|
||||
break;
|
||||
std::wstring* _path = new std::wstring (path);
|
||||
return _path;
|
||||
|
||||
}
|
||||
|
||||
return savePath;
|
||||
#else
|
||||
|
||||
char* _defaultPath = 0;
|
||||
|
||||
if (defaultPath) {
|
||||
|
||||
int size = std::wcslen (defaultPath->c_str ());
|
||||
char* _defaultPath = (char*)malloc (size);
|
||||
std::wcstombs (_defaultPath, defaultPath->c_str (), size);
|
||||
|
||||
}
|
||||
|
||||
const char* path = tinyfd_saveFileDialog ("", _defaultPath, 0, NULL, NULL);
|
||||
|
||||
if (_defaultPath) free (_defaultPath);
|
||||
|
||||
if (path) {
|
||||
|
||||
std::string _path = std::string (path);
|
||||
std::wstring* __path = new std::wstring (_path.begin (), _path.end ());
|
||||
return __path;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user