diff --git a/.gitmodules b/.gitmodules
index ca8879d31..0b537db5f 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -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
diff --git a/project/Build.xml b/project/Build.xml
index d932d59fb..f32be95a1 100644
--- a/project/Build.xml
+++ b/project/Build.xml
@@ -16,7 +16,6 @@
-
@@ -27,6 +26,7 @@
+
@@ -117,15 +117,6 @@
-
-
+
+
@@ -256,12 +256,12 @@
-
+
@@ -282,12 +282,12 @@
-
+
diff --git a/project/include/ui/FileDialog.h b/project/include/ui/FileDialog.h
index 815c77f6e..42e973895 100644
--- a/project/include/ui/FileDialog.h
+++ b/project/include/ui/FileDialog.h
@@ -2,6 +2,7 @@
#define LIME_UI_FILE_DIALOG_H
+#include
#include
@@ -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* 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* files, std::wstring* filter = 0, std::wstring* defaultPath = 0);
+ static std::wstring* SaveFile (std::wstring* filter = 0, std::wstring* defaultPath = 0);
};
diff --git a/project/lib/nfd b/project/lib/nfd
deleted file mode 160000
index e9e3636b0..000000000
--- a/project/lib/nfd
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit e9e3636b031797396aa502b78432ae1347c2afe3
diff --git a/project/lib/tinyfiledialogs b/project/lib/tinyfiledialogs
new file mode 160000
index 000000000..9e9fc169a
--- /dev/null
+++ b/project/lib/tinyfiledialogs
@@ -0,0 +1 @@
+Subproject commit 9e9fc169a1465c4550d8fe5efe4f654feae10675
diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp
index d6e6bc28d..5390a99b8 100644
--- a/project/src/ExternalInterface.cpp
+++ b/project/src/ExternalInterface.cpp
@@ -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 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 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
}
diff --git a/project/src/ui/FileDialog.cpp b/project/src/ui/FileDialog.cpp
index 9bd7fe0c9..a43c1fdba 100644
--- a/project/src/ui/FileDialog.cpp
+++ b/project/src/ui/FileDialog.cpp
@@ -1,124 +1,207 @@
#include
-#include
#include
+#include
+
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
+
+ const wchar_t* path = tinyfd_selectFolderDialogW (L"", defaultPath ? defaultPath->c_str () : 0);
+
+ if (path) {
- case NFD_OKAY:
-
- return savePath;
- break;
-
- 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
+
+ const wchar_t* path = tinyfd_openFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, 0, NULL, NULL, 0);
+
+ if (path) {
- case NFD_OKAY:
-
- return savePath;
- break;
-
- 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* files, const char* filter, const char* defaultPath) {
+ void FileDialog::OpenFiles (std::vector* 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;
+
+ #ifdef HX_WINDOWS
+
+ const wchar_t* paths = tinyfd_openFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, 0, NULL, NULL, 1);
+
+ if (paths) {
- case NFD_OKAY:
- {
- for (int i = 0; i < NFD_PathSet_GetCount (&pathSet); i++) {
-
- files->push_back (NFD_PathSet_GetPath (&pathSet, i));
-
- }
+ __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
+
+ const wchar_t* path = tinyfd_saveFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, 0, NULL, NULL);
+
+ if (path) {
- case NFD_OKAY:
-
- return savePath;
- break;
-
- 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;
}