MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / ButtonClicked

Method ButtonClicked

Source/ScriptModule.cpp:920–1033  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

918}
919
920void 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;

Callers

nothing calls this directly

Calls 11

ofToDataPathFunction · 0.85
ofStringReplaceFunction · 0.85
PublishMethod · 0.80
GetFileChooserParentMethod · 0.80
sizeMethod · 0.80
SpawnModuleOnTheFlyMethod · 0.80
SetAudioPausedMethod · 0.80
ReloadInitialLayoutMethod · 0.80
DeleteModuleMethod · 0.80
GetTextMethod · 0.45
SetTextMethod · 0.45

Tested by

no test coverage detected