From 0df5c410d14e8785ad81e48e28eecc5cd624ff13 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 5 Mar 2015 19:48:47 +0000 Subject: [PATCH] Fix bug when pressing cancel on save dialog --- src/dialogs/FileDialog.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/dialogs/FileDialog.cpp b/src/dialogs/FileDialog.cpp index c0fbdc0..518db69 100644 --- a/src/dialogs/FileDialog.cpp +++ b/src/dialogs/FileDialog.cpp @@ -149,12 +149,18 @@ void FileDialog_save_project(EditorState *state) state->isInstalled); const char* filters[] = {"*.nbe"}; - std::string file = tinyfd_saveFileDialog("Save Project", path.c_str(), + const char *cfile = tinyfd_saveFileDialog("Save Project", path.c_str(), 1, filters); - std::cerr << file << std::endl; + + if (!cfile) + return; + + std::string file = cfile; if (file == "") return; + + std::cerr << file << std::endl; FileFormat *writer = getFromType(FILE_FORMAT_NBE, state); save_file(writer, state, file); @@ -173,13 +179,19 @@ void FileDialog_export(EditorState *state, int parser) else if (parser == (int)FILE_FORMAT_CPP) filters[0] = "*.cpp"; - std::string file = tinyfd_saveFileDialog("Save Project", path.c_str(), + const char *cfile = tinyfd_saveFileDialog("Save Project", path.c_str(), 1, filters); - std::cerr << file << std::endl; + + if (!cfile) + return; + + std::string file = cfile; if (file == "") return; + std::cerr << file << std::endl; + FileFormat *writer = getFromType((FileFormatType)parser, state); save_file(writer, state, file); } @@ -195,8 +207,14 @@ void FileDialog_export_obj(EditorState *state, Node *node) const char* filters[] = {"*.obj"}; - std::string filename = tinyfd_saveFileDialog("Export Node to Mesh", path.c_str(), - 1, filters); + const char *cfile = tinyfd_saveFileDialog("Export Node to Mesh", path.c_str(), + 1, filters); + + if (!cfile) + return; + + std::string filename = cfile; + if (filename == "") return;