file dialog extracted

This commit is contained in:
BADIM-PC\Vadim 2018-02-08 14:26:17 +03:00
parent 826ac4d769
commit 2de319ce5a
11 changed files with 36 additions and 49 deletions

View File

@ -257,11 +257,13 @@ SDL_NET = \
bin/SDLnetselect.o \
bin/net.o
FILE_DIALOG = \
bin/file_dialog.o
TIC_O=\
bin/studio.o \
bin/console.o \
bin/run.o \
bin/file_dialog.o \
bin/md5.o \
bin/gif.o \
bin/fs.o \
@ -320,8 +322,8 @@ emscripten:
wasm:
$(EMS_CC) $(SOURCES) $(TIC80_SRC) $(OPT) $(INCLUDES) $(EMS_OPT) -s WASM=1 $(EMS_LINKER_FLAGS) -o build/html/tic.js
mingw: $(STUDIO_DLL) $(SDL_NET) bin/main.o bin/res.o
$(CC) bin/main.o bin/res.o $(STUDIO_A) $(SDL_NET) $(OPT) $(INCLUDES) $(MINGW_LINKER_FLAGS) -o $(MINGW_OUTPUT)
mingw: $(STUDIO_DLL) $(SDL_NET) $(FILE_DIALOG) bin/main.o bin/res.o
$(CC) bin/main.o bin/res.o $(STUDIO_A) $(SDL_NET) $(FILE_DIALOG) $(OPT) $(INCLUDES) $(MINGW_LINKER_FLAGS) -o $(MINGW_OUTPUT)
mingw-pro:
$(eval OPT += $(OPT_PRO))

View File

@ -280,7 +280,6 @@
<ClCompile Include="..\..\..\src\config.c" />
<ClCompile Include="..\..\..\src\console.c" />
<ClCompile Include="..\..\..\src\dialog.c" />
<ClCompile Include="..\..\..\src\ext\file_dialog.c" />
<ClCompile Include="..\..\..\src\ext\gif.c" />
<ClCompile Include="..\..\..\src\ext\md5.c" />
<ClCompile Include="..\..\..\src\fs.c" />

View File

@ -63,9 +63,6 @@
<ClCompile Include="..\..\..\src\world.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\file_dialog.c">
<Filter>src\ext</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\md5.c">
<Filter>src\ext</Filter>
</ClCompile>

View File

@ -52,6 +52,7 @@
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnet.c" />
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetselect.c" />
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetTCP.c" />
<ClCompile Include="..\..\..\src\ext\file_dialog.c" />
<ClCompile Include="..\..\..\src\main.c" />
<ClCompile Include="..\..\..\src\net.c" />
</ItemGroup>

View File

@ -30,6 +30,9 @@
<ClCompile Include="..\..\..\src\net.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\file_dialog.c">
<Filter>src\ext</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="icon.ico">

View File

@ -24,7 +24,7 @@
#include <SDL.h>
#if defined(__TIC_WINDOWS__)
#if defined(__WINDOWS__)
#include <windows.h>
#include <commdlg.h>
@ -104,7 +104,7 @@ void file_dialog_save(file_dialog_save_callback callback, const char* name, cons
fwrite(buffer, 1, size, file);
fclose(file);
#if !defined(__TIC_WINDOWS__)
#if !defined(__WINDOWS__)
chmod(filename, mode);
#endif
callback(true, data);
@ -115,40 +115,6 @@ void file_dialog_save(file_dialog_save_callback callback, const char* name, cons
callback(false, data);
}
#include <shlobj.h>
const char* folder_dialog(void* data)
{
BROWSEINFOW bi = { 0 };
bi.lpszTitle = L"Browse for folder...";
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
bi.lParam = (LPARAM) NULL;
LPITEMIDLIST pidl = SHBrowseForFolderW ( &bi );
if ( pidl != 0 )
{
wchar_t path[MAX_PATH];
SHGetPathFromIDListW (pidl, path);
LPMALLOC imalloc = NULL;
if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
{
imalloc->lpVtbl->Free (imalloc, pidl );
imalloc->lpVtbl->Release (imalloc);
}
{
static char result[MAX_PATH];
strcpy(result, StringToUTF8(path));
return result;
}
}
return NULL;
}
#elif defined(__EMSCRIPTEN__)
#include <emscripten.h>

View File

@ -34,7 +34,6 @@ typedef void(*file_dialog_save_callback)(bool result, void* data);
void file_dialog_load(file_dialog_load_callback callback, void* data);
void file_dialog_save(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode);
const char* folder_dialog(void* data);
#ifdef __cplusplus
}

View File

@ -300,7 +300,7 @@ void fsAddFile(FileSystem* fs, AddCallback callback, void* data)
*addFileData = (AddFileData) { fs, callback, data };
file_dialog_load(&onAddFile, addFileData);
_file_dialog_load(&onAddFile, addFileData);
}
typedef struct
@ -432,7 +432,7 @@ void fsGetFileData(GetCallback callback, const char* name, void* buffer, size_t
GetFileData* command = (GetFileData*)malloc(sizeof(GetFileData));
*command = (GetFileData) {callback, data, buffer};
file_dialog_save(onGetFile, name, buffer, size, command, mode);
_file_dialog_save(onGetFile, name, buffer, size, command, mode);
}
typedef struct
@ -456,7 +456,7 @@ void fsOpenFileData(OpenCallback callback, void* data)
*command = (OpenFileData){callback, data};
file_dialog_load(onOpenFileData, command);
_file_dialog_load(onOpenFileData, command);
}
void fsGetFile(FileSystem* fs, GetCallback callback, const char* name, void* data)
@ -470,7 +470,7 @@ void fsGetFile(FileSystem* fs, GetCallback callback, const char* name, void* dat
*command = (GetFileData) {callback, data, buffer};
s32 mode = fsGetMode(fs, name);
file_dialog_save(onGetFile, name, buffer, size, command, mode);
_file_dialog_save(onGetFile, name, buffer, size, command, mode);
}
else callback(FS_FILE_NOT_DOWNLOADED, data);
}

View File

@ -904,6 +904,9 @@ static System sysHandlers =
.netGetRequest = netGetRequest,
.createNet = createNet,
.closeNet = closeNet,
.file_dialog_load = file_dialog_load,
.file_dialog_save = file_dialog_save,
};
s32 main(s32 argc, char **argv)

View File

@ -3129,3 +3129,13 @@ void _closeNet(Net* net)
{
return studioImpl.system->closeNet(net);
}
void _file_dialog_load(file_dialog_load_callback callback, void* data)
{
studioImpl.system->file_dialog_load(callback, data);
}
void _file_dialog_save(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode)
{
studioImpl.system->file_dialog_save(callback, name, buffer, size, data, mode);
}

View File

@ -38,6 +38,7 @@
#include "defines.h"
#include "tools.h"
#include "net.h"
#include "ext/file_dialog.h"
#define TIC_LOCAL ".local/"
#define TIC_CACHE TIC_LOCAL "cache/"
@ -232,6 +233,9 @@ typedef struct
Net* (*createNet)();
void (*closeNet)(Net* net);
void (*file_dialog_load)(file_dialog_load_callback callback, void* data);
void (*file_dialog_save)(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode);
} System;
TIC80_API Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* appFolder, System* system);
@ -254,3 +258,6 @@ void _netDirRequest(Net* net, const char* path, ListCallback callback, void* dat
void* _netGetRequest(Net* net, const char* path, s32* size);
Net* _createNet();
void _closeNet(Net* net);
void _file_dialog_load(file_dialog_load_callback callback, void* data);
void _file_dialog_save(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode);