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

Method onLanguageChanged

app/src/MQTT/PublisherScriptEditor.cpp:393–415  ·  view source on GitHub ↗

* @brief Swaps the highlighter and, when recognised, the template variant. */

Source from the content-addressed store, hash-verified

391 * @brief Swaps the highlighter and, when recognised, the template variant.
392 */
393void MQTT::PublisherScriptEditor::onLanguageChanged(int index)
394{
395 const int newLang = (index == 1) ? SerialStudio::Lua : SerialStudio::JavaScript;
396 if (newLang == m_language)
397 return;
398
399 const int tmplIdx = detectTemplate();
400
401 applyLanguage(newLang);
402
403 if (tmplIdx >= 0) {
404 const auto& tmpl = m_templates[tmplIdx];
405 const QString code = (newLang == SerialStudio::Lua) ? tmpl.luaCode : tmpl.jsCode;
406 m_editor->setPlainText(code);
407 m_templateCombo->setCurrentIndex(tmplIdx + 1);
408 return;
409 }
410
411 const QString trimmed = m_editor->toPlainText().trimmed();
412 const int other = (newLang == SerialStudio::Lua) ? SerialStudio::JavaScript : SerialStudio::Lua;
413 if (trimmed == defaultPlaceholder(other).trimmed())
414 m_editor->setPlainText(defaultPlaceholder(newLang));
415}
416
417/**
418 * @brief Toggles hex-mode framing of the test input.

Callers

nothing calls this directly

Calls 1

setCurrentIndexMethod · 0.80

Tested by

no test coverage detected