From 61ec43b2ce9e9410ad412be92381b480311123b2 Mon Sep 17 00:00:00 2001 From: Aman Negi Date: Thu, 14 May 2026 15:31:27 +0530 Subject: [PATCH 1/2] Fix: always prompt when closing a single SQL tab with unsaved content (#4128) When closing an individual SQL tab that belongs to a project, the save prompt was gated behind the 'promptsqltabsinnewproject' preference. This meant users with that setting disabled could accidentally close tabs and lose work silently. Fix: pass singleTabClose=true from closeSqlTab() to askSaveSqlTab(), bypassing the preference check for individual tab closes. The preference still applies when closing the whole app/project (closeFiles path). --- src/MainWindow.cpp | 6 +++--- src/MainWindow.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index b2c1aa90c..ea218a2bf 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -2089,13 +2089,13 @@ 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) { + if(sqlExecArea->fileName().isEmpty() && !ignoreUnattachedBuffers && (singleTabClose || 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?") : @@ -2154,7 +2154,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); From 409fe8bc03944a16b379ab281c6b23628b6112f8 Mon Sep 17 00:00:00 2001 From: Negi2110 Date: Tue, 9 Jun 2026 11:10:05 +0530 Subject: [PATCH 2/2] Address Copilot review: use singular wording for single-tab close prompt --- src/MainWindow.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index ea218a2bf..239cde7c2 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -2096,11 +2096,17 @@ bool MainWindow::askSaveSqlTab(int index, bool& ignoreUnattachedBuffers, bool si if(sqlExecArea->getEditor()->isModified()) { if(sqlExecArea->fileName().isEmpty() && !ignoreUnattachedBuffers && (singleTabClose || 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()); + // 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,