Skip to content

Commit 791a2d8

Browse files
committed
Avoid touching the Modified asterisk marker on Execute SQL tabs
1 parent 943a81f commit 791a2d8

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

src/MainWindow.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ void MainWindow::executeQuery()
11471147
SqlExecutionArea* sqlWidget = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget());
11481148
SqlTextEdit* editor = sqlWidget->getEditor();
11491149
auto* current_tab = ui->tabSqlAreas->currentWidget();
1150-
const QString tabName = ui->tabSqlAreas->tabText(ui->tabSqlAreas->currentIndex()).remove('&');
1150+
const QString tabName = ui->tabSqlAreas->tabText(ui->tabSqlAreas->currentIndex()).remove('&').remove(QRegularExpression("\\*$"));
11511151

11521152
// Remove any error indicators
11531153
editor->clearErrorIndicators();
@@ -2149,6 +2149,26 @@ void MainWindow::closeSqlTab(int index, bool force, bool askSaving)
21492149
focusSqlEditor();
21502150
}
21512151

2152+
void MainWindow::markTabsModified()
2153+
{
2154+
// Add (and remove) an asterisk next to the filename of modified file tabs.
2155+
for (int i = 0; i < ui->tabSqlAreas->count(); ++i) {
2156+
SqlExecutionArea* sqlWidget = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->widget(i));
2157+
QString currentText = ui->tabSqlAreas->tabText(i);
2158+
if (!currentText.endsWith("*")) {
2159+
if (sqlWidget->getEditor()->isModified()) {
2160+
ui->tabSqlAreas->setTabText(i, currentText + "*");
2161+
}
2162+
}
2163+
else {
2164+
if (!sqlWidget->getEditor()->isModified()) {
2165+
currentText.chop(1);
2166+
ui->tabSqlAreas->setTabText(i, currentText);
2167+
}
2168+
}
2169+
}
2170+
}
2171+
21522172
int MainWindow::openSqlTab(bool resetCounter)
21532173
{
21542174
static int tabNumber = 0;
@@ -2166,23 +2186,7 @@ int MainWindow::openSqlTab(bool resetCounter)
21662186
w->getEditor()->setEnabledFindDialog(false);
21672187
w->getEditor()->setFocus();
21682188
connect(w, &SqlExecutionArea::findFrameVisibilityChanged, ui->actionSqlFind, &QAction::setChecked);
2169-
// Add (and remove) an asterisk next to the filename of modified file tabs.
2170-
connect(w->getEditor(), &SqlTextEdit::modificationChanged, this, [this](bool) {
2171-
for(int i=0; i < ui->tabSqlAreas->count(); ++i) {
2172-
SqlExecutionArea* sqlWidget = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->widget(i));
2173-
QString currentText = ui->tabSqlAreas->tabText(i);
2174-
if(!currentText.endsWith("*")) {
2175-
if(sqlWidget->getEditor()->isModified()) {
2176-
ui->tabSqlAreas->setTabText(i, currentText + "*");
2177-
}
2178-
} else {
2179-
if(!sqlWidget->getEditor()->isModified()) {
2180-
currentText.chop(1);
2181-
ui->tabSqlAreas->setTabText(i, currentText);
2182-
}
2183-
}
2184-
}
2185-
});
2189+
connect(w->getEditor(), &SqlTextEdit::modificationChanged, this, &MainWindow::markTabsModified);
21862190

21872191
// Connect now the find shortcut to the editor with widget context, so it isn't ambiguous with other Scintilla Widgets.
21882192
QShortcut* shortcutFind = new QShortcut(ui->actionSqlFind->shortcut(), w->getEditor(), nullptr, nullptr, Qt::WidgetShortcut);
@@ -3282,7 +3286,7 @@ void MainWindow::saveProject(const QString& currentFilename)
32823286
SqlExecutionArea* sqlArea = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->widget(i));
32833287
QString sqlFilename = sqlArea->fileName();
32843288
xml.writeStartElement("sql");
3285-
xml.writeAttribute("name", ui->tabSqlAreas->tabText(i));
3289+
xml.writeAttribute("name", ui->tabSqlAreas->tabText(i).remove(QRegularExpression("\\*$")));
32863290
if(sqlFilename.isEmpty()) {
32873291
xml.writeCharacters(sqlArea->getSql());
32883292
sqlArea->getEditor()->setModified(false);
@@ -3539,10 +3543,12 @@ void MainWindow::renameSqlTab(int index)
35393543
qApp->applicationName(),
35403544
tr("Set a new name for the SQL tab. Use the '&&' character to allow using the following character as a keyboard shortcut."),
35413545
QLineEdit::EchoMode::Normal,
3542-
ui->tabSqlAreas->tabText(index));
3546+
ui->tabSqlAreas->tabText(index).remove(QRegularExpression("\\*$")));
35433547

3548+
35443549
if(!new_name.isNull()) // Don't do anything if the Cancel button was clicked
35453550
ui->tabSqlAreas->setTabText(index, new_name);
3551+
markTabsModified();
35463552
}
35473553

35483554
void MainWindow::setFindFrameVisibility(bool show)
@@ -3826,15 +3832,15 @@ void MainWindow::showContextMenuSqlTabBar(const QPoint& pos)
38263832
QAction* actionDuplicate = new QAction(this);
38273833
actionDuplicate->setText(tr("Duplicate Tab"));
38283834
connect(actionDuplicate, &QAction::triggered, this, [this, tab]() {
3829-
QString tab_name = ui->tabSqlAreas->tabText(tab).remove("&").remove(QRegularExpression(" \\(\\d+\\)$"));
3835+
QString tab_name = ui->tabSqlAreas->tabText(tab).remove("&").remove(QRegularExpression("\\*$")).remove(QRegularExpression(" \\(\\d+\\)$"));
38303836
QString new_tab_name;
38313837
for(int i=1;;i++)
38323838
{
38333839
new_tab_name = tab_name + QString(" (%1)").arg(i);
38343840
bool name_already_exists = false;
38353841
for(int j=0;j<ui->tabSqlAreas->count();j++)
38363842
{
3837-
if(ui->tabSqlAreas->tabText(j).remove("&") == new_tab_name)
3843+
if(ui->tabSqlAreas->tabText(j).remove("&").remove(QRegularExpression("\\*$")) == new_tab_name)
38383844
{
38393845
name_already_exists = true;
38403846
break;

src/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ private slots:
244244
void openUrlOrFile(const QString& urlString);
245245
void newRowCountsTab();
246246

247+
void markTabsModified();
247248
int openSqlTab(bool resetCounter = false);
248249
void closeSqlTab(int index, bool force = false, bool askSaving = true);
249250
void changeSqlTab(int index);

0 commit comments

Comments
 (0)