| 906 | } |
| 907 | |
| 908 | QString MainWindow::currentModelFile() |
| 909 | { |
| 910 | if (curEditor) { |
| 911 | if (curEditor->filepath.endsWith(".fzn") || |
| 912 | (curEditor->filepath.endsWith(".mzn") && !curEditor->filepath.endsWith(".mzc.mzn"))) { |
| 913 | // The current file is a model |
| 914 | return curEditor->filepath; |
| 915 | } |
| 916 | if (curEditor->filepath.isEmpty()) { |
| 917 | // The current file is a playground buffer |
| 918 | QTemporaryDir* modelTmpDir = new QTemporaryDir; |
| 919 | if (!modelTmpDir->isValid()) { |
| 920 | throw InternalError("Could not create temporary directory for compilation."); |
| 921 | } else { |
| 922 | cleanupTmpDirs.append(modelTmpDir); |
| 923 | QString model = modelTmpDir->path() + "/untitled_model." + (curEditor->filename.endsWith(".fzn") ? "fzn" : "mzn"); |
| 924 | QFile modelFile(model); |
| 925 | if (modelFile.open(QIODevice::ReadWrite)) { |
| 926 | QTextStream ts(&modelFile); |
| 927 | #if QT_VERSION < 0x060000 |
| 928 | ts.setCodec("UTF-8"); |
| 929 | #endif |
| 930 | ts << curEditor->document()->toPlainText(); |
| 931 | modelFile.close(); |
| 932 | } else { |
| 933 | throw InternalError("Could not write temporary model file."); |
| 934 | } |
| 935 | curEditor->playgroundTempFile = model; |
| 936 | return model; |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | auto modelFiles = getProject().modelFiles(); |
| 942 | if (modelFiles.count() == 0) { |
| 943 | // There are no model files |
| 944 | return ""; |
| 945 | } |
| 946 | if (modelFiles.count() == 1) { |
| 947 | return modelFiles[0]; |
| 948 | } |
| 949 | |
| 950 | int selectedModel = paramDialog->getModel(modelFiles); |
| 951 | if (selectedModel == -1) { |
| 952 | return ""; |
| 953 | } |
| 954 | return modelFiles[selectedModel]; |
| 955 | } |
| 956 | |
| 957 | bool MainWindow::promptSaveModified() |
| 958 | { |