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

Method selectTemplate

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

* @brief Shows a template picker dialog and loads the selected template. */

Source from the content-addressed store, hash-verified

517 * @brief Shows a template picker dialog and loads the selected template.
518 */
519void DataModel::JsCodeEditor::selectTemplate()
520{
521 auto& parser = DataModel::FrameParser::instance();
522
523 bool ok;
524 const auto name = QInputDialog::getItem(nullptr,
525 tr("Select Frame Parser Template"),
526 tr("Choose a template to load:"),
527 parser.templateNames(),
528 0,
529 false,
530 &ok);
531
532 if (!ok)
533 return;
534
535 const int idx = parser.templateNames().indexOf(name);
536 if (idx < 0)
537 return;
538
539 if (m_sourceId > 0) {
540 parser.setTemplateIdx(m_sourceId, idx);
541 const QString code = parser.templateCode(m_sourceId);
542 m_widget.setPlainText(code);
543 m_widget.document()->clearUndoRedoStacks();
544 m_widget.document()->setModified(false);
545 Q_EMIT modifiedChanged();
546 return;
547 }
548
549 parser.setTemplateIdx(0, idx);
550}
551
552/**
553 * @brief Loads the current script into the live engine; true when the test dialog may open.

Callers

nothing calls this directly

Calls 4

setTemplateIdxMethod · 0.80
templateCodeMethod · 0.80
setModifiedMethod · 0.80
indexOfMethod · 0.45

Tested by

no test coverage detected