add save as, reload, and save log buttons to scriptingwindow
This commit is contained in:
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"thread": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"chrono": "cpp",
|
||||
"algorithm": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -41,8 +41,11 @@ ScriptingWindow::ScriptingWindow(const QVector<CANFrame> *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<ScriptContainer*>(sender());
|
||||
|
||||
@@ -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<CANFrame>&);
|
||||
@@ -49,6 +51,7 @@ private:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void readSettings();
|
||||
void writeSettings();
|
||||
void saveLog();
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
Ui::ScriptingWindow *ui;
|
||||
|
||||
@@ -108,6 +108,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSaveAsScript">
|
||||
<property name="text">
|
||||
<string>Sa&ve As</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnRevertScript">
|
||||
<property name="text">
|
||||
@@ -115,6 +122,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnReloadScript">
|
||||
<property name="text">
|
||||
<string>R&eload</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnRecompile">
|
||||
<property name="text">
|
||||
@@ -150,6 +164,12 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_log">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="contentsMargins">10, 0, 10, 0</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnClearLog">
|
||||
<property name="text">
|
||||
@@ -157,6 +177,15 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSaveLog">
|
||||
<property name="text">
|
||||
<string>Save L&og</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -169,10 +198,13 @@
|
||||
<tabstop>listLoadedScripts</tabstop>
|
||||
<tabstop>tableVariables</tabstop>
|
||||
<tabstop>btnSaveScript</tabstop>
|
||||
<tabstop>btnSaveAsScript</tabstop>
|
||||
<tabstop>btnRevertScript</tabstop>
|
||||
<tabstop>btnReloadScript</tabstop>
|
||||
<tabstop>btnRecompile</tabstop>
|
||||
<tabstop>cbAutoScroll</tabstop>
|
||||
<tabstop>btnClearLog</tabstop>
|
||||
<tabstop>btnSaveLog</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
Reference in New Issue
Block a user