MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / OpenSaveFileDialog

Function OpenSaveFileDialog

src/Window_X11.c:1146–1172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1144}
1145
1146static cc_result OpenSaveFileDialog(const char* args, FileDialogCallback callback, const char* defaultExt) {
1147 cc_string path; char pathBuffer[1024];
1148 char result[4096] = { 0 };
1149 int len;
1150 /* TODO this doesn't detect when Zenity doesn't exist */
1151 FILE* fp = popen(args, "r");
1152 if (!fp) return 0;
1153
1154 /* result from zenity is normally just one string */
1155 while (fgets(result, sizeof(result), fp)) { }
1156 pclose(fp);
1157
1158 len = String_Length(result);
1159 if (!len) return 0;
1160
1161 String_InitArray(path, pathBuffer);
1162 String_AppendUtf8(&path, result, len);
1163
1164 /* Add default file extension if necessary */
1165 if (defaultExt) {
1166 cc_string file = path;
1167 Utils_UNSAFE_GetFilename(&file);
1168 if (String_IndexOf(&file, '.') == -1) String_AppendConst(&path, defaultExt);
1169 }
1170 callback(&path);
1171 return 0;
1172}
1173
1174cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) {
1175 const char* const* filters = args->filters;

Callers 2

Window_OpenFileDialogFunction · 0.70
Window_SaveFileDialogFunction · 0.70

Calls 5

String_LengthFunction · 0.85
String_AppendUtf8Function · 0.85
Utils_UNSAFE_GetFilenameFunction · 0.85
String_AppendConstFunction · 0.85
callbackFunction · 0.85

Tested by

no test coverage detected