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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue