diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index d6686d90..6a6ec113 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1108,7 +1108,7 @@ void MainWindow::closeSqlTab(int index, bool force) delete w; } -void MainWindow::openSqlTab(bool resetCounter) +unsigned int MainWindow::openSqlTab(bool resetCounter) { static unsigned int tabNumber = 0; @@ -1122,4 +1122,40 @@ void MainWindow::openSqlTab(bool resetCounter) w->getEditor()->insertFieldCompleterModels(completerModelsFields); int index = ui->tabSqlAreas->addTab(w, QString("SQL %1").arg(++tabNumber)); ui->tabSqlAreas->setCurrentIndex(index); + + return index; +} + +void MainWindow::openSqlFile() +{ + QString file = QFileDialog::getOpenFileName( + this, + tr("Select SQL file to open"), + PreferencesDialog::getSettingsValue("db", "defaultlocation").toString(), + tr("Text files(*.sql *.txt);;All files(*)")); + + if(QFile::exists(file)) + { + QFile f(file); + f.open(QIODevice::ReadOnly); + unsigned int index = openSqlTab(); + qobject_cast(ui->tabSqlAreas->widget(index))->getEditor()->setPlainText(f.readAll()); + QFileInfo fileinfo(file); + ui->tabSqlAreas->setTabText(index, fileinfo.fileName()); + } +} + +void MainWindow::saveSqlFile() +{ + QString file = QFileDialog::getSaveFileName( + this, + tr("Select file name"), + PreferencesDialog::getSettingsValue("db", "defaultlocation").toString(), + tr("Text files(*.sql *.txt);;All files(*)")); + + QFile f(file); + f.open(QIODevice::WriteOnly); + f.write(qobject_cast(ui->tabSqlAreas->currentWidget())->getSql().toUtf8()); + QFileInfo fileinfo(file); + ui->tabSqlAreas->setTabText(ui->tabSqlAreas->currentIndex(), fileinfo.fileName()); } diff --git a/src/MainWindow.h b/src/MainWindow.h index d003f6fc..660a5dd1 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -136,8 +136,10 @@ private slots: virtual void mainTabSelected( int tabindex ); virtual void browseTableHeaderClicked(int logicalindex); virtual void createSyntaxHighlighters(); - virtual void openSqlTab(bool resetCounter = false); + virtual unsigned int openSqlTab(bool resetCounter = false); virtual void closeSqlTab(int index, bool force = false); + virtual void openSqlFile(); + virtual void saveSqlFile(); }; #endif diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 77da5bff..2db2299f 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -292,7 +292,7 @@ 0 0 - 763 + 278 444 @@ -746,6 +746,9 @@ toolBar1 + + + @@ -1271,6 +1274,24 @@ F5 + + + + :/icons/open_sql:/icons/open_sql + + + Open SQL file + + + + + + :/icons/save_sql:/icons/save_sql + + + Save SQL file + + @@ -1971,6 +1992,38 @@ + + actionSqlOpenFile + activated() + MainWindow + openSqlFile() + + + -1 + -1 + + + 399 + 299 + + + + + actionSqlSaveFile + activated() + MainWindow + saveSqlFile() + + + -1 + -1 + + + 399 + 299 + + + fileOpen() @@ -2014,5 +2067,7 @@ copy() closeSqlTab(int) openSqlTab() + openSqlFile() + saveSqlFile() diff --git a/src/icons/icons.qrc b/src/icons/icons.qrc index 39363302..16609383 100644 --- a/src/icons/icons.qrc +++ b/src/icons/icons.qrc @@ -26,6 +26,8 @@ help.png tab_add.png resultset_next.png + page_save.png + page_white_database.png oldimages/128.png diff --git a/src/icons/page_save.png b/src/icons/page_save.png new file mode 100644 index 00000000..caea546a Binary files /dev/null and b/src/icons/page_save.png differ diff --git a/src/icons/page_white_database.png b/src/icons/page_white_database.png new file mode 100644 index 00000000..bddba1f9 Binary files /dev/null and b/src/icons/page_white_database.png differ