Change get_readable/writable_extensions() API from char* to std::string

This commit is contained in:
David Capello 2015-03-17 17:17:01 -03:00
parent 79c30a9ef3
commit 5ef4cb1460
9 changed files with 35 additions and 44 deletions

View File

@ -265,8 +265,7 @@ protected:
}
void onImageFilename() {
char exts[4096];
get_writable_extensions(exts, sizeof(exts));
std::string exts = get_writable_extensions();
std::string newFilename = app::show_file_selector(
"Save Sprite Sheet", m_filename, exts, FileSelectorType::Save);

View File

@ -41,9 +41,7 @@ LoadPaletteCommand::LoadPaletteCommand()
void LoadPaletteCommand::onExecute(Context* context)
{
char exts[4096];
get_readable_palette_extensions(exts, sizeof(exts));
std::string exts = get_readable_palette_extensions();
std::string filename =
app::show_file_selector("Load Palette", "", exts,
FileSelectorType::Open);

View File

@ -109,8 +109,7 @@ void OpenFileCommand::onExecute(Context* context)
// interactive
if (context->isUiAvailable() && m_filename.empty()) {
char exts[4096];
get_readable_extensions(exts, sizeof(exts));
std::string exts = get_readable_extensions();
// Add backslash as show_file_selector() expected a filename as
// initial path (and the file part is removed from the path).

View File

@ -135,8 +135,7 @@ void SaveFileBaseCommand::saveAsDialog(const ContextReader& reader, const char*
else {
filename = document->filename();
char exts[4096];
get_writable_extensions(exts, sizeof(exts));
std::string exts = get_writable_extensions();
for (;;) {
std::string newfilename = app::show_file_selector(

View File

@ -40,9 +40,7 @@ SavePaletteCommand::SavePaletteCommand()
void SavePaletteCommand::onExecute(Context* context)
{
char exts[4096];
get_writable_palette_extensions(exts, sizeof(exts));
std::string exts = get_writable_palette_extensions();
std::string filename;
int ret;

View File

@ -43,38 +43,34 @@ using namespace base;
static FileOp* fop_new(FileOpType type, Context* context);
static void fop_prepare_for_sequence(FileOp* fop);
void get_readable_extensions(char* buf, int size)
std::string get_readable_extensions()
{
FileFormatsList::iterator it = FileFormatsManager::instance()->begin();
FileFormatsList::iterator end = FileFormatsManager::instance()->end();
std::string buf;
// Clear the string
strncpy(buf, "", size);
// Insert file format
for (; it != end; ++it) {
if ((*it)->support(FILE_SUPPORT_LOAD)) {
if (*buf) strncat(buf, ",", size);
strncat(buf, (*it)->extensions(), size);
for (const FileFormat* format : *FileFormatsManager::instance()) {
if (format->support(FILE_SUPPORT_LOAD)) {
if (!buf.empty())
buf.push_back(',');
buf += format->extensions();
}
}
return buf;
}
void get_writable_extensions(char* buf, int size)
std::string get_writable_extensions()
{
FileFormatsList::iterator it = FileFormatsManager::instance()->begin();
FileFormatsList::iterator end = FileFormatsManager::instance()->end();
std::string buf;
// Clear the string
strncpy(buf, "", size);
// Insert file format
for (; it != end; ++it) {
if ((*it)->support(FILE_SUPPORT_SAVE)) {
if (*buf) strncat(buf, ",", size);
strncat(buf, (*it)->extensions(), size);
for (const FileFormat* format : *FileFormatsManager::instance()) {
if (format->support(FILE_SUPPORT_SAVE)) {
if (!buf.empty())
buf.push_back(',');
buf += format->extensions();
}
}
return buf;
}
Document* load_document(Context* context, const char* filename)

View File

@ -112,8 +112,8 @@ namespace app {
// Available extensions for each load/save operation.
void get_readable_extensions(char* buf, int size);
void get_writable_extensions(char* buf, int size);
std::string get_readable_extensions();
std::string get_writable_extensions();
// High-level routines to load/save documents.

View File

@ -30,16 +30,18 @@ namespace app {
using namespace doc;
void get_readable_palette_extensions(char* buf, int size)
std::string get_readable_palette_extensions()
{
get_readable_extensions(buf, size);
std::strcat(buf, ",col,gpl");
std::string buf = get_readable_extensions();
buf += ",col,gpl";
return buf;
}
void get_writable_palette_extensions(char* buf, int size)
std::string get_writable_palette_extensions()
{
get_writable_extensions(buf, size);
std::strcat(buf, ",col,gpl");
std::string buf = get_writable_extensions();
buf += ",col,gpl";
return buf;
}
Palette* load_palette(const char *filename)

View File

@ -15,8 +15,8 @@ namespace doc {
namespace app {
void get_readable_palette_extensions(char* buf, int size);
void get_writable_palette_extensions(char* buf, int size);
std::string get_readable_palette_extensions();
std::string get_writable_palette_extensions();
doc::Palette* load_palette(const char *filename);
bool save_palette(const char *filename, doc::Palette* pal);