Fix: always prompt when closing a single SQL tab with unsaved content…#4141
Fix: always prompt when closing a single SQL tab with unsaved content…#4141Negi2110 wants to merge 2 commits into
Conversation
…sqlitebrowser#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).
There was a problem hiding this comment.
Pull request overview
This PR fixes a UX/data-loss issue where closing a single SQL tab with unsaved content could silently discard edits when the promptsqltabsinnewproject preference was disabled, even if the tab belonged to a saved project. It introduces a new singleTabClose flag to force prompting on deliberate single-tab closes while preserving the existing “bulk close” behavior.
Changes:
- Added a
singleTabCloseparameter toMainWindow::askSaveSqlTab()(defaultfalse) to distinguish bulk-close vs. single-tab close behavior. - Updated
closeSqlTab()to callaskSaveSqlTab(..., /*singleTabClose=*/true)so unsaved buffers always prompt on single-tab close. - Left the
closeFiles()bulk path behavior unchanged by relying on the new default parameter.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/MainWindow.h |
Extends askSaveSqlTab signature with a singleTabClose defaulted parameter. |
src/MainWindow.cpp |
Uses singleTabClose to bypass the preference gate during single-tab closes and updates the call site in closeSqlTab(). |
Comments suppressed due to low confidence (1)
src/MainWindow.cpp:2103
- When
singleTabCloseis true, this prompt can be shown for closing a single tab, but the text currently says "changes made to SQL tabs" (plural) and the adjacent comment implies this is only asked once after saving a project. This becomes misleading for single-tab closes; consider using singular wording (and adjusting the comment) whensingleTabCloseis set.
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());
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Addressed the Copilot review suggestion — updated the prompt message to use singular wording ('this SQL tab') when closing a single tab, keeping the original plural wording for the bulk-close path. |
Fixes #4128
Problem
When closing an individual SQL tab that belongs to a saved project,
the save prompt was gated behind the
promptsqltabsinnewprojectpreference setting. If a user had that setting disabled, closing a
single tab would silently discard its content with no warning.
The root cause:
askSaveSqlTab()was called the same way whetherclosing the entire app (bulk path via
closeFiles()) or closing asingle tab (via
closeSqlTab()). The preference makes sense forthe bulk path but not for a deliberate single-tab close.
Fix
Added a
singleTabCloseparameter (defaultfalse) toaskSaveSqlTab(). WhencloseSqlTab()calls it, it passestrue,bypassing the preference check and always prompting if the tab
has unsaved content. The
closeFiles()bulk path is unchanged.How to test