From 1c638896e4ebe6366be041c61fa129770a788506 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Thu, 31 Aug 2017 21:05:48 -0400 Subject: [PATCH] Add ability to revert and delete scripts. Fixes to scripting interface. Update version number Multi-script execution works pretty well now. --- config.h | 2 +- scriptingwindow.cpp | 58 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/config.h b/config.h index 870af30..ce9dad3 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 174 +#define VERSION 175 //try to keep this in sync. //SavvyCAN will complain if you connect a GVRET board with a revision diff --git a/scriptingwindow.cpp b/scriptingwindow.cpp index b87a016..814e289 100644 --- a/scriptingwindow.cpp +++ b/scriptingwindow.cpp @@ -36,6 +36,8 @@ ScriptingWindow::ScriptingWindow(const QVector *frames, QWidget *paren connect(CANConManager::getInstance(), &CANConManager::framesReceived, this, &ScriptingWindow::newFrames); + currentScript = NULL; + elapsedTime.start(); } @@ -162,14 +164,45 @@ void ScriptingWindow::createNewScript() container->setScriptWindow(this); scripts.append(container); ui->listLoadedScripts->addItem(container->fileName); - currentScript = container; - editor->setPlainText(container->scriptText); - editor->setEnabled(true); + + ui->listLoadedScripts->setCurrentRow(ui->listLoadedScripts->count() - 1); + changeCurrentScript(); } void ScriptingWindow::deleteCurrentScript() { + int sel = ui->listLoadedScripts->currentRow(); + if (sel < 0) return; + QMessageBox msgBox; + msgBox.setText("Really remove script?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + int ret = msgBox.exec(); + switch (ret) + { + case QMessageBox::Yes: + ui->listLoadedScripts->takeItem(sel); + scripts.removeAt(sel); + currentScript = NULL; + + if (ui->listLoadedScripts->count() > 0) + { + ui->listLoadedScripts->setCurrentRow(0); + changeCurrentScript(); + } + else + { + editor->setPlainText(""); + editor->setEnabled(false); + } + break; + case QMessageBox::No: + break; + default: + // should never be reached + break; + } } void ScriptingWindow::refreshSourceWindow() @@ -212,7 +245,24 @@ void ScriptingWindow::saveScript() void ScriptingWindow::revertScript() { - + QMessageBox msgBox; + msgBox.setText("Are you sure you'd like to revert?"); + msgBox.setInformativeText("Really do it?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Cancel); + int ret = msgBox.exec(); + switch (ret) + { + case QMessageBox::Yes: + //just grab the last stored copy of the script (last compiled version) and replace current text with that text + editor->setPlainText(currentScript->scriptText); + break; + case QMessageBox::No: + break; + default: + // should never be reached + break; + } } void ScriptingWindow::recompileScript()