| 2079 | } |
| 2080 | |
| 2081 | bool JavascriptProcessor::parseSnippetsFromString(const String &x, bool clearUndoHistory /*= false*/) |
| 2082 | { |
| 2083 | String codeToCut = String(x); |
| 2084 | |
| 2085 | for (int i = getNumSnippets(); i > 1; i--) |
| 2086 | { |
| 2087 | SnippetDocument *s = getSnippet(i-1); |
| 2088 | |
| 2089 | const String filter = "function " + s->getCallbackName().toString() + "("; |
| 2090 | |
| 2091 | if (!x.contains(filter)) |
| 2092 | { |
| 2093 | if(MessageManager::getInstance()->isThisTheMessageThread()) |
| 2094 | { |
| 2095 | PresetHandler::showMessageWindow("Invalid script", "The script you are trying to load is not a valid HISE script file.\nThe callback " + filter + " is not defined.", PresetHandler::IconType::Error); |
| 2096 | } |
| 2097 | |
| 2098 | debugError(dynamic_cast<Processor*>(this), s->getCallbackName().toString() + " could not be parsed!"); |
| 2099 | |
| 2100 | return false; |
| 2101 | } |
| 2102 | |
| 2103 | String code = codeToCut.fromLastOccurrenceOf(filter, true, false); |
| 2104 | |
| 2105 | // If this is true, we're loading the preset and don't care about multithreading |
| 2106 | auto shouldBeAsync = !clearUndoHistory; |
| 2107 | |
| 2108 | s->replaceContentAsync(code, shouldBeAsync); |
| 2109 | |
| 2110 | codeToCut = codeToCut.upToLastOccurrenceOf(filter, false, false); |
| 2111 | |
| 2112 | } |
| 2113 | |
| 2114 | getSnippet(0)->replaceContentAsync(codeToCut); |
| 2115 | |
| 2116 | return true; |
| 2117 | } |
| 2118 | |
| 2119 | |
| 2120 | |