MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / switchLanguage

Method switchLanguage

app/src/DataModel/Editors/JsCodeEditor.cpp:207–242  ·  view source on GitHub ↗

* @brief Handles a user-initiated language switch from the QML combobox. */

Source from the content-addressed store, hash-verified

205 * @brief Handles a user-initiated language switch from the QML combobox.
206 */
207void 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.

Callers

nothing calls this directly

Calls 4

setTemplateIdxMethod · 0.80
detectTemplateMethod · 0.45
loadDefaultTemplateMethod · 0.45

Tested by

no test coverage detected