| 1144 | } |
| 1145 | |
| 1146 | static 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 | |
| 1174 | cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) { |
| 1175 | const char* const* filters = args->filters; |
no test coverage detected