Removing plugin system is holding back development to much.
This commit is contained in:
parent
048843a1d4
commit
edb789ca4a
22 changed files with 198 additions and 562 deletions
|
|
@ -1,35 +1,62 @@
|
|||
#include "DatabaseWindow.h"
|
||||
#include "plugin_support/IPluginContentWidgetContext.h"
|
||||
#include "util.h"
|
||||
#include "OpenDatabase.h"
|
||||
#include "MasterController.h"
|
||||
#include "TaskExecutor.h"
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QFileDialog>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QMetaMethod>
|
||||
#include <QStandardPaths>
|
||||
#include <QTableView>
|
||||
|
||||
// Pages that should become modules
|
||||
#include "EditTableWidget.h"
|
||||
#include "CodeGenerator.h"
|
||||
#include "QueryTool.h"
|
||||
|
||||
namespace pg = Pgsql;
|
||||
|
||||
|
||||
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
||||
: LMainWindow(parent)
|
||||
|
||||
: QMainWindow(parent)
|
||||
, m_masterController(master)
|
||||
{
|
||||
connect(&loadWatcher, &QFutureWatcher<LoadCatalog::Result>::finished,
|
||||
this, &DatabaseWindow::catalogLoaded);
|
||||
|
||||
initModuleMenus();
|
||||
m_tabWidget = new QTabWidget(this);
|
||||
setCentralWidget(m_tabWidget);
|
||||
|
||||
createActions();
|
||||
initMenus();
|
||||
|
||||
QMetaObject::connectSlotsByName(this);
|
||||
}
|
||||
|
||||
DatabaseWindow::~DatabaseWindow() = default;
|
||||
|
||||
void DatabaseWindow::addPage(QWidget* page, QString caption)
|
||||
{
|
||||
m_tabWidget->addTab(page, caption);
|
||||
m_tabWidget->setCurrentWidget(page);
|
||||
}
|
||||
|
||||
void DatabaseWindow::setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint)
|
||||
{
|
||||
auto index = m_tabWidget->indexOf(widget);
|
||||
m_tabWidget->setTabText(index, caption);
|
||||
m_tabWidget->setTabToolTip(index, hint);
|
||||
}
|
||||
|
||||
void DatabaseWindow::setTabIcon(QWidget *widget, const QString &iconname)
|
||||
{
|
||||
auto index = m_tabWidget->indexOf(widget);
|
||||
auto n = ":/icons/16x16/" + iconname;
|
||||
m_tabWidget->setTabIcon(index, QIcon(n));
|
||||
}
|
||||
|
||||
void DatabaseWindow::newCreateTablePage()
|
||||
{
|
||||
auto w = new EditTableWidget(m_database, this);
|
||||
|
|
@ -65,27 +92,130 @@ void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void DatabaseWindow::createActions()
|
||||
{
|
||||
{
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/about.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
actionAbout = new QAction(icon, tr("About"), this);
|
||||
}
|
||||
{
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/page_white_delete.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
auto action = actionClose = new QAction(icon, tr("Close"), this);
|
||||
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W));
|
||||
}
|
||||
{
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/new_query_tab.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
auto action = actionNewSql = new QAction(icon, tr("New Query"), this);
|
||||
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
|
||||
}
|
||||
{
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/folder.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
auto action = actionOpenSql = new QAction(icon, tr("Open Query"), this);
|
||||
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
|
||||
}
|
||||
|
||||
// {
|
||||
// auto ca = makeContextAction<QueryTool>(tr("Save SQL"), &QueryTool::save);
|
||||
// ca->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
||||
// ca->setMenuLocation(MenuPath("File/Save"));
|
||||
// ca->setToolbarLocation(ToolbarLocation("main", "save"));
|
||||
// // how we tell the system we want this to become a menu button with this as it's default action
|
||||
// registerContextAction(ca);
|
||||
// }
|
||||
// {
|
||||
// auto ca = makeContextAction<QueryTool>(tr("Save SQL as"), &QueryTool::saveAs);
|
||||
// ca->setMenuLocation(MenuPath("File/Save"));
|
||||
// ca->setToolbarLocation(ToolbarLocation("main", "save"));
|
||||
// // how we tell the system we want this to become a secondary action for the previous button?
|
||||
// registerContextAction(ca);
|
||||
// }
|
||||
// {
|
||||
// auto ca = makeContextAction<QueryTool>(tr("Save copy of SQL as"), &QueryTool::saveCopyAs);
|
||||
// ca->setMenuLocation(MenuPath("File/Save"));
|
||||
// ca->setToolbarLocation(ToolbarLocation("main", "save"));
|
||||
// // how we tell the system we want this to become a secondary action for the previous button?
|
||||
// registerContextAction(ca);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
void DatabaseWindow::initMenus()
|
||||
{
|
||||
// TODO construct menubar
|
||||
auto seperator = new QAction(this);
|
||||
seperator->setSeparator(true);
|
||||
|
||||
auto mb = new QMenuBar(this);
|
||||
menuFile = mb->addMenu(tr("File"));
|
||||
menuFile->addActions({
|
||||
actionNewSql,
|
||||
actionOpenSql,
|
||||
seperator,
|
||||
seperator,
|
||||
actionClose
|
||||
});
|
||||
|
||||
menuHelp = mb->addMenu(tr("Help"));
|
||||
menuHelp->addActions({
|
||||
seperator,
|
||||
actionAbout
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
setMenuBar(mb);
|
||||
}
|
||||
|
||||
|
||||
void DatabaseWindow::on_actionClose_triggered()
|
||||
{
|
||||
m_tabWidget->tabCloseRequested(m_tabWidget->currentIndex());
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionNewSql_triggered()
|
||||
{
|
||||
auto *ct = new QueryTool(m_database, this);
|
||||
addPage(ct, "");
|
||||
ct->newdoc();
|
||||
}
|
||||
|
||||
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(m_database, this);
|
||||
addPage(ct, "");
|
||||
if (!ct->load(file_name)) {
|
||||
// TODO load has failed remove widget or never add it?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::catalogLoaded()
|
||||
{
|
||||
try {
|
||||
m_database = loadWatcher.future().result();
|
||||
auto ctx = context();
|
||||
ctx->registerObject(m_database);
|
||||
|
||||
for (auto f : { "user", "pg_catalog", "information_schema" })
|
||||
ctx->moduleAction("pglab.catalog-inspector", "open", {
|
||||
{ "namespace-filter", f }
|
||||
});
|
||||
for (auto f : { "user", "pg_catalog", "information_schema" }) {
|
||||
// TODO open inspector windows
|
||||
}
|
||||
|
||||
|
||||
newCreateTablePage();
|
||||
} catch (const OpenDatabaseException &ex) {
|
||||
QMessageBox::critical(this, "Error reading database", ex.text());
|
||||
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DatabaseWindow::on_actionAbout_triggered()
|
||||
{
|
||||
QMessageBox::about(this, "pgLab 0.1", tr(
|
||||
|
|
@ -128,4 +258,3 @@ void DatabaseWindow::on_actionCopy_triggered()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue