Dialog fixes
This commit is contained in:
@@ -40,10 +40,10 @@ class NativeCFFI {
|
||||
@:cffi private static function lime_deflate_compress (data:Dynamic, bytes:Dynamic):Dynamic;
|
||||
@:cffi private static function lime_deflate_decompress (data:Dynamic, bytes:Dynamic):Dynamic;
|
||||
@:cffi private static function lime_drop_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
|
||||
@:cffi private static function lime_file_dialog_open_directory (filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_dialog_open_file (filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_dialog_open_files (filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_dialog_save_file (filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_dialog_open_directory (title:String, filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_dialog_open_file (title:String, filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_dialog_open_files (title:String, filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_dialog_save_file (title:String, filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_font_get_ascender (handle:Dynamic):Int;
|
||||
@:cffi private static function lime_font_get_descender (handle:Dynamic):Int;
|
||||
@:cffi private static function lime_font_get_family_name (handle:Dynamic):Dynamic;
|
||||
|
||||
@@ -35,7 +35,7 @@ class FileDialog {
|
||||
}
|
||||
|
||||
|
||||
public function browse (type:FileDialogType = null, filter:String = null, defaultPath:String = null):Bool {
|
||||
public function browse (type:FileDialogType = null, filter:String = null, defaultPath:String = null, title:String = null):Bool {
|
||||
|
||||
if (type == null) type = FileDialogType.OPEN;
|
||||
|
||||
@@ -49,19 +49,35 @@ class FileDialog {
|
||||
|
||||
case OPEN:
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_open_file (filter, defaultPath));
|
||||
#if linux
|
||||
if (title == null) title = "Open File";
|
||||
#end
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_open_file (title, filter, defaultPath));
|
||||
|
||||
case OPEN_MULTIPLE:
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_open_files (filter, defaultPath));
|
||||
#if linux
|
||||
if (title == null) title = "Open Files";
|
||||
#end
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_open_files (title, filter, defaultPath));
|
||||
|
||||
case OPEN_DIRECTORY:
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_open_directory (filter, defaultPath));
|
||||
#if linux
|
||||
if (title == null) title = "Open Directory";
|
||||
#end
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_open_directory (title, filter, defaultPath));
|
||||
|
||||
case SAVE:
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_save_file (filter, defaultPath));
|
||||
#if linux
|
||||
if (title == null) title = "Save File";
|
||||
#end
|
||||
trace (title);
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_save_file (title, filter, defaultPath));
|
||||
|
||||
}
|
||||
|
||||
@@ -124,7 +140,7 @@ class FileDialog {
|
||||
}
|
||||
|
||||
|
||||
public function open (filter:String = null, defaultPath:String = null):Bool {
|
||||
public function open (filter:String = null, defaultPath:String = null, title:String = null):Bool {
|
||||
|
||||
#if desktop
|
||||
|
||||
@@ -132,7 +148,11 @@ class FileDialog {
|
||||
|
||||
worker.doWork.add (function (_) {
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_open_file (filter, defaultPath));
|
||||
#if linux
|
||||
if (title == null) title = "Open File";
|
||||
#end
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_open_file (title, filter, defaultPath));
|
||||
|
||||
});
|
||||
|
||||
@@ -168,7 +188,7 @@ class FileDialog {
|
||||
}
|
||||
|
||||
|
||||
public function save (data:Resource, filter:String = null, defaultPath:String = null):Bool {
|
||||
public function save (data:Resource, filter:String = null, defaultPath:String = null, title:String = null):Bool {
|
||||
|
||||
#if desktop
|
||||
|
||||
@@ -176,7 +196,11 @@ class FileDialog {
|
||||
|
||||
worker.doWork.add (function (_) {
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_save_file (filter, defaultPath));
|
||||
#if linux
|
||||
if (title == null) title = "Save File";
|
||||
#end
|
||||
|
||||
worker.sendComplete (NativeCFFI.lime_file_dialog_save_file (title, filter, defaultPath));
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ namespace lime {
|
||||
|
||||
public:
|
||||
|
||||
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);
|
||||
static std::wstring* OpenDirectory (std::wstring* title = 0, std::wstring* filter = 0, std::wstring* defaultPath = 0);
|
||||
static std::wstring* OpenFile (std::wstring* title = 0, std::wstring* filter = 0, std::wstring* defaultPath = 0);
|
||||
static void OpenFiles (std::vector<std::wstring*>* files, std::wstring* title = 0, std::wstring* filter = 0, std::wstring* defaultPath = 0);
|
||||
static std::wstring* SaveFile (std::wstring* title = 0, std::wstring* filter = 0, std::wstring* defaultPath = 0);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -332,15 +332,17 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_file_dialog_open_directory (HxString filter, HxString defaultPath) {
|
||||
value lime_file_dialog_open_directory (HxString title, HxString filter, HxString defaultPath) {
|
||||
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
std::wstring* _title = hxstring_to_wstring (title);
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
std::wstring* path = FileDialog::OpenDirectory (_filter, _defaultPath);
|
||||
std::wstring* path = FileDialog::OpenDirectory (_title, _filter, _defaultPath);
|
||||
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
@@ -363,15 +365,17 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
value lime_file_dialog_open_file (HxString filter, HxString defaultPath) {
|
||||
value lime_file_dialog_open_file (HxString title, HxString filter, HxString defaultPath) {
|
||||
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
std::wstring* _title = hxstring_to_wstring (title);
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
std::wstring* path = FileDialog::OpenFile (_filter, _defaultPath);
|
||||
std::wstring* path = FileDialog::OpenFile (_title, _filter, _defaultPath);
|
||||
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
@@ -395,18 +399,20 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_file_dialog_open_files (HxString filter, HxString defaultPath) {
|
||||
value lime_file_dialog_open_files (HxString title, HxString filter, HxString defaultPath) {
|
||||
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
std::wstring* _title = hxstring_to_wstring (title);
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
std::vector<std::wstring*> files;
|
||||
|
||||
FileDialog::OpenFiles (&files, _filter, _defaultPath);
|
||||
FileDialog::OpenFiles (&files, _title, _filter, _defaultPath);
|
||||
value result = alloc_array (files.size ());
|
||||
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
@@ -426,15 +432,17 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_file_dialog_save_file (HxString filter, HxString defaultPath) {
|
||||
value lime_file_dialog_save_file (HxString title, HxString filter, HxString defaultPath) {
|
||||
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
std::wstring* _title = hxstring_to_wstring (title);
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
std::wstring* path = FileDialog::SaveFile (_filter, _defaultPath);
|
||||
std::wstring* path = FileDialog::SaveFile (_title, _filter, _defaultPath);
|
||||
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
@@ -1753,10 +1761,10 @@ namespace lime {
|
||||
DEFINE_PRIME2 (lime_deflate_compress);
|
||||
DEFINE_PRIME2 (lime_deflate_decompress);
|
||||
DEFINE_PRIME2v (lime_drop_event_manager_register);
|
||||
DEFINE_PRIME2 (lime_file_dialog_open_directory);
|
||||
DEFINE_PRIME2 (lime_file_dialog_open_file);
|
||||
DEFINE_PRIME2 (lime_file_dialog_open_files);
|
||||
DEFINE_PRIME2 (lime_file_dialog_save_file);
|
||||
DEFINE_PRIME3 (lime_file_dialog_open_directory);
|
||||
DEFINE_PRIME3 (lime_file_dialog_open_file);
|
||||
DEFINE_PRIME3 (lime_file_dialog_open_files);
|
||||
DEFINE_PRIME3 (lime_file_dialog_save_file);
|
||||
DEFINE_PRIME1 (lime_font_get_ascender);
|
||||
DEFINE_PRIME1 (lime_font_get_descender);
|
||||
DEFINE_PRIME1 (lime_font_get_family_name);
|
||||
|
||||
@@ -8,22 +8,28 @@
|
||||
namespace lime {
|
||||
|
||||
|
||||
void wstringToChar (std::wstring* source, char* destination) {
|
||||
std::string* wstring_to_string (std::wstring* source) {
|
||||
|
||||
if (!source) return NULL;
|
||||
|
||||
int size = std::wcslen (source->c_str ());
|
||||
destination = (char*)malloc (size);
|
||||
std::wcstombs (destination, source->c_str (), size);
|
||||
char* temp = (char*)malloc (size);
|
||||
std::wcstombs (temp, source->c_str (), size);
|
||||
|
||||
std::string* data = new std::string (temp);
|
||||
free (temp);
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::wstring* FileDialog::OpenDirectory (std::wstring* filter, std::wstring* defaultPath) {
|
||||
std::wstring* FileDialog::OpenDirectory (std::wstring* title, std::wstring* filter, std::wstring* defaultPath) {
|
||||
|
||||
// TODO: Filter?
|
||||
|
||||
#ifdef HX_WINDOWS
|
||||
|
||||
const wchar_t* path = tinyfd_selectFolderDialogW (L"", defaultPath ? defaultPath->c_str () : 0);
|
||||
const wchar_t* path = tinyfd_selectFolderDialogW (title ? title->c_str () : 0, defaultPath ? defaultPath->c_str () : 0);
|
||||
|
||||
if (path) {
|
||||
|
||||
@@ -34,12 +40,15 @@ namespace lime {
|
||||
|
||||
#else
|
||||
|
||||
char* _defaultPath = 0;
|
||||
wstringToChar (defaultPath, _defaultPath);
|
||||
std::string* _title = wstring_to_string (title);
|
||||
//std::string* _filter = wstring_to_string (filter);
|
||||
std::string* _defaultPath = wstring_to_string (defaultPath);
|
||||
|
||||
const char* path = tinyfd_selectFolderDialog ("", _defaultPath);
|
||||
const char* path = tinyfd_selectFolderDialog (_title ? _title->c_str () : NULL, _defaultPath ? _defaultPath->c_str () : NULL);
|
||||
|
||||
if (_defaultPath) free (_defaultPath);
|
||||
if (_title) delete _title;
|
||||
//if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
if (path) {
|
||||
|
||||
@@ -56,14 +65,14 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
std::wstring* FileDialog::OpenFile (std::wstring* filter, std::wstring* defaultPath) {
|
||||
std::wstring* FileDialog::OpenFile (std::wstring* title, std::wstring* filter, std::wstring* defaultPath) {
|
||||
|
||||
#ifdef HX_WINDOWS
|
||||
|
||||
std::wstring temp (L"*.");
|
||||
const wchar_t* filters[] = { filter ? (temp + *filter).c_str () : NULL };
|
||||
|
||||
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 (title ? title->c_str () : 0, defaultPath ? defaultPath->c_str () : 0, filter ? 1 : 0, filter ? filters : NULL, NULL, 0);
|
||||
|
||||
if (path) {
|
||||
|
||||
@@ -74,23 +83,24 @@ namespace lime {
|
||||
|
||||
#else
|
||||
|
||||
char* _filter = 0;
|
||||
char* _defaultPath = 0;
|
||||
wstringToChar (filter, _filter);
|
||||
wstringToChar (defaultPath, _defaultPath);
|
||||
std::string* _title = wstring_to_string (title);
|
||||
std::string* _filter = wstring_to_string (filter);
|
||||
std::string* _defaultPath = wstring_to_string (defaultPath);
|
||||
|
||||
const char* filters[] = { NULL };
|
||||
|
||||
if (_filter) {
|
||||
|
||||
std::string temp = std::string ("*.") + std::string (_filter);
|
||||
filters[0] = temp.c_str ();
|
||||
_filter->insert (0, "*.");
|
||||
filters[0] = _filter->c_str ();
|
||||
|
||||
}
|
||||
|
||||
const char* path = tinyfd_openFileDialog ("", _defaultPath, filter ? 1 : 0, filter ? filters : NULL, NULL, 0);
|
||||
const char* path = tinyfd_openFileDialog (_title ? _title->c_str () : NULL, _defaultPath ? _defaultPath->c_str () : NULL, _filter ? 1 : 0, _filter ? filters : NULL, NULL, 0);
|
||||
|
||||
if (_defaultPath) free (_defaultPath);
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
if (path) {
|
||||
|
||||
@@ -107,7 +117,7 @@ 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* title, std::wstring* filter, std::wstring* defaultPath) {
|
||||
|
||||
std::wstring* __paths = 0;
|
||||
|
||||
@@ -116,7 +126,7 @@ namespace lime {
|
||||
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 (title ? title->c_str () : 0, defaultPath ? defaultPath->c_str () : 0, filter ? 1 : 0, filter ? filters : NULL, NULL, 1);
|
||||
|
||||
if (paths) {
|
||||
|
||||
@@ -126,23 +136,24 @@ namespace lime {
|
||||
|
||||
#else
|
||||
|
||||
char* _filter = 0;
|
||||
char* _defaultPath = 0;
|
||||
wstringToChar (filter, _filter);
|
||||
wstringToChar (defaultPath, _defaultPath);
|
||||
std::string* _title = wstring_to_string (title);
|
||||
std::string* _filter = wstring_to_string (filter);
|
||||
std::string* _defaultPath = wstring_to_string (defaultPath);
|
||||
|
||||
const char* filters[] = { NULL };
|
||||
|
||||
if (_filter) {
|
||||
|
||||
std::string temp = std::string ("*.") + std::string (_filter);
|
||||
filters[0] = temp.c_str ();
|
||||
_filter->insert (0, "*.");
|
||||
filters[0] = _filter->c_str ();
|
||||
|
||||
}
|
||||
|
||||
const char* paths = tinyfd_openFileDialog ("", _defaultPath, filter ? 1 : 0, filter ? filters : NULL, NULL, 1);
|
||||
const char* paths = tinyfd_openFileDialog (_title ? _title->c_str () : NULL, _defaultPath ? _defaultPath->c_str () : NULL, _filter ? 1 : 0, _filter ? filters : NULL, NULL, 1);
|
||||
|
||||
if (_defaultPath) free (_defaultPath);
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
if (paths) {
|
||||
|
||||
@@ -173,14 +184,14 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
std::wstring* FileDialog::SaveFile (std::wstring* filter, std::wstring* defaultPath) {
|
||||
std::wstring* FileDialog::SaveFile (std::wstring* title, std::wstring* filter, std::wstring* defaultPath) {
|
||||
|
||||
#ifdef HX_WINDOWS
|
||||
|
||||
std::wstring temp (L"*.");
|
||||
const wchar_t* filters[] = { filter ? (temp + *filter).c_str () : NULL };
|
||||
|
||||
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 (title ? title->c_str () : 0, defaultPath ? defaultPath->c_str () : 0, filter ? 1 : 0, filter ? filters : NULL, NULL);
|
||||
|
||||
if (path) {
|
||||
|
||||
@@ -191,23 +202,24 @@ namespace lime {
|
||||
|
||||
#else
|
||||
|
||||
char* _filter = 0;
|
||||
char* _defaultPath = 0;
|
||||
wstringToChar (filter, _filter);
|
||||
wstringToChar (defaultPath, _defaultPath);
|
||||
std::string* _title = wstring_to_string (title);
|
||||
std::string* _filter = wstring_to_string (filter);
|
||||
std::string* _defaultPath = wstring_to_string (defaultPath);
|
||||
|
||||
const char* filters[] = { NULL };
|
||||
|
||||
if (_filter) {
|
||||
|
||||
std::string temp = std::string ("*.") + std::string (_filter);
|
||||
filters[0] = temp.c_str ();
|
||||
_filter->insert (0, "*.");
|
||||
filters[0] = _filter->c_str ();
|
||||
|
||||
}
|
||||
|
||||
const char* path = tinyfd_saveFileDialog ("", _defaultPath, filter ? 1 : 0, filter ? filters : NULL, NULL);
|
||||
const char* path = tinyfd_saveFileDialog (_title ? _title->c_str () : NULL, _defaultPath ? _defaultPath->c_str () : NULL, _filter ? 1 : 0, _filter ? filters : NULL, NULL);
|
||||
|
||||
if (_defaultPath) free (_defaultPath);
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
if (path) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user