* @brief Opens a file dialog to import an external JS file. */
| 283 | * @brief Opens a file dialog to import an external JS file. |
| 284 | */ |
| 285 | void DataModel::OutputCodeEditor::import() |
| 286 | { |
| 287 | auto* dialog = new QFileDialog( |
| 288 | nullptr, tr("Select Javascript file to import"), QDir::homePath(), QStringLiteral("*.js")); |
| 289 | dialog->setFileMode(QFileDialog::ExistingFile); |
| 290 | |
| 291 | connect(dialog, &QFileDialog::fileSelected, this, [this, dialog](const QString& path) { |
| 292 | dialog->deleteLater(); |
| 293 | if (path.isEmpty()) |
| 294 | return; |
| 295 | |
| 296 | QMetaObject::invokeMethod( |
| 297 | this, |
| 298 | [this, path]() { |
| 299 | QFile file(path); |
| 300 | if (file.open(QFile::ReadOnly)) { |
| 301 | m_widget.setPlainText(QString::fromUtf8(file.readAll())); |
| 302 | file.close(); |
| 303 | } |
| 304 | }, |
| 305 | Qt::QueuedConnection); |
| 306 | }); |
| 307 | |
| 308 | dialog->open(); |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * @brief Loads the transmit function from the currently selected output widget. |