Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3178,7 +3178,8 @@ void MainWindow::saveProject(const QString& currentFilename)
currentProjectFilename = filename;
QApplication::setOverrideCursor(Qt::WaitCursor);

QXmlStreamWriter xml(&file);
QByteArray byteArray;
QXmlStreamWriter xml(&byteArray);
xml.writeStartDocument();
xml.writeStartElement("sqlb_project");

Expand Down Expand Up @@ -3285,7 +3286,6 @@ void MainWindow::saveProject(const QString& currentFilename)
xml.writeAttribute("name", ui->tabSqlAreas->tabText(i));
if(sqlFilename.isEmpty()) {
xml.writeCharacters(sqlArea->getSql());
sqlArea->getEditor()->setModified(false);
} else {
xml.writeAttribute("filename", sqlFilename);
// Backwards compatibility, so older versions do not break.
Expand All @@ -3300,8 +3300,23 @@ void MainWindow::saveProject(const QString& currentFilename)

xml.writeEndElement();
xml.writeEndDocument();
file.commit();
QTextStream out(&file);
out << byteArray;
if (!file.commit())
{
QMessageBox::warning(this, QApplication::applicationName(), tr("Failed to save project file '%1'!").arg(currentProjectFilename));
QApplication::restoreOverrideCursor();
return;
}

for (int i = 0; i < ui->tabSqlAreas->count(); i++)
{
SqlExecutionArea* sqlArea = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->widget(i));
QString sqlFilename = sqlArea->fileName();
if (sqlFilename.isEmpty()) {
sqlArea->getEditor()->setModified(false);
}
}
addToRecentFilesMenu(filename);
setCurrentFile(db.currentFile());
isProjectModified = false;
Expand Down