diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index be20fefb..97416fe8 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -822,6 +822,7 @@ void MainWindow::dbState( bool dirty ) { ui->fileSaveAction->setEnabled(dirty); ui->fileRevertAction->setEnabled(dirty); + ui->fileAttachAction->setEnabled(!dirty); } void MainWindow::fileSave() @@ -1932,3 +1933,26 @@ void MainWindow::saveProject() file.close(); } } + +void MainWindow::fileAttach() +{ + // Get file name of database to attach + QString file = QFileDialog::getOpenFileName( + this, + tr("Choose a database file"), + PreferencesDialog::getSettingsValue("db", "defaultlocation").toString()); + if(!QFile::exists(file)) + return; + + // Ask for name to be given to the attached database + QString attachAs = QInputDialog::getText(this, + qApp->applicationName(), + tr("Please specify the database name under which you want to access the attached database") + ).trimmed(); + if(attachAs.isEmpty()) + return; + + // Attach database + if(!db.executeSQL(QString("ATTACH '%1' AS `%2`").arg(file).arg(attachAs), false)) + QMessageBox::warning(this, qApp->applicationName(), db.lastErrorMessage); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index 4e14ea3a..be314476 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -175,6 +175,7 @@ private slots: void updateBrowseDataColumnWidth(int section, int /*old_size*/, int new_size); bool loadProject(QString filename = QString()); void saveProject(); + void fileAttach(); }; #endif diff --git a/src/MainWindow.ui b/src/MainWindow.ui index ae570b74..e1acf50c 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -787,6 +787,7 @@ + @@ -1514,6 +1515,14 @@ Load a working session from a file + + + false + + + &Attach Database + + @@ -2289,6 +2298,22 @@ + + fileAttachAction + triggered() + MainWindow + fileAttach() + + + -1 + -1 + + + 499 + 314 + + + fileOpen() @@ -2337,5 +2362,6 @@ loadExtension() loadProject() saveProject() + fileAttach()