Skip to content

Fix: always prompt when closing a single SQL tab with unsaved content…#4141

Open
Negi2110 wants to merge 2 commits into
sqlitebrowser:masterfrom
Negi2110:fix/prompt-on-tab-close-in-project
Open

Fix: always prompt when closing a single SQL tab with unsaved content…#4141
Negi2110 wants to merge 2 commits into
sqlitebrowser:masterfrom
Negi2110:fix/prompt-on-tab-close-in-project

Conversation

@Negi2110

Copy link
Copy Markdown

Fixes #4128

Problem

When closing an individual SQL tab that belongs to a saved project,
the save prompt was gated behind the promptsqltabsinnewproject
preference 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 whether
closing the entire app (bulk path via closeFiles()) or closing a
single tab (via closeSqlTab()). The preference makes sense for
the bulk path but not for a deliberate single-tab close.

Fix

Added a singleTabClose parameter (default false) to
askSaveSqlTab(). When closeSqlTab() calls it, it passes true,
bypassing the preference check and always prompting if the tab
has unsaved content. The closeFiles() bulk path is unchanged.

How to test

  1. Open a database → Execute SQL tab → type any query
  2. File → Save Project → save as test.sqbpro
  3. Type new content in the SQL tab
  4. Click ✕ to close the tab
  5. ✅ "Do you want to save?" prompt appears
  6. Repeat but close the entire app after saving → ✅ no prompt

…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).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 singleTabClose parameter to MainWindow::askSaveSqlTab() (default false) to distinguish bulk-close vs. single-tab close behavior.
  • Updated closeSqlTab() to call askSaveSqlTab(..., /*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 singleTabClose is 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) when singleTabClose is 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.

@Negi2110

Negi2110 commented Jun 9, 2026

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: UI/UX - Show "Save?" prompt for tabs in an unmodified project

2 participants