* @brief Shows a template picker dialog and loads the selected template. */
| 517 | * @brief Shows a template picker dialog and loads the selected template. |
| 518 | */ |
| 519 | void 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. |
nothing calls this directly
no test coverage detected