When files are dropped on a database window open them as sql files.
This commit is contained in:
parent
b04b947633
commit
6d08b40309
3 changed files with 55 additions and 22 deletions
|
|
@ -14,6 +14,7 @@
|
|||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QMetaMethod>
|
||||
#include <QMimeData>
|
||||
#include <QStandardPaths>
|
||||
#include <QStatusBar>
|
||||
#include <QTableView>
|
||||
|
|
@ -44,6 +45,8 @@ DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
|||
initMenus();
|
||||
|
||||
QMetaObject::connectSlotsByName(this);
|
||||
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
DatabaseWindow::~DatabaseWindow() = default;
|
||||
|
|
@ -397,20 +400,35 @@ void DatabaseWindow::closeTab(int index)
|
|||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::openSqlFile(QString file_name)
|
||||
{
|
||||
if ( ! file_name.isEmpty()) {
|
||||
auto *ct = new QueryTool(this, this);
|
||||
if (ct->load(file_name)) {
|
||||
ct->addAction(actionExecuteQuery);
|
||||
addPage(ct, ct->title());
|
||||
}
|
||||
else {
|
||||
delete ct;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DatabaseWindow::catalogLoaded()
|
||||
{
|
||||
try {
|
||||
m_database = loadWatcher.future().result();
|
||||
try {
|
||||
m_database = loadWatcher.future().result();
|
||||
|
||||
// for (auto f : { "user", "pg_catalog", "information_schema" }) {
|
||||
// // TODO open inspector windows
|
||||
// }
|
||||
// newCreateTablePage();
|
||||
on_actionNewSql_triggered();
|
||||
} catch (const OpenDatabaseException &ex) {
|
||||
QMessageBox::critical(this, "Error reading database", ex.text());
|
||||
close();
|
||||
}
|
||||
// for (auto f : { "user", "pg_catalog", "information_schema" }) {
|
||||
// // TODO open inspector windows
|
||||
// }
|
||||
// newCreateTablePage();
|
||||
on_actionNewSql_triggered();
|
||||
} catch (const OpenDatabaseException &ex) {
|
||||
QMessageBox::critical(this, "Error reading database", ex.text());
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::tableSelected(Oid tableoid)
|
||||
|
|
@ -557,16 +575,7 @@ void DatabaseWindow::on_actionOpenSql_triggered()
|
|||
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
|
||||
QString file_name = QFileDialog::getOpenFileName(this,
|
||||
tr("Open sql query"), home_dir, tr("SQL files (*.sql *.txt)"));
|
||||
if ( ! file_name.isEmpty()) {
|
||||
auto *ct = new QueryTool(this, this);
|
||||
if (ct->load(file_name)) {
|
||||
ct->addAction(actionExecuteQuery);
|
||||
addPage(ct, ct->title());
|
||||
}
|
||||
else {
|
||||
delete ct;
|
||||
}
|
||||
}
|
||||
openSqlFile(file_name);
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionPasteLangString_triggered()
|
||||
|
|
@ -662,5 +671,21 @@ std::shared_ptr<OpenDatabase> DatabaseWindow::openDatabase()
|
|||
|
||||
void DatabaseWindow::showStatusBarMessage(QString message)
|
||||
{
|
||||
statusBar()->showMessage(message);
|
||||
statusBar()->showMessage(message);
|
||||
}
|
||||
|
||||
void DatabaseWindow::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::dropEvent(QDropEvent *event)
|
||||
{
|
||||
foreach (const QUrl &url, event->mimeData()->urls()) {
|
||||
QString file_name = url.toLocalFile();
|
||||
qDebug() << "Dropped file:" << file_name;
|
||||
openSqlFile(file_name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,6 +128,8 @@ private:
|
|||
void newCatalogInspectorPage(QString caption, NamespaceFilter filter);
|
||||
void newServerInspectorPage();
|
||||
void closeTab(int index);
|
||||
void openSqlFile(QString file_name);
|
||||
|
||||
private slots:
|
||||
void catalogLoaded();
|
||||
void tableSelected(Oid tableoid);
|
||||
|
|
@ -167,6 +169,11 @@ public:
|
|||
virtual void setIconForWidget(QWidget *widget, QIcon icon) override;
|
||||
virtual std::shared_ptr<OpenDatabase> openDatabase() override;
|
||||
virtual void showStatusBarMessage(QString message) override;
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ QueryTool::QueryTool(IDatabaseWindow *context, QWidget *parent)
|
|||
}
|
||||
|
||||
connect(ui->queryEdit, &QPlainTextEdit::textChanged, this, &QueryTool::queryTextChanged);
|
||||
ui->queryEdit->setAcceptDrops(false);
|
||||
|
||||
m_queryParamListController = new QueryParamListController(ui->paramTableView, m_context->openDatabase(), this);
|
||||
connect(ui->addButton, &QPushButton::clicked, m_queryParamListController,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue