diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..936eb86 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "files.associations": { + "thread": "cpp", + "*.tcc": "cpp", + "chrono": "cpp", + "algorithm": "cpp" + } +} \ No newline at end of file diff --git a/scriptingwindow.cpp b/scriptingwindow.cpp index 1f24dee..ea254c3 100644 --- a/scriptingwindow.cpp +++ b/scriptingwindow.cpp @@ -41,8 +41,11 @@ ScriptingWindow::ScriptingWindow(const QVector *frames, QWidget *paren connect(ui->btnRecompile, &QAbstractButton::pressed, this, &ScriptingWindow::recompileScript); connect(ui->btnRemoveScript, &QAbstractButton::pressed, this, &ScriptingWindow::deleteCurrentScript); connect(ui->btnRevertScript, &QAbstractButton::pressed, this, &ScriptingWindow::revertScript); + connect(ui->btnReloadScript, &QAbstractButton::pressed, this, &ScriptingWindow::reloadScript); connect(ui->btnSaveScript, &QAbstractButton::pressed, this, &ScriptingWindow::saveScript); + connect(ui->btnSaveAsScript, &QAbstractButton::pressed, this, &ScriptingWindow::saveAsScript); connect(ui->btnClearLog, &QAbstractButton::pressed, this, &ScriptingWindow::clickedLogClear); + connect(ui->btnSaveLog, &QAbstractButton::pressed, this, &ScriptingWindow::saveLog); connect(ui->listLoadedScripts, &QListWidget::currentRowChanged, this, &ScriptingWindow::changeCurrentScript); connect(ui->tableVariables, SIGNAL(cellChanged(int,int)), this, SLOT(updatedValue(int, int))); @@ -301,6 +304,21 @@ void ScriptingWindow::refreshSourceWindow() } void ScriptingWindow::saveScript() +{ + QFile *outFile = new QFile(currentScript->filePath); + + if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) + { + delete outFile; + return; + } + outFile->write(editor->toPlainText().toUtf8()); + currentScript->scriptText = editor->toPlainText(); + outFile->close(); + delete outFile; +} + +void ScriptingWindow::saveAsScript() { QString filename; QFileDialog dialog(this); @@ -358,6 +376,38 @@ void ScriptingWindow::revertScript() } } +void ScriptingWindow::reloadScript() +{ + QMessageBox msgBox; + msgBox.setText("Are you sure you'd like to reload from disk?"); + msgBox.setInformativeText("Really do it?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Cancel); + int ret = msgBox.exec(); + switch (ret) + { + case QMessageBox::Yes: + { + // get the latest version from disk and set in the editor/state + QFile scriptFile(currentScript->filePath); + if (scriptFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QString contents = scriptFile.readAll(); + scriptFile.close(); + editor->setPlainText(contents); + currentScript->scriptText = contents; + currentScript->compileScript(); + } + break; + } + case QMessageBox::No: + break; + default: + // should never be reached + break; + } +} + void ScriptingWindow::recompileScript() { if (currentScript) @@ -373,6 +423,45 @@ void ScriptingWindow::clickedLogClear() elapsedTime.start(); } +void ScriptingWindow::saveLog() +{ + QString filename; + QFileDialog dialog(this); + QSettings settings; + + QStringList filters; + filters.append(QString(tr("Log File (*.log)"))); + + dialog.setDirectory(settings.value("ScriptingWindow/LoadSaveDirectory", dialog.directory().path()).toString()); + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setNameFilters(filters); + dialog.setViewMode(QFileDialog::Detail); + dialog.setAcceptMode(QFileDialog::AcceptSave); + + if (dialog.exec() == QDialog::Accepted) + { + filename = dialog.selectedFiles()[0]; + if (!filename.contains('.')) filename += ".log"; + if (dialog.selectedNameFilter() == filters[0]) + { + QFile *outFile = new QFile(filename); + + if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) + { + delete outFile; + return; + } + int c = ui->listLog ->count(); + for (int row = 0; row < c; row++) { + outFile->write(ui->listLog->item(row)->data(Qt::DisplayRole).toString().toUtf8() + "\n"); + } + outFile->close(); + delete outFile; + settings.setValue("ScriptingWindow/LoadSaveDirectory", dialog.directory().path()); + } + } +} + void ScriptingWindow::log(QString text) { ScriptContainer *cont = qobject_cast(sender()); diff --git a/scriptingwindow.h b/scriptingwindow.h index 156a72e..5577099 100644 --- a/scriptingwindow.h +++ b/scriptingwindow.h @@ -37,7 +37,9 @@ private slots: void deleteCurrentScript(); void refreshSourceWindow(); void saveScript(); + void saveAsScript(); void revertScript(); + void reloadScript(); void recompileScript(); void changeCurrentScript(); void newFrames(const CANConnection*, const QVector&); @@ -49,6 +51,7 @@ private: void closeEvent(QCloseEvent *event); void readSettings(); void writeSettings(); + void saveLog(); bool eventFilter(QObject *obj, QEvent *event); Ui::ScriptingWindow *ui; diff --git a/ui/scriptingwindow.ui b/ui/scriptingwindow.ui index 35c0b9e..5623804 100644 --- a/ui/scriptingwindow.ui +++ b/ui/scriptingwindow.ui @@ -108,6 +108,13 @@ + + + + Sa&ve As + + + @@ -115,6 +122,13 @@ + + + + R&eload + + + @@ -151,11 +165,26 @@ - - - Clear Log &Window - - + + + Qt::AlignCenter + + 10, 0, 10, 0 + + + + Clear Log &Window + + + + + + + Save L&og + + + + @@ -169,10 +198,13 @@ listLoadedScripts tableVariables btnSaveScript + btnSaveAsScript btnRevertScript + btnReloadScript btnRecompile cbAutoScroll btnClearLog + btnSaveLog