Improved question an error handling when closing and saving query.

This commit is contained in:
eelke 2017-02-19 14:46:01 +01:00
parent f5046fbd68
commit 4adb78a84e
2 changed files with 27 additions and 13 deletions

View file

@ -152,23 +152,29 @@ bool QueryTab::load(const QString &filename)
return result;
}
void QueryTab::save()
bool QueryTab::save()
{
bool result;
if (m_fileName.isEmpty()) {
saveAs();
result = saveAs();
}
else {
saveSqlTo(m_fileName);
result = saveSqlTo(m_fileName);
}
return result;
}
void QueryTab::saveAs()
bool QueryTab::saveAs()
{
bool result = false;
QString filename = promptUserForSaveSqlFilename();
if (!filename.isEmpty()) {
saveSqlTo(filename);
setFileName(filename);
result = saveSqlTo(filename);
if (result) {
setFileName(filename);
}
}
return result;
}
void QueryTab::saveCopyAs()
@ -253,12 +259,19 @@ bool QueryTab::continueWithoutSavingWarning()
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
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);
msgBox.setText(QString("Save changes in document \"%1\" before closing?").arg(m_fileName));
msgBox.setInformativeText("The changes will be lost when you choose Discard.");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
int ret = msgBox.exec();
return ret == QMessageBox::Yes;
if (ret == QMessageBox::Save) {
if (!save()) {
// save failed or was a saveAs and was cancelled, don't close!
ret = QMessageBox::Cancel;
}
}
return ret != QMessageBox::Cancel;
}
bool QueryTab::saveSqlTo(const QString &filename)
@ -281,6 +294,7 @@ bool QueryTab::saveSqlTo(const QString &filename)
block = block.next();
}*/
stream.flush();
if (stream.status() == QTextStream::Ok) {
m_queryTextChanged = false;
result = true;