Skip to content
Open
Show file tree
Hide file tree
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
22 changes: 14 additions & 8 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SqlExecutionArea*>(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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading