1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #include "file_dialog_save.h"
- #include <cstdio>
- #include <cstring>
- #ifdef _WIN32
- #include <windows.h>
- #include <Commdlg.h>
- #endif
- IGL_INLINE std::string igl::file_dialog_save()
- {
- const int FILE_DIALOG_MAX_BUFFER = 1024;
- char buffer[FILE_DIALOG_MAX_BUFFER];
- #ifdef __APPLE__
-
-
-
-
- FILE * output = popen(
- "osascript -e \""
- " tell application \\\"System Events\\\"\n"
- " activate\n"
- " set existing_file to choose file name\n"
- " end tell\n"
- " set existing_file_path to (POSIX path of (existing_file))\n"
- "\" 2>/dev/null | tr -d '\n' ","r");
- while ( fgets(buffer, FILE_DIALOG_MAX_BUFFER, output) != NULL )
- {
- }
- #elif defined _WIN32
-
-
- OPENFILENAME ofn;
- char szFile[260];
-
- ZeroMemory(&ofn, sizeof(ofn));
- ofn.lStructSize = sizeof(ofn);
- ofn.hwndOwner = NULL;
- ofn.lpstrFile = new char[100];
-
-
- ofn.lpstrFile[0] = '\0';
- ofn.nMaxFile = sizeof(szFile);
- ofn.lpstrFilter = "";
- ofn.nFilterIndex = 1;
- ofn.lpstrFileTitle = NULL;
- ofn.nMaxFileTitle = 0;
- ofn.lpstrInitialDir = NULL;
- ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
-
- int pos = 0;
- if (GetSaveFileName(&ofn)==TRUE)
- {
- while(ofn.lpstrFile[pos] != '\0')
- {
- buffer[pos] = (char)ofn.lpstrFile[pos];
- pos++;
- }
- buffer[pos] = 0;
- }
- #else
-
- FILE * output = popen("/usr/bin/zenity --file-selection --save","r");
- while ( fgets(buffer, FILE_DIALOG_MAX_BUFFER, output) != NULL )
- {
- }
-
- if (strlen(buffer) > 0)
- {
- buffer[strlen(buffer)-1] = 0;
- }
- #endif
- return std::string(buffer);
- }
|