Add default file extension for zenity file dialog result if none is provided, also reduce width of save map input field so that it fits better on vertical phone orientation

This commit is contained in:
UnknownShadow200 2022-11-13 10:23:42 +11:00
parent 69090c8bae
commit 680d739e6b
2 changed files with 19 additions and 12 deletions

View File

@ -1377,7 +1377,7 @@ static void SaveLevelScreen_UploadCallback(const cc_string* path) {
static void SaveLevelScreen_File(void* screen, void* b) {
static const char* const titles[] = {
"ClassiCube map", "MineCraft schematic", "MineCraft classic map", NULL
"ClassiCube map", "Minecraft schematic", "Minecraft classic map", NULL
};
static const char* const filters[] = {
".cw", ".schematic", ".mine", NULL
@ -1476,7 +1476,7 @@ static void SaveLevelScreen_Init(void* screen) {
ButtonWidget_Init(&s->file, 400, SaveLevelScreen_File);
ButtonWidget_Init(&s->cancel, 400, Menu_SwitchPause);
TextInputWidget_Create(&s->input, 500, &World.Name, &desc);
TextInputWidget_Create(&s->input, 400, &World.Name, &desc);
TextWidget_Init(&s->desc);
s->input.onscreenPlaceholder = "Map name";
}

View File

@ -967,7 +967,7 @@ static void ShowDialogCore(const char* title, const char* msg) {
XFlush(m.dpy); /* flush so window disappears immediately */
}
static cc_result OpenSaveFileDialog(const char* args, FileDialogCallback callback) {
static cc_result OpenSaveFileDialog(const char* args, FileDialogCallback callback, const char* defaultExt) {
cc_string path; char pathBuffer[1024];
char result[4096] = { 0 };
int len, i;
@ -977,14 +977,21 @@ static cc_result OpenSaveFileDialog(const char* args, FileDialogCallback callbac
/* result from zenity is normally just one string */
while (fgets(result, sizeof(result), fp)) { }
len = String_Length(result);
pclose(fp);
len = String_Length(result);
if (!len) return 0;
if (len) {
String_InitArray(path, pathBuffer);
String_AppendUtf8(&path, result, len);
callback(&path);
/* Add default file extension if necessary */
if (defaultExt) {
cc_string file = path;
Utils_UNSAFE_GetFilename(&file);
if (String_IndexOf(&file, '.') == -1) String_AppendConst(&path, defaultExt);
}
pclose(fp);
callback(&path);
return 0;
}
@ -1010,7 +1017,7 @@ cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) {
String_AppendConst(&path, "'");
path.buffer[path.length] = '\0';
return OpenSaveFileDialog(path.buffer, args->Callback);
return OpenSaveFileDialog(path.buffer, args->Callback, NULL);
}
cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) {
@ -1028,7 +1035,7 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) {
String_AppendConst(&path, " --save --confirm-overwrite");
path.buffer[path.length] = '\0';
return OpenSaveFileDialog(path.buffer, args->Callback);
return OpenSaveFileDialog(path.buffer, args->Callback, fileExts[0]);
}
static GC fb_gc;