diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index b2c1aa90c..239cde7c2 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -2089,18 +2089,24 @@ void MainWindow::logSql(const QString& sql, int msgtype) // Ask user to save the buffer in the specified tab index. // ignoreUnattachedBuffers is used to store answer about buffers not linked to files, so user is only asked once about them. // Return true unless user wants to cancel the invoking action. -bool MainWindow::askSaveSqlTab(int index, bool& ignoreUnattachedBuffers) +bool MainWindow::askSaveSqlTab(int index, bool& ignoreUnattachedBuffers, bool singleTabClose) { SqlExecutionArea* sqlExecArea = qobject_cast(ui->tabSqlAreas->widget(index)); const bool isPromptSQLTabsInNewProject = Settings::getValue("General", "promptsqltabsinnewproject").toBool(); if(sqlExecArea->getEditor()->isModified()) { - if(sqlExecArea->fileName().isEmpty() && !ignoreUnattachedBuffers && isPromptSQLTabsInNewProject) { - // Once the project is saved, remaining SQL tabs will not be modified, so this is only expected to be asked once. - QString message = currentProjectFilename.isEmpty() ? - tr("Do you want to save the changes made to SQL tabs in a new project file?") : - tr("Do you want to save the changes made to SQL tabs in the project file '%1'?"). - arg(QFileInfo(currentProjectFilename).fileName()); + if(sqlExecArea->fileName().isEmpty() && !ignoreUnattachedBuffers && (singleTabClose || isPromptSQLTabsInNewProject)) { + // For single-tab closes, always prompt with singular wording. + // For bulk closes, only asked once after project save. + QString message = singleTabClose ? + (currentProjectFilename.isEmpty() ? + tr("Do you want to save the changes made to this SQL tab in a new project file?") : + tr("Do you want to save the changes made to this SQL tab in the project file '%1'?"). + arg(QFileInfo(currentProjectFilename).fileName())) : + (currentProjectFilename.isEmpty() ? + tr("Do you want to save the changes made to SQL tabs in a new project file?") : + tr("Do you want to save the changes made to SQL tabs in the project file '%1'?"). + arg(QFileInfo(currentProjectFilename).fileName())); QMessageBox::StandardButton reply = QMessageBox::question(nullptr, QApplication::applicationName(), message, @@ -2154,7 +2160,7 @@ void MainWindow::closeSqlTab(int index, bool force, bool askSaving) } // Ask for saving and comply with cancel answer. bool ignoreUnattachedBuffers = false; - if (askSaving && !askSaveSqlTab(index, ignoreUnattachedBuffers)) + if (askSaving && !askSaveSqlTab(index, ignoreUnattachedBuffers, true)) return; // Remove the tab and delete the widget QWidget* w = ui->tabSqlAreas->widget(index); diff --git a/src/MainWindow.h b/src/MainWindow.h index 75d5e16c6..6b77120c7 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -142,7 +142,7 @@ friend TableBrowserDock; QString saveOpenTabs(); void saveProject(const QString& currentFilename); bool closeProject(); - bool askSaveSqlTab(int index, bool& ignoreUnattachedBuffers); + bool askSaveSqlTab(int index, bool& ignoreUnattachedBuffers, bool singleTabClose = false); void focusSqlEditor(); void moveDocksTo(Qt::DockWidgetArea area);