From 09afe637c600b5759d86a841ebfa95306f7d3bf1 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Tue, 7 May 2013 20:33:04 +0200 Subject: [PATCH] MainWindow: Don't open new SQL tab when the current one is empty When opening an SQL file don't open a new tab for it when the current one is completely empty and could be used just as well. --- src/MainWindow.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 2def9bc6..36521c3d 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1145,7 +1145,15 @@ void MainWindow::openSqlFile() { QFile f(file); f.open(QIODevice::ReadOnly); - unsigned int index = openSqlTab(); + + // Decide wether to open a new tab or take the current one + unsigned int index; + SqlExecutionArea* current_tab = qobject_cast(ui->tabSqlAreas->currentWidget()); + if(current_tab->getSql().isEmpty() && current_tab->getModel()->rowCount() == 0) + index = ui->tabSqlAreas->currentIndex(); + else + index = openSqlTab(); + qobject_cast(ui->tabSqlAreas->widget(index))->getEditor()->setPlainText(f.readAll()); QFileInfo fileinfo(file); ui->tabSqlAreas->setTabText(index, fileinfo.fileName());