|
@@ -20,6 +20,7 @@
|
|
|
#include <entry/entry.h>
|
|
#include <entry/entry.h>
|
|
|
#include <entry/input.h>
|
|
#include <entry/input.h>
|
|
|
#include <entry/cmd.h>
|
|
#include <entry/cmd.h>
|
|
|
|
|
+#include <entry/dialog.h>
|
|
|
#include <imgui/imgui.h>
|
|
#include <imgui/imgui.h>
|
|
|
#include <bgfx_utils.h>
|
|
#include <bgfx_utils.h>
|
|
|
|
|
|
|
@@ -239,209 +240,13 @@ static const char* s_filter = ""
|
|
|
"Truevision TGA (tga) | *.tga\n"
|
|
"Truevision TGA (tga) | *.tga\n"
|
|
|
;
|
|
;
|
|
|
|
|
|
|
|
-struct FileSelectionDialogType
|
|
|
|
|
-{
|
|
|
|
|
- enum Enum
|
|
|
|
|
- {
|
|
|
|
|
- Open,
|
|
|
|
|
- Save,
|
|
|
|
|
-
|
|
|
|
|
- Count
|
|
|
|
|
- };
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
#if BX_PLATFORM_WINDOWS
|
|
#if BX_PLATFORM_WINDOWS
|
|
|
|
|
+
|
|
|
extern "C" void* __stdcall GetModuleHandleA(const char* _moduleName);
|
|
extern "C" void* __stdcall GetModuleHandleA(const char* _moduleName);
|
|
|
extern "C" uint32_t __stdcall GetModuleFileNameA(void* _module, char* _outFilePath, uint32_t _size);
|
|
extern "C" uint32_t __stdcall GetModuleFileNameA(void* _module, char* _outFilePath, uint32_t _size);
|
|
|
|
|
|
|
|
-typedef uintptr_t (__stdcall *LPOFNHOOKPROC)(void*, uint32_t, uintptr_t, uint64_t);
|
|
|
|
|
-
|
|
|
|
|
-struct OPENFILENAMEA
|
|
|
|
|
-{
|
|
|
|
|
- uint32_t structSize;
|
|
|
|
|
- void* hwndOwner;
|
|
|
|
|
- void* hinstance;
|
|
|
|
|
- const char* filter;
|
|
|
|
|
- const char* customFilter;
|
|
|
|
|
- uint32_t maxCustomFilter;
|
|
|
|
|
- uint32_t filterIndex;
|
|
|
|
|
- const char* file;
|
|
|
|
|
- uint32_t maxFile;
|
|
|
|
|
- const char* fileTitle;
|
|
|
|
|
- uint32_t maxFileTitle;
|
|
|
|
|
- const char* initialDir;
|
|
|
|
|
- const char* title;
|
|
|
|
|
- uint32_t flags;
|
|
|
|
|
- uint16_t fileOffset;
|
|
|
|
|
- uint16_t fileExtension;
|
|
|
|
|
- const char* defExt;
|
|
|
|
|
- uint64_t customData;
|
|
|
|
|
- LPOFNHOOKPROC hook;
|
|
|
|
|
- const char* templateName;
|
|
|
|
|
- void* reserved0;
|
|
|
|
|
- uint32_t reserved1;
|
|
|
|
|
- uint32_t flagsEx;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-extern "C" bool __stdcall GetOpenFileNameA(OPENFILENAMEA* _ofn);
|
|
|
|
|
-
|
|
|
|
|
#endif // BX_PLATFORM_WINDOWS
|
|
#endif // BX_PLATFORM_WINDOWS
|
|
|
|
|
|
|
|
-class Split
|
|
|
|
|
-{
|
|
|
|
|
-public:
|
|
|
|
|
- Split(const bx::StringView& _str, char _ch)
|
|
|
|
|
- : m_str(_str)
|
|
|
|
|
- , m_token(_str.getPtr(), bx::strFind(_str, _ch).getPtr() )
|
|
|
|
|
- , m_ch(_ch)
|
|
|
|
|
- {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- bx::StringView next()
|
|
|
|
|
- {
|
|
|
|
|
- bx::StringView result = m_token;
|
|
|
|
|
- m_token = bx::strTrim(
|
|
|
|
|
- bx::StringView(m_token.getTerm()+1
|
|
|
|
|
- , bx::strFind(bx::StringView(m_token.getTerm()+1, m_str.getTerm() ), m_ch).getPtr() )
|
|
|
|
|
- , " \t\n"
|
|
|
|
|
- );
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- bool isDone() const
|
|
|
|
|
- {
|
|
|
|
|
- return m_token.isEmpty();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-private:
|
|
|
|
|
- const bx::StringView& m_str;
|
|
|
|
|
- bx::StringView m_token;
|
|
|
|
|
- char m_ch;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-bool openFileSelectionDialog(
|
|
|
|
|
- bx::FilePath& _inOutFilePath
|
|
|
|
|
- , FileSelectionDialogType::Enum _type
|
|
|
|
|
- , const bx::StringView& _title
|
|
|
|
|
- , const bx::StringView& _filter = "All Files | *"
|
|
|
|
|
- )
|
|
|
|
|
-{
|
|
|
|
|
-#if BX_PLATFORM_LINUX || BX_PLATFORM_OSX
|
|
|
|
|
- char tmp[4096];
|
|
|
|
|
- bx::StaticMemoryBlockWriter writer(tmp, sizeof(tmp) );
|
|
|
|
|
-
|
|
|
|
|
- bx::Error err;
|
|
|
|
|
- bx::write(&writer, &err
|
|
|
|
|
- , "--file-selection%s --title \"%.*s\" --filename \"%s\""
|
|
|
|
|
- , FileSelectionDialogType::Save == _type ? " --save" : ""
|
|
|
|
|
- , _title.getLength(), _title.getPtr()
|
|
|
|
|
- , _inOutFilePath.getCPtr()
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- for (bx::LineReader lr(_filter); !lr.isDone();)
|
|
|
|
|
- {
|
|
|
|
|
- const bx::StringView line = lr.next();
|
|
|
|
|
-
|
|
|
|
|
- bx::write(&writer, &err
|
|
|
|
|
- , " --file-filter \"%.*s\""
|
|
|
|
|
- , line.getLength(), line.getPtr()
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (err.isOk() )
|
|
|
|
|
- {
|
|
|
|
|
- bx::ProcessReader pr;
|
|
|
|
|
-
|
|
|
|
|
- if (bx::open(&pr, "zenity", tmp, &err) )
|
|
|
|
|
- {
|
|
|
|
|
- char buffer[1024];
|
|
|
|
|
- int32_t total = bx::read(&pr, buffer, sizeof(buffer), &err);
|
|
|
|
|
- bx::close(&pr);
|
|
|
|
|
-
|
|
|
|
|
- if (0 == pr.getExitCode() )
|
|
|
|
|
- {
|
|
|
|
|
- _inOutFilePath.set(bx::strRTrim(bx::StringView(buffer, total), "\n\r") );
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-#elif BX_PLATFORM_WINDOWS
|
|
|
|
|
- BX_UNUSED(_type);
|
|
|
|
|
-
|
|
|
|
|
- char out[bx::kMaxFilePath] = { '\0' };
|
|
|
|
|
-
|
|
|
|
|
- OPENFILENAMEA ofn;
|
|
|
|
|
- bx::memSet(&ofn, 0, sizeof(ofn) );
|
|
|
|
|
- ofn.structSize = sizeof(OPENFILENAMEA);
|
|
|
|
|
- ofn.initialDir = _inOutFilePath.getCPtr();
|
|
|
|
|
- ofn.file = out;
|
|
|
|
|
- ofn.maxFile = sizeof(out);
|
|
|
|
|
- ofn.flags = 0
|
|
|
|
|
- | /* OFN_EXPLORER */ 0x00080000
|
|
|
|
|
- | /* OFN_FILEMUSTEXIST */ 0x00001000
|
|
|
|
|
- | /* OFN_DONTADDTORECENT */ 0x02000000
|
|
|
|
|
- ;
|
|
|
|
|
-
|
|
|
|
|
- char tmp[4096];
|
|
|
|
|
- bx::StaticMemoryBlockWriter writer(tmp, sizeof(tmp) );
|
|
|
|
|
-
|
|
|
|
|
- bx::Error err;
|
|
|
|
|
-
|
|
|
|
|
- ofn.title = tmp;
|
|
|
|
|
- bx::write(&writer, &err, "%.*s", _title.getLength(), _title.getPtr() );
|
|
|
|
|
- bx::write(&writer, '\0', &err);
|
|
|
|
|
-
|
|
|
|
|
- ofn.filter = tmp + uint32_t(bx::seek(&writer) );
|
|
|
|
|
-
|
|
|
|
|
- for (bx::LineReader lr(_filter); !lr.isDone() && err.isOk();)
|
|
|
|
|
- {
|
|
|
|
|
- const bx::StringView line = lr.next();
|
|
|
|
|
- const bx::StringView sep = bx::strFind(line, '|');
|
|
|
|
|
-
|
|
|
|
|
- if (!sep.isEmpty() )
|
|
|
|
|
- {
|
|
|
|
|
- bx::write(&writer, bx::strTrim(bx::StringView(line.getPtr(), sep.getPtr() ), " "), &err);
|
|
|
|
|
- bx::write(&writer, '\0', &err);
|
|
|
|
|
-
|
|
|
|
|
- bool first = true;
|
|
|
|
|
-
|
|
|
|
|
- for (Split split(bx::strTrim(bx::StringView(sep.getPtr()+1, line.getTerm() ), " "), ' '); !split.isDone() && err.isOk();)
|
|
|
|
|
- {
|
|
|
|
|
- const bx::StringView token = split.next();
|
|
|
|
|
- if (!first)
|
|
|
|
|
- {
|
|
|
|
|
- bx::write(&writer, ';', &err);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- first = false;
|
|
|
|
|
- bx::write(&writer, token, &err);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- bx::write(&writer, '\0', &err);
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- bx::write(&writer, line, &err);
|
|
|
|
|
- bx::write(&writer, '\0', &err);
|
|
|
|
|
- bx::write(&writer, '\0', &err);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- bx::write(&writer, '\0', &err);
|
|
|
|
|
-
|
|
|
|
|
- if (err.isOk()
|
|
|
|
|
- && GetOpenFileNameA(&ofn) )
|
|
|
|
|
- {
|
|
|
|
|
- _inOutFilePath.set(ofn.file);
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
-#else
|
|
|
|
|
- BX_UNUSED(_inOutFilePath, _type, _title, _filter);
|
|
|
|
|
-#endif // BX_PLATFORM_LINUX || BX_PLATFORM_OSX
|
|
|
|
|
-
|
|
|
|
|
- return false;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
struct View
|
|
struct View
|
|
|
{
|
|
{
|
|
|
View()
|
|
View()
|