| 918 | } |
| 919 | |
| 920 | void ScriptModule::ButtonClicked(ClickButton* button, double time) |
| 921 | { |
| 922 | if (button == mPythonInstalledConfirmButton) |
| 923 | InitializePythonIfNecessary(); |
| 924 | |
| 925 | if (button == mRunButton) |
| 926 | { |
| 927 | mCodeEntry->Publish(); |
| 928 | RunScript(time); |
| 929 | } |
| 930 | |
| 931 | if (button == mStopButton) |
| 932 | Stop(); |
| 933 | |
| 934 | if (button == mSaveScriptButton) |
| 935 | { |
| 936 | FileChooser chooser("Save script as...", File(ofToDataPath("scripts/script.py")), "*.py", true, false, TheSynth->GetFileChooserParent()); |
| 937 | if (chooser.browseForFileToSave(true)) |
| 938 | { |
| 939 | std::string path = chooser.getResult().getFullPathName().toStdString(); |
| 940 | |
| 941 | File resourceFile(path); |
| 942 | TemporaryFile tempFile(resourceFile); |
| 943 | |
| 944 | { |
| 945 | FileOutputStream output(tempFile.getFile()); |
| 946 | |
| 947 | if (!output.openedOk()) |
| 948 | { |
| 949 | DBG("FileOutputStream didn't open correctly ..."); |
| 950 | return; |
| 951 | } |
| 952 | |
| 953 | output.writeText(mCodeEntry->GetText(false), false, false, nullptr); |
| 954 | output.flush(); // (called explicitly to force an fsync on posix) |
| 955 | |
| 956 | if (output.getStatus().failed()) |
| 957 | { |
| 958 | DBG("An error occurred in the FileOutputStream"); |
| 959 | return; |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | bool success = tempFile.overwriteTargetFileWithTemporary(); |
| 964 | if (!success) |
| 965 | { |
| 966 | DBG("An error occurred writing the file"); |
| 967 | return; |
| 968 | } |
| 969 | |
| 970 | RefreshScriptFiles(); |
| 971 | |
| 972 | for (size_t i = 0; i < mScriptFilePaths.size(); ++i) |
| 973 | { |
| 974 | if (mScriptFilePaths[i] == path) |
| 975 | { |
| 976 | mLoadScriptIndex = (int)i; |
| 977 | break; |
nothing calls this directly
no test coverage detected