Gives a warning when there are unsaved changes when opening a file or closing the window.
This commit is contained in:
parent
eb06c57141
commit
35932e7a8d
2 changed files with 42 additions and 0 deletions
|
|
@ -6,6 +6,7 @@
|
|||
#include "sqlhighlighter.h"
|
||||
#include <QStandardPaths>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QTextStream>
|
||||
#include <QTextTable>
|
||||
|
|
@ -14,6 +15,7 @@
|
|||
#include "json/json.h"
|
||||
#include "explaintreemodelitem.h"
|
||||
#include <algorithm>
|
||||
#include <QCloseEvent>
|
||||
|
||||
//#include <thread>
|
||||
|
||||
|
|
@ -121,6 +123,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
QueueTask([this, details]() { receiveNotice(details); });
|
||||
});
|
||||
|
||||
connect(ui->queryEdit, &QPlainTextEdit::textChanged, this, &MainWindow::queryTextChanged);
|
||||
|
||||
m_timeElapsedLabel = new QLabel(this);
|
||||
statusBar()->addPermanentWidget(m_timeElapsedLabel);
|
||||
}
|
||||
|
|
@ -420,9 +424,24 @@ void MainWindow::endTimer()
|
|||
}
|
||||
}
|
||||
|
||||
bool MainWindow::continueWithoutSaving()
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("The document has been modified.");
|
||||
msgBox.setInformativeText("The current query has unsaved changes, do you want to continue without saving those changes?");
|
||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
msgBox.setDefaultButton(QMessageBox::No);
|
||||
int ret = msgBox.exec();
|
||||
return ret == QMessageBox::Yes;
|
||||
}
|
||||
|
||||
void MainWindow::on_actionLoad_SQL_triggered()
|
||||
{
|
||||
//
|
||||
if (m_queryTextChanged && !continueWithoutSaving()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
|
||||
QString file_name = QFileDialog::getOpenFileName(this,
|
||||
tr("Open sql query"), home_dir, tr("SQL files (*.sql *.txt)"));
|
||||
|
|
@ -435,6 +454,7 @@ void MainWindow::on_actionLoad_SQL_triggered()
|
|||
QString line = stream.readLine();
|
||||
ui->queryEdit->appendPlainText(line);
|
||||
}
|
||||
m_queryTextChanged = false;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -452,6 +472,7 @@ void MainWindow::on_actionSave_SQL_triggered()
|
|||
QTextStream stream(&file);
|
||||
QString text = ui->queryEdit->toPlainText();
|
||||
stream << text;
|
||||
m_queryTextChanged = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -519,3 +540,18 @@ void MainWindow::on_actionCancel_triggered()
|
|||
{
|
||||
cancel_query();
|
||||
}
|
||||
|
||||
void MainWindow::queryTextChanged()
|
||||
{
|
||||
m_queryTextChanged = true;
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (!m_queryTextChanged || continueWithoutSaving()) {
|
||||
event->accept();
|
||||
}
|
||||
else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue