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->btnRecompile, &QAbstractButton::pressed, this, &ScriptingWindow::recompileScript);
|
||||||
connect(ui->btnRemoveScript, &QAbstractButton::pressed, this, &ScriptingWindow::deleteCurrentScript);
|
connect(ui->btnRemoveScript, &QAbstractButton::pressed, this, &ScriptingWindow::deleteCurrentScript);
|
||||||
connect(ui->btnRevertScript, &QAbstractButton::pressed, this, &ScriptingWindow::revertScript);
|
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->btnSaveScript, &QAbstractButton::pressed, this, &ScriptingWindow::saveScript);
|
||||||
|
connect(ui->btnSaveAsScript, &QAbstractButton::pressed, this, &ScriptingWindow::saveAsScript);
|
||||||
connect(ui->btnClearLog, &QAbstractButton::pressed, this, &ScriptingWindow::clickedLogClear);
|
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->listLoadedScripts, &QListWidget::currentRowChanged, this, &ScriptingWindow::changeCurrentScript);
|
||||||
connect(ui->tableVariables, SIGNAL(cellChanged(int,int)), this, SLOT(updatedValue(int, int)));
|
connect(ui->tableVariables, SIGNAL(cellChanged(int,int)), this, SLOT(updatedValue(int, int)));
|
||||||
|
|
||||||
@@ -301,6 +304,21 @@ void ScriptingWindow::refreshSourceWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ScriptingWindow::saveScript()
|
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;
|
QString filename;
|
||||||
QFileDialog dialog(this);
|
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()
|
void ScriptingWindow::recompileScript()
|
||||||
{
|
{
|
||||||
if (currentScript)
|
if (currentScript)
|
||||||
@@ -373,6 +423,45 @@ void ScriptingWindow::clickedLogClear()
|
|||||||
elapsedTime.start();
|
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)
|
void ScriptingWindow::log(QString text)
|
||||||
{
|
{
|
||||||
ScriptContainer *cont = qobject_cast<ScriptContainer*>(sender());
|
ScriptContainer *cont = qobject_cast<ScriptContainer*>(sender());
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ private slots:
|
|||||||
void deleteCurrentScript();
|
void deleteCurrentScript();
|
||||||
void refreshSourceWindow();
|
void refreshSourceWindow();
|
||||||
void saveScript();
|
void saveScript();
|
||||||
|
void saveAsScript();
|
||||||
void revertScript();
|
void revertScript();
|
||||||
|
void reloadScript();
|
||||||
void recompileScript();
|
void recompileScript();
|
||||||
void changeCurrentScript();
|
void changeCurrentScript();
|
||||||
void newFrames(const CANConnection*, const QVector<CANFrame>&);
|
void newFrames(const CANConnection*, const QVector<CANFrame>&);
|
||||||
@@ -49,6 +51,7 @@ private:
|
|||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
void saveLog();
|
||||||
bool eventFilter(QObject *obj, QEvent *event);
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
Ui::ScriptingWindow *ui;
|
Ui::ScriptingWindow *ui;
|
||||||
|
|||||||
+37
-5
@@ -108,6 +108,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnSaveAsScript">
|
||||||
|
<property name="text">
|
||||||
|
<string>Sa&ve As</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnRevertScript">
|
<widget class="QPushButton" name="btnRevertScript">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -115,6 +122,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnReloadScript">
|
||||||
|
<property name="text">
|
||||||
|
<string>R&eload</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnRecompile">
|
<widget class="QPushButton" name="btnRecompile">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -151,11 +165,26 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnClearLog">
|
<layout class="QHBoxLayout" name="horizontalLayout_log">
|
||||||
<property name="text">
|
<property name="alignment">
|
||||||
<string>Clear Log &Window</string>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="contentsMargins">10, 0, 10, 0</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnClearLog">
|
||||||
|
<property name="text">
|
||||||
|
<string>Clear Log &Window</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnSaveLog">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save L&og</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
@@ -169,10 +198,13 @@
|
|||||||
<tabstop>listLoadedScripts</tabstop>
|
<tabstop>listLoadedScripts</tabstop>
|
||||||
<tabstop>tableVariables</tabstop>
|
<tabstop>tableVariables</tabstop>
|
||||||
<tabstop>btnSaveScript</tabstop>
|
<tabstop>btnSaveScript</tabstop>
|
||||||
|
<tabstop>btnSaveAsScript</tabstop>
|
||||||
<tabstop>btnRevertScript</tabstop>
|
<tabstop>btnRevertScript</tabstop>
|
||||||
|
<tabstop>btnReloadScript</tabstop>
|
||||||
<tabstop>btnRecompile</tabstop>
|
<tabstop>btnRecompile</tabstop>
|
||||||
<tabstop>cbAutoScroll</tabstop>
|
<tabstop>cbAutoScroll</tabstop>
|
||||||
<tabstop>btnClearLog</tabstop>
|
<tabstop>btnClearLog</tabstop>
|
||||||
|
<tabstop>btnSaveLog</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
Reference in New Issue
Block a user