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.
This commit is contained in:
Martin Kleusberg
2013-05-07 20:33:04 +02:00
parent d6ed7e932f
commit 09afe637c6

View File

@@ -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<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget());
if(current_tab->getSql().isEmpty() && current_tab->getModel()->rowCount() == 0)
index = ui->tabSqlAreas->currentIndex();
else
index = openSqlTab();
qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->widget(index))->getEditor()->setPlainText(f.readAll());
QFileInfo fileinfo(file);
ui->tabSqlAreas->setTabText(index, fileinfo.fileName());