* @brief Handles a user-initiated language switch from the QML combobox. */
| 205 | * @brief Handles a user-initiated language switch from the QML combobox. |
| 206 | */ |
| 207 | void DataModel::JsCodeEditor::switchLanguage(const int language) |
| 208 | { |
| 209 | if (m_language == language) |
| 210 | return; |
| 211 | |
| 212 | if (language == SerialStudio::Native || m_language == SerialStudio::Native) { |
| 213 | switchNativeLanguage(language); |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | if (isModified()) { |
| 218 | const auto answer = Misc::Utilities::showMessageBox( |
| 219 | tr("Change Scripting Language?"), |
| 220 | tr("Switching the scripting language replaces the current " |
| 221 | "parser code with the equivalent template in the new language." |
| 222 | "\n\nAny unsaved changes are lost. Continue?"), |
| 223 | QMessageBox::Warning, |
| 224 | QString(), |
| 225 | QMessageBox::Yes | QMessageBox::No); |
| 226 | |
| 227 | if (answer != QMessageBox::Yes) |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | auto& parser = DataModel::FrameParser::instance(); |
| 232 | auto& model = DataModel::ProjectModel::instance(); |
| 233 | |
| 234 | const int tmplIdx = parser.detectTemplate(text()); |
| 235 | |
| 236 | model.updateSourceFrameParserLanguage(m_sourceId, language); |
| 237 | |
| 238 | if (tmplIdx >= 0) |
| 239 | parser.setTemplateIdx(m_sourceId, tmplIdx); |
| 240 | else |
| 241 | parser.loadDefaultTemplate(m_sourceId, true); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * @brief Switches into/out of Native, converting the template to its equivalent both ways. |
nothing calls this directly
no test coverage detected