Improve tiny file dialog integration code

master
stujones11 2018-09-11 18:45:25 +01:00
parent 730f15058f
commit c3c18147c9
3 changed files with 31 additions and 31 deletions

View File

@ -20,7 +20,7 @@ namespace dialog
{
SEvent event;
bool has_event = false;
const char *filename = "";
const char *filename = nullptr;
void showFileOpen(IGUIEnvironment *env, s32 id, const char *caption,
const char **filters, const int filter_count)
@ -52,14 +52,14 @@ namespace dialog
}
else
{
filename = "";
filename = nullptr;
event.GUIEvent.EventType = EGET_FILE_CHOOSE_DIALOG_CANCELLED;
}
window->remove();
has_event = true;
}
catch (const std::exception& except)
catch (const std::exception &except)
{
std::cout << except.what() << std::endl;
}
@ -570,7 +570,7 @@ bool TexturesDialog::OnEvent(const SEvent &event)
}
else if (event.GUIEvent.EventType == EGET_FILE_SELECTED)
{
stringw fn = dialog::filename;
stringw fn = (dialog::filename) ? dialog::filename : "";
if (!fn.empty())
{
s32 id = event.UserEvent.UserData1;

View File

@ -7,32 +7,6 @@ using namespace scene;
using namespace gui;
using namespace video;
namespace dialog
{
static const int model_filter_count = 19;
static const char *model_filters[] = {
"*.obj", "*.b3d", "*.x", "*.3ds",
"*.irr", "*.irrmesh", "*.md2", "*.md3",
"*.bsp", "*.mesh", "*.ms3d", "*.my3D",
"*.lwo", "*.xml", "*.dae", "*.dmf",
"*.oct", "*.csm", "*.stl"
};
static const int texture_filter_count = 8;
static const char *texture_filters[] = {
"*.png", "*.jpg", "*.tga", "*.bmp",
"*.psd", "*.pcx", "*.ppm", "*.wal"
};
extern const char *filename;
extern bool has_event;
extern SEvent event;
void showFileOpen(IGUIEnvironment *env, s32 id, const char *caption,
const char **filters, const int filter_count);
void fileOpen(IGUIEnvironment *env, s32 id, const char *caption,
const char **filters, const int filter_count);
}
enum
{
E_DIALOG_ID_ABOUT = 0x1000,
@ -69,6 +43,32 @@ enum
E_BUTTON_ID_WIELD = 0x2030
};
namespace dialog
{
static const int model_filter_count = 19;
static const char *model_filters[] = {
"*.obj", "*.b3d", "*.x", "*.3ds",
"*.irr", "*.irrmesh", "*.md2", "*.md3",
"*.bsp", "*.mesh", "*.ms3d", "*.my3D",
"*.lwo", "*.xml", "*.dae", "*.dmf",
"*.oct", "*.csm", "*.stl"
};
static const int texture_filter_count = 8;
static const char *texture_filters[] = {
"*.png", "*.jpg", "*.tga", "*.bmp",
"*.psd", "*.pcx", "*.ppm", "*.wal"
};
extern const char *filename;
extern bool has_event;
extern SEvent event;
void showFileOpen(IGUIEnvironment *env, s32 id, const char *caption,
const char **filters, const int filter_count);
void fileOpen(IGUIEnvironment *env, s32 id, const char *caption,
const char **filters, const int filter_count);
}
class Config;
class HyperlinkCtrl : public IGUIElement

View File

@ -294,7 +294,7 @@ bool Viewer::OnEvent(const SEvent &event)
}
else if (event.GUIEvent.EventType == EGET_FILE_SELECTED)
{
stringc fn = dialog::filename;
stringc fn = (dialog::filename) ? dialog::filename : "";
s32 id = event.UserEvent.UserData1;
gui->setFocused(false);
switch (id)