Fix non-Windows dialog
This commit is contained in:
@@ -8,6 +8,15 @@
|
|||||||
namespace lime {
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
|
void wstringToChar (std::wstring source, char* destination) {
|
||||||
|
|
||||||
|
int size = std::wcslen (source->c_str ());
|
||||||
|
destination = (char*)malloc (size);
|
||||||
|
std::wcstombs (destination, source->c_str (), size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::wstring* FileDialog::OpenDirectory (std::wstring* filter, std::wstring* defaultPath) {
|
std::wstring* FileDialog::OpenDirectory (std::wstring* filter, std::wstring* defaultPath) {
|
||||||
|
|
||||||
// TODO: Filter?
|
// TODO: Filter?
|
||||||
@@ -26,14 +35,7 @@ namespace lime {
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
char* _defaultPath = 0;
|
char* _defaultPath = 0;
|
||||||
|
wstringToChar (defaultPath, _defaultPath);
|
||||||
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);
|
const char* path = tinyfd_selectFolderDialog ("", _defaultPath);
|
||||||
|
|
||||||
@@ -56,11 +58,11 @@ namespace lime {
|
|||||||
|
|
||||||
std::wstring* FileDialog::OpenFile (std::wstring* filter, std::wstring* defaultPath) {
|
std::wstring* FileDialog::OpenFile (std::wstring* filter, std::wstring* defaultPath) {
|
||||||
|
|
||||||
|
#ifdef HX_WINDOWS
|
||||||
|
|
||||||
std::wstring temp (L"*.");
|
std::wstring temp (L"*.");
|
||||||
const wchar_t* filters[] = { filter ? (temp + *filter).c_str () : NULL };
|
const wchar_t* filters[] = { filter ? (temp + *filter).c_str () : NULL };
|
||||||
|
|
||||||
#ifdef HX_WINDOWS
|
|
||||||
|
|
||||||
const wchar_t* path = tinyfd_openFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, filter ? 1 : 0, filter ? filters : NULL, NULL, 0);
|
const wchar_t* path = tinyfd_openFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, filter ? 1 : 0, filter ? filters : NULL, NULL, 0);
|
||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
@@ -72,13 +74,25 @@ namespace lime {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
char* _defaultPath = 0;
|
char* _filter = 0;
|
||||||
|
|
||||||
if (defaultPath) {
|
if (filter) {
|
||||||
|
|
||||||
int size = std::wcslen (defaultPath->c_str ());
|
|
||||||
char* _defaultPath = (char*)malloc (size);
|
|
||||||
std::wcstombs (_defaultPath, defaultPath->c_str (), size);
|
}
|
||||||
|
|
||||||
|
char* _filter = 0;
|
||||||
|
char* _defaultPath = 0;
|
||||||
|
wstringToChar (filter, _filter);
|
||||||
|
wstringToChar (defaultPath, _defaultPath);
|
||||||
|
|
||||||
|
const char_t* filters[] = { NULL };
|
||||||
|
|
||||||
|
if (_filter) {
|
||||||
|
|
||||||
|
std::string temp = std::string ("*.") + std::string (_filter);
|
||||||
|
filters[0] = temp.c_str ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,13 +117,13 @@ namespace lime {
|
|||||||
|
|
||||||
void FileDialog::OpenFiles (std::vector<std::wstring*>* files, std::wstring* filter, std::wstring* defaultPath) {
|
void FileDialog::OpenFiles (std::vector<std::wstring*>* files, std::wstring* filter, std::wstring* defaultPath) {
|
||||||
|
|
||||||
std::wstring temp (L"*.");
|
|
||||||
const wchar_t* filters[] = { filter ? (temp + *filter).c_str () : NULL };
|
|
||||||
|
|
||||||
std::wstring* __paths = 0;
|
std::wstring* __paths = 0;
|
||||||
|
|
||||||
#ifdef HX_WINDOWS
|
#ifdef HX_WINDOWS
|
||||||
|
|
||||||
|
std::wstring temp (L"*.");
|
||||||
|
const wchar_t* filters[] = { filter ? (temp + *filter).c_str () : NULL };
|
||||||
|
|
||||||
const wchar_t* paths = tinyfd_openFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, filter ? 1 : 0, filter ? filters : NULL, NULL, 1);
|
const wchar_t* paths = tinyfd_openFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, filter ? 1 : 0, filter ? filters : NULL, NULL, 1);
|
||||||
|
|
||||||
if (paths) {
|
if (paths) {
|
||||||
@@ -120,13 +134,17 @@ namespace lime {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
char* _filter = 0;
|
||||||
char* _defaultPath = 0;
|
char* _defaultPath = 0;
|
||||||
|
wstringToChar (filter, _filter);
|
||||||
|
wstringToChar (defaultPath, _defaultPath);
|
||||||
|
|
||||||
if (defaultPath) {
|
const char_t* filters[] = { NULL };
|
||||||
|
|
||||||
|
if (_filter) {
|
||||||
|
|
||||||
int size = std::wcslen (defaultPath->c_str ());
|
std::string temp = std::string ("*.") + std::string (_filter);
|
||||||
char* _defaultPath = (char*)malloc (size);
|
filters[0] = temp.c_str ();
|
||||||
std::wcstombs (_defaultPath, defaultPath->c_str (), size);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,11 +183,11 @@ namespace lime {
|
|||||||
|
|
||||||
std::wstring* FileDialog::SaveFile (std::wstring* filter, std::wstring* defaultPath) {
|
std::wstring* FileDialog::SaveFile (std::wstring* filter, std::wstring* defaultPath) {
|
||||||
|
|
||||||
|
#ifdef HX_WINDOWS
|
||||||
|
|
||||||
std::wstring temp (L"*.");
|
std::wstring temp (L"*.");
|
||||||
const wchar_t* filters[] = { filter ? (temp + *filter).c_str () : NULL };
|
const wchar_t* filters[] = { filter ? (temp + *filter).c_str () : NULL };
|
||||||
|
|
||||||
#ifdef HX_WINDOWS
|
|
||||||
|
|
||||||
const wchar_t* path = tinyfd_saveFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, filter ? 1 : 0, filter ? filters : NULL, NULL);
|
const wchar_t* path = tinyfd_saveFileDialogW (L"", defaultPath ? defaultPath->c_str () : 0, filter ? 1 : 0, filter ? filters : NULL, NULL);
|
||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
@@ -181,13 +199,17 @@ namespace lime {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
char* _filter = 0;
|
||||||
char* _defaultPath = 0;
|
char* _defaultPath = 0;
|
||||||
|
wstringToChar (filter, _filter);
|
||||||
|
wstringToChar (defaultPath, _defaultPath);
|
||||||
|
|
||||||
if (defaultPath) {
|
const char_t* filters[] = { NULL };
|
||||||
|
|
||||||
|
if (_filter) {
|
||||||
|
|
||||||
int size = std::wcslen (defaultPath->c_str ());
|
std::string temp = std::string ("*.") + std::string (_filter);
|
||||||
char* _defaultPath = (char*)malloc (size);
|
filters[0] = temp.c_str ();
|
||||||
std::wcstombs (_defaultPath, defaultPath->c_str (), size);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user