Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions project/include/ui/FileDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace lime {

public:

static void OpenDirectory (Window* window, std::function<void(const char* const*, int, int)> callback, const char* defaultPath = nullptr, bool allowMultiple = false);
static void OpenFile (Window* window, std::function<void(const char* const*, int, int)> callback, const char** names = nullptr, const char** patterns = nullptr, int filterCount = 0, const char* defaultPath = nullptr, bool allowMultiple = false);
static void SaveFile (Window* window, std::function<void(const char* const*, int, int)> callback, const char** names = nullptr, const char** patterns = nullptr, int filterCount = 0, const char* defaultPath = nullptr);
static void OpenDirectory (Window* window = nullptr, const char* title = nullptr, std::function<void(const char* const*, int, int)> callback = nullptr, const char* defaultPath = nullptr, bool allowMultiple = false);
static void OpenFile (Window* window = nullptr, const char* title = nullptr, std::function<void(const char* const*, int, int)> callback = nullptr, const char** names = nullptr, const char** patterns = nullptr, int filterCount = 0, const char* defaultPath = nullptr, bool allowMultiple = false);
static void SaveFile (Window* window = nullptr, const char* title = nullptr, std::function<void(const char* const*, int, int)> callback = nullptr, const char** names = nullptr, const char** patterns = nullptr, int filterCount = 0, const char* defaultPath = nullptr);

};

Expand Down
66 changes: 36 additions & 30 deletions project/src/ExternalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,14 +782,15 @@ namespace lime {
}


void lime_file_dialog_open_directory (value window, value callback, HxString defaultPath, bool allowMultiple) {
void lime_file_dialog_open_directory (value window, HxString title, value callback, HxString defaultPath, bool allowMultiple) {

#ifdef LIME_SDL
Window* targetWindow = window ? (Window*)val_data (window) : nullptr;

const char* targetTitle = hxs_utf8 (title, nullptr);
ValuePointer* targetCallback = new ValuePointer (callback);
const char* targetDefaultPath = hxs_utf8 (defaultPath, nullptr);

FileDialog::OpenDirectory (targetWindow, [targetCallback](const char* const* filelist, int filecount, int filter)
FileDialog::OpenDirectory (targetWindow, targetTitle, [targetCallback](const char* const* filelist, int filecount, int filter)
{
if (targetCallback) {

Expand All @@ -805,20 +806,21 @@ namespace lime {

delete targetCallback;
}
}, hxs_utf8 (defaultPath, nullptr), allowMultiple);
}, targetDefaultPath, allowMultiple);
#endif

}


HL_PRIM void HL_NAME(hl_file_dialog_open_directory) (HL_CFFIPointer* window, vclosure* callback, hl_vstring* defaultPath, bool allowMultiple) {
HL_PRIM void HL_NAME(hl_file_dialog_open_directory) (HL_CFFIPointer* window, hl_vstring* title, vclosure* callback, hl_vstring* defaultPath, bool allowMultiple) {

#ifdef LIME_SDL
Window* targetWindow = window ? (Window*)window->ptr : nullptr;

const char* targetTitle = title ? (char*)hl_to_utf8 ((const uchar*)title->bytes) : nullptr;
ValuePointer* targetCallback = new ValuePointer (callback);
const char* targetDefaultPath = defaultPath ? (char*)hl_to_utf8 ((const uchar*)defaultPath->bytes) : nullptr;

FileDialog::OpenDirectory (targetWindow, [targetCallback](const char* const* filelist, int filecount, int filter)
FileDialog::OpenDirectory (targetWindow, targetTitle, [targetCallback](const char* const* filelist, int filecount, int filter)
{
if (targetCallback) {

Expand All @@ -836,18 +838,19 @@ namespace lime {
delete targetCallback;

}
}, (char*)hl_to_utf8 ((const uchar*)defaultPath->bytes), allowMultiple);
}, targetDefaultPath, allowMultiple);
#endif

}


void lime_file_dialog_open_file (value window, value callback, value names, value patterns, int filterCount, HxString defaultPath, bool allowMultiple) {
void lime_file_dialog_open_file (value window, HxString title, value callback, value names, value patterns, int filterCount, HxString defaultPath, bool allowMultiple) {

#ifdef LIME_SDL
Window* targetWindow = window ? (Window*)val_data (window) : nullptr;

const char* targetTitle = hxs_utf8 (title, nullptr);
ValuePointer* targetCallback = new ValuePointer (callback);
const char* targetDefaultPath = hxs_utf8 (defaultPath, nullptr);

int targetCount = 0;

Expand All @@ -870,7 +873,7 @@ namespace lime {

}

FileDialog::OpenFile (targetWindow, [targetCallback](const char* const* filelist, int filecount, int filter)
FileDialog::OpenFile (targetWindow, targetTitle, [targetCallback](const char* const* filelist, int filecount, int filter)
{
if (targetCallback) {

Expand All @@ -887,18 +890,19 @@ namespace lime {
delete targetCallback;

}
}, targetNames.data(), targetPatterns.data(), targetCount, hxs_utf8 (defaultPath, nullptr), allowMultiple);
}, targetNames.data(), targetPatterns.data(), targetCount, targetDefaultPath, allowMultiple);
#endif

}


HL_PRIM void HL_NAME(hl_file_dialog_open_file) (HL_CFFIPointer* window, vclosure* callback, hl_varray* names, hl_varray* patterns, int filterCount, hl_vstring* defaultPath, bool allowMultiple) {
HL_PRIM void HL_NAME(hl_file_dialog_open_file) (HL_CFFIPointer* window, hl_vstring* title, vclosure* callback, hl_varray* names, hl_varray* patterns, int filterCount, hl_vstring* defaultPath, bool allowMultiple) {

#ifdef LIME_SDL
Window* targetWindow = window ? (Window*)window->ptr : nullptr;

const char* targetTitle = title ? (char*)hl_to_utf8 ((const uchar*)title->bytes) : nullptr;
ValuePointer* targetCallback = new ValuePointer (callback);
const char* targetDefaultPath = defaultPath ? (char*)hl_to_utf8 ((const uchar*)defaultPath->bytes) : nullptr;

int targetCount = 0;

Expand All @@ -924,7 +928,7 @@ namespace lime {

}

FileDialog::OpenFile (targetWindow, [targetCallback](const char* const* filelist, int filecount, int filter)
FileDialog::OpenFile (targetWindow, targetTitle, [targetCallback](const char* const* filelist, int filecount, int filter)
{
if (targetCallback) {

Expand All @@ -945,18 +949,19 @@ namespace lime {
delete targetCallback;

}
}, targetNames.data(), targetPatterns.data(), targetCount, (char*)hl_to_utf8 ((const uchar*)defaultPath->bytes));
}, targetNames.data(), targetPatterns.data(), targetCount, targetDefaultPath);
#endif

}


void lime_file_dialog_save_file (value window, value callback, value names, value patterns, int filterCount, HxString defaultPath) {
void lime_file_dialog_save_file (value window, HxString title, value callback, value names, value patterns, int filterCount, HxString defaultPath) {

#ifdef LIME_SDL
Window* targetWindow = window ? (Window*)val_data (window) : nullptr;

const char* targetTitle = hxs_utf8 (title, nullptr);
ValuePointer* targetCallback = new ValuePointer (callback);
const char* targetDefaultPath = hxs_utf8 (defaultPath, nullptr);

int targetCount = 0;

Expand All @@ -979,7 +984,7 @@ namespace lime {

}

FileDialog::SaveFile (targetWindow, [targetCallback](const char* const* filelist, int filecount, int filter)
FileDialog::SaveFile (targetWindow, targetTitle, [targetCallback](const char* const* filelist, int filecount, int filter)
{
if (targetCallback) {

Expand All @@ -988,18 +993,19 @@ namespace lime {
delete targetCallback;

}
}, targetNames.data(), targetPatterns.data(), targetCount, hxs_utf8 (defaultPath, nullptr));
}, targetNames.data(), targetPatterns.data(), targetCount, targetDefaultPath);
#endif

}


HL_PRIM void HL_NAME(hl_file_dialog_save_file) (HL_CFFIPointer* window, vclosure* callback, hl_varray* names, hl_varray* patterns, int filterCount, hl_vstring* defaultPath) {
HL_PRIM void HL_NAME(hl_file_dialog_save_file) (HL_CFFIPointer* window, hl_vstring* title, vclosure* callback, hl_varray* names, hl_varray* patterns, int filterCount, hl_vstring* defaultPath) {

#ifdef LIME_SDL
Window* targetWindow = window ? (Window*)window->ptr : nullptr;

const char* targetTitle = title ? (char*)hl_to_utf8 ((const uchar*)title->bytes) : nullptr;
ValuePointer* targetCallback = new ValuePointer (callback);
const char* targetDefaultPath = defaultPath ? (char*)hl_to_utf8 ((const uchar*)defaultPath->bytes) : nullptr;

int targetCount = 0;

Expand All @@ -1025,7 +1031,7 @@ namespace lime {

}

FileDialog::SaveFile (targetWindow, [targetCallback](const char* const* filelist, int filecount, int filter)
FileDialog::SaveFile (targetWindow, targetTitle, [targetCallback](const char* const* filelist, int filecount, int filter)
{
if (targetCallback) {

Expand All @@ -1040,7 +1046,7 @@ namespace lime {
delete targetCallback;

}
}, targetNames.data(), targetPatterns.data(), targetCount, (char*)hl_to_utf8 ((const uchar*)defaultPath->bytes));
}, targetNames.data(), targetPatterns.data(), targetCount, targetDefaultPath);
#endif

}
Expand Down Expand Up @@ -4091,9 +4097,9 @@ namespace lime {
DEFINE_PRIME2 (lime_deflate_compress);
DEFINE_PRIME2 (lime_deflate_decompress);
DEFINE_PRIME2v (lime_drop_event_manager_register);
DEFINE_PRIME4v (lime_file_dialog_open_directory);
DEFINE_PRIME7v (lime_file_dialog_open_file);
DEFINE_PRIME6v (lime_file_dialog_save_file);
DEFINE_PRIME5v (lime_file_dialog_open_directory);
DEFINE_PRIME8v (lime_file_dialog_open_file);
DEFINE_PRIME7v (lime_file_dialog_save_file);
DEFINE_PRIME1 (lime_file_watcher_create);
DEFINE_PRIME3 (lime_file_watcher_add_directory);
DEFINE_PRIME2v (lime_file_watcher_remove_directory);
Expand Down Expand Up @@ -4285,9 +4291,9 @@ namespace lime {
DEFINE_HL_PRIM (_TBYTES, hl_deflate_compress, _TBYTES _TBYTES);
DEFINE_HL_PRIM (_TBYTES, hl_deflate_decompress, _TBYTES _TBYTES);
DEFINE_HL_PRIM (_VOID, hl_drop_event_manager_register, _FUN(_VOID, _NO_ARG) _TDROP_EVENT);
DEFINE_HL_PRIM (_VOID, hl_file_dialog_open_directory, _TCFFIPOINTER _FUN(_VOID, _ARR) _STRING _BOOL);
DEFINE_HL_PRIM (_VOID, hl_file_dialog_open_file, _TCFFIPOINTER _FUN(_VOID, _ARR _I32) _ARR _ARR _I32 _STRING _BOOL);
DEFINE_HL_PRIM (_VOID, hl_file_dialog_save_file, _TCFFIPOINTER _FUN(_VOID, _BYTES _I32) _ARR _ARR _I32 _STRING);
DEFINE_HL_PRIM (_VOID, hl_file_dialog_open_directory, _TCFFIPOINTER _STRING _FUN(_VOID, _ARR) _STRING _BOOL);
DEFINE_HL_PRIM (_VOID, hl_file_dialog_open_file, _TCFFIPOINTER _STRING _FUN(_VOID, _ARR _I32) _ARR _ARR _I32 _STRING _BOOL);
DEFINE_HL_PRIM (_VOID, hl_file_dialog_save_file, _TCFFIPOINTER _STRING _FUN(_VOID, _BYTES _I32) _ARR _ARR _I32 _STRING);
DEFINE_HL_PRIM (_TCFFIPOINTER, hl_file_watcher_create, _DYN);
DEFINE_HL_PRIM (_I32, hl_file_watcher_add_directory, _TCFFIPOINTER _STRING _BOOL);
DEFINE_HL_PRIM (_VOID, hl_file_watcher_remove_directory, _TCFFIPOINTER _I32);
Expand Down
63 changes: 56 additions & 7 deletions project/src/ui/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,36 +140,85 @@ namespace lime {
#endif


void FileDialog::OpenDirectory (Window* window, std::function<void(const char* const*, int, int)> callback, const char* defaultPath, bool allowMultiple) {
void FileDialog::OpenDirectory (Window* window, const char* title, std::function<void(const char* const*, int, int)> callback, const char* defaultPath, bool allowMultiple) {

#ifdef LIME_SDL
SDL_PropertiesID props = SDL_CreateProperties ();

SDL_SetPointerProperty (props, SDL_PROP_FILE_DIALOG_WINDOW_POINTER, window ? static_cast<SDLWindow*> (window)->sdlWindow : nullptr);
SDL_SetStringProperty (props, SDL_PROP_FILE_DIALOG_LOCATION_STRING, defaultPath);
SDL_SetBooleanProperty (props, SDL_PROP_FILE_DIALOG_MANY_BOOLEAN, allowMultiple);

if (title) {

SDL_SetStringProperty (props, SDL_PROP_FILE_DIALOG_TITLE_STRING, title);

}

auto* dialogData = new FileDialogData;
dialogData->callback = std::move(callback);
SDL_ShowOpenFolderDialog(dialogFileCallbackThunk, dialogData, window ? static_cast<SDLWindow*>(window)->sdlWindow : nullptr, defaultPath, allowMultiple);
dialogData->callback = std::move (callback);
SDL_ShowFileDialogWithProperties (SDL_FILEDIALOG_OPENFOLDER, dialogFileCallbackThunk, dialogData, props);

SDL_DestroyProperties (props);
#endif

}


void FileDialog::OpenFile (Window* window, std::function<void(const char* const*, int, int)> callback, const char** names, const char** patterns, int filterCount, const char* defaultPath, bool allowMultiple) {
void FileDialog::OpenFile (Window* window, const char* title, std::function<void(const char* const*, int, int)> callback, const char** names, const char** patterns, int filterCount, const char* defaultPath, bool allowMultiple) {

#ifdef LIME_SDL
auto* dialogData = new FileDialogData;
dialogData->callback = std::move(callback);
dialogData->filters = buildFilters(names, patterns, filterCount);
SDL_ShowOpenFileDialog(dialogFileCallbackThunk, dialogData, window ? static_cast<SDLWindow*>(window)->sdlWindow : nullptr, dialogData->filters.data(), static_cast<int>(dialogData->filters.size()), defaultPath, allowMultiple);

SDL_PropertiesID props = SDL_CreateProperties();

SDL_SetPointerProperty(props, SDL_PROP_FILE_DIALOG_FILTERS_POINTER, (void*)dialogData->filters.data());
SDL_SetNumberProperty(props, SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER, static_cast<int>(dialogData->filters.size()));
SDL_SetPointerProperty(props, SDL_PROP_FILE_DIALOG_WINDOW_POINTER, window ? static_cast<SDLWindow*>(window)->sdlWindow : nullptr);
SDL_SetStringProperty(props, SDL_PROP_FILE_DIALOG_LOCATION_STRING, defaultPath);
SDL_SetBooleanProperty(props, SDL_PROP_FILE_DIALOG_MANY_BOOLEAN, allowMultiple);

if (title) {

SDL_SetStringProperty(props, SDL_PROP_FILE_DIALOG_TITLE_STRING, title);

}

SDL_ShowFileDialogWithProperties(SDL_FILEDIALOG_OPENFILE, dialogFileCallbackThunk, dialogData, props);

SDL_DestroyProperties(props);

#endif

}


void FileDialog::SaveFile (Window* window, std::function<void(const char* const*, int, int)> callback, const char** names, const char** patterns, int filterCount, const char* defaultPath) {
void FileDialog::SaveFile (Window* window, const char* title, std::function<void(const char* const*, int, int)> callback, const char** names, const char** patterns, int filterCount, const char* defaultPath) {

#ifdef LIME_SDL
auto* dialogData = new FileDialogData;
dialogData->callback = std::move(callback);
dialogData->filters = buildFilters(names, patterns, filterCount);
SDL_ShowSaveFileDialog(dialogFileCallbackThunk, dialogData, window ? static_cast<SDLWindow*>(window)->sdlWindow : nullptr, dialogData->filters.data(), static_cast<int>(dialogData->filters.size()), defaultPath);

SDL_PropertiesID props = SDL_CreateProperties();

SDL_SetPointerProperty(props, SDL_PROP_FILE_DIALOG_FILTERS_POINTER, (void*)dialogData->filters.data());
SDL_SetNumberProperty(props, SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER, static_cast<int>(dialogData->filters.size()));
SDL_SetPointerProperty(props, SDL_PROP_FILE_DIALOG_WINDOW_POINTER, window ? static_cast<SDLWindow*>(window)->sdlWindow : nullptr);
SDL_SetStringProperty(props, SDL_PROP_FILE_DIALOG_LOCATION_STRING, defaultPath);

if (title) {

SDL_SetStringProperty(props, SDL_PROP_FILE_DIALOG_TITLE_STRING, title);

}

SDL_ShowFileDialogWithProperties(SDL_FILEDIALOG_SAVEFILE, dialogFileCallbackThunk, dialogData, props);

SDL_DestroyProperties(props);

#endif

}
Expand Down
Loading