Most of menu is back in its original state before the plugin experiment.
This commit is contained in:
parent
b0fa02455c
commit
e2fa613a49
2 changed files with 237 additions and 101 deletions
|
|
@ -71,7 +71,14 @@ void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::
|
|||
// auto cgtab = new CodeGenerator(context(), pluginModule(), this);
|
||||
// cgtab->Init(m_database->catalog(), query, dbres);
|
||||
// addPage(cgtab, "Codegen");
|
||||
//
|
||||
//
|
||||
}
|
||||
|
||||
QueryTool *DatabaseWindow::GetActiveQueryTool()
|
||||
{
|
||||
auto widget = m_tabWidget->currentWidget();
|
||||
auto qt = dynamic_cast<QueryTool*>(widget);
|
||||
return qt;
|
||||
}
|
||||
|
||||
void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
||||
|
|
@ -109,6 +116,37 @@ void DatabaseWindow::createActions()
|
|||
action->setObjectName("actionClose");
|
||||
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W));
|
||||
}
|
||||
{
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/page_white_copy.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
auto action = actionCopy = new QAction(icon, tr("Copy"), this);
|
||||
action->setObjectName("actionCopy");
|
||||
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
|
||||
}
|
||||
{
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/token_shortland_character.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
auto action = actionCopyAsCString = new QAction(icon, tr("Copy as C string"), this);
|
||||
action->setObjectName("actionCopyAsCString");
|
||||
action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_C));
|
||||
}
|
||||
{
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/token_shortland_character.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
auto action = actionCopyAsRawCppString = new QAction(icon, tr("Copy as raw C++-string"), this);
|
||||
action->setObjectName("actionCopyAsRawCppString");
|
||||
action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_C));
|
||||
}
|
||||
{
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/table_save.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
auto action = actionExportData = new QAction(icon, tr("Export data"), this);
|
||||
action->setObjectName("actionExportData");
|
||||
}
|
||||
{
|
||||
auto action = actionGenerateCode = new QAction(tr("Generate code"), this);
|
||||
action->setObjectName("actionGenerateCode");
|
||||
}
|
||||
{
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/page_white_add.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
|
|
@ -141,72 +179,170 @@ void DatabaseWindow::createActions()
|
|||
action->setObjectName("actionOpenSql");
|
||||
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);
|
||||
// }
|
||||
|
||||
{
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/script_save.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
auto action = actionSaveSql = new QAction(icon, tr("Save query"), this);
|
||||
action->setObjectName("actionSaveSql");
|
||||
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
||||
}
|
||||
{
|
||||
auto action = actionSaveSqlAs = new QAction(tr("Save query as"), this);
|
||||
action->setObjectName("actionSaveSqlAs");
|
||||
}
|
||||
{
|
||||
auto action = actionSaveCopyOfSqlAs = new QAction(tr("Save copy of query as"), this);
|
||||
action->setObjectName("actionSaveCopyOfSqlAs");
|
||||
}
|
||||
{
|
||||
auto action = actionShowConnectionManager = new QAction(tr("Show connection manager"), this);
|
||||
action->setObjectName("actionShowConnectionManager");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DatabaseWindow::initMenus()
|
||||
{
|
||||
auto seperator = new QAction(this);
|
||||
seperator->setSeparator(true);
|
||||
|
||||
auto mb = new QMenuBar(this);
|
||||
menuFile = mb->addMenu(tr("File"));
|
||||
menuFile->addActions({
|
||||
actionNewSql,
|
||||
actionOpenSql,
|
||||
seperator,
|
||||
actionInspectUserSchemas,
|
||||
actionInspectPgCatalog,
|
||||
actionInspectInformationSchema,
|
||||
seperator,
|
||||
actionClose
|
||||
actionNewSql,
|
||||
actionOpenSql,
|
||||
seperator(),
|
||||
actionSaveSql,
|
||||
actionSaveSqlAs,
|
||||
actionSaveCopyOfSqlAs,
|
||||
seperator(),
|
||||
actionInspectUserSchemas,
|
||||
actionInspectPgCatalog,
|
||||
actionInspectInformationSchema,
|
||||
seperator(),
|
||||
actionExportData,
|
||||
seperator(),
|
||||
actionClose
|
||||
});
|
||||
|
||||
menuEdit = mb->addMenu(tr("edit"));
|
||||
menuEdit->addActions({
|
||||
actionCopy,
|
||||
actionCopyAsCString,
|
||||
actionCopyAsRawCppString,
|
||||
actionGenerateCode
|
||||
});
|
||||
menuWindow = mb->addMenu(tr("Window"));
|
||||
menuWindow->addActions({
|
||||
actionShowConnectionManager
|
||||
});
|
||||
|
||||
|
||||
menuHelp = mb->addMenu(tr("Help"));
|
||||
menuHelp->addActions({
|
||||
seperator,
|
||||
actionAbout
|
||||
seperator(),
|
||||
actionAbout
|
||||
});
|
||||
|
||||
setMenuBar(mb);
|
||||
}
|
||||
|
||||
QAction *DatabaseWindow::seperator()
|
||||
{
|
||||
auto ac = new QAction(this);
|
||||
ac->setSeparator(true);
|
||||
return ac;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DatabaseWindow::catalogLoaded()
|
||||
{
|
||||
try {
|
||||
m_database = loadWatcher.future().result();
|
||||
|
||||
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(
|
||||
"Copyrights 2016-2019, Eelke Klein, All Rights Reserved.\n"
|
||||
"\n"
|
||||
"The program is provided AS IS with NO WARRANTY OF ANY KIND, "
|
||||
"INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
|
||||
"FOR A PARTICULAR PURPOSE.\n"
|
||||
"\n"
|
||||
"This program is dynamically linked with Qt 5.12 Copyright (C) 2018 "
|
||||
"The Qt Company Ltd. https://www.qt.io/licensing/. \n"
|
||||
"\n"
|
||||
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
||||
"attribution 3.0 license."
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionCopy_triggered()
|
||||
{
|
||||
QWidget *w = QApplication::focusWidget();
|
||||
QTableView *tv = dynamic_cast<QTableView*>(w);
|
||||
if (tv) {
|
||||
copySelectionToClipboard(tv);
|
||||
}
|
||||
else {
|
||||
const QMetaObject *meta = w->metaObject();
|
||||
int i = meta->indexOfSlot("copy");
|
||||
if (i != -1) {
|
||||
QMetaMethod method = meta->method(i);
|
||||
method.invoke(w, Qt::AutoConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionCopyAsCString_triggered()
|
||||
{
|
||||
auto query_tool = GetActiveQueryTool();
|
||||
if (query_tool) {
|
||||
query_tool->copyQueryAsCString();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionCopyAsRawCppString_triggered()
|
||||
{
|
||||
auto query_tool = GetActiveQueryTool();
|
||||
if (query_tool) {
|
||||
query_tool->copyQueryAsRawCppString();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionExportData_triggered()
|
||||
{
|
||||
auto query_tool = GetActiveQueryTool();
|
||||
if (query_tool) {
|
||||
query_tool->exportData();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionGenerateCode_triggered()
|
||||
{
|
||||
auto query_tool = GetActiveQueryTool();
|
||||
if (query_tool) {
|
||||
query_tool->generateCode();
|
||||
}
|
||||
}
|
||||
|
||||
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, "query");
|
||||
ct->newdoc();
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionInspectInformationSchema_triggered()
|
||||
{
|
||||
auto ct = new CatalogInspector(m_database, this);
|
||||
|
|
@ -228,6 +364,13 @@ void DatabaseWindow::on_actionInspectUserSchemas_triggered()
|
|||
ct->setNamespaceFilter(NamespaceFilter::User);
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionNewSql_triggered()
|
||||
{
|
||||
auto *ct = new QueryTool(m_database, this);
|
||||
addPage(ct, "query");
|
||||
ct->newdoc();
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionOpenSql_triggered()
|
||||
{
|
||||
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
|
||||
|
|
@ -235,69 +378,41 @@ void DatabaseWindow::on_actionOpenSql_triggered()
|
|||
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?
|
||||
if (ct->load(file_name)) {
|
||||
addPage(ct, "");
|
||||
}
|
||||
else {
|
||||
delete ct;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::catalogLoaded()
|
||||
void DatabaseWindow::on_actionSaveSql_triggered()
|
||||
{
|
||||
try {
|
||||
m_database = loadWatcher.future().result();
|
||||
|
||||
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();
|
||||
auto query_tool = GetActiveQueryTool();
|
||||
if (query_tool) {
|
||||
query_tool->save();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionAbout_triggered()
|
||||
void DatabaseWindow::on_actionSaveSqlAs_triggered()
|
||||
{
|
||||
QMessageBox::about(this, "pgLab 0.1", tr(
|
||||
"Copyrights 2016-2019, Eelke Klein, All Rights Reserved.\n"
|
||||
"\n"
|
||||
"The program is provided AS IS with NO WARRANTY OF ANY KIND, "
|
||||
"INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
|
||||
"FOR A PARTICULAR PURPOSE.\n"
|
||||
"\n"
|
||||
"This program is dynamically linked with Qt 5.12 Copyright (C) 2018 "
|
||||
"The Qt Company Ltd. https://www.qt.io/licensing/. \n"
|
||||
"\n"
|
||||
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
||||
"attribution 3.0 license."
|
||||
));
|
||||
|
||||
auto query_tool = GetActiveQueryTool();
|
||||
if (query_tool) {
|
||||
query_tool->saveAs();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionShow_connection_manager_triggered()
|
||||
void DatabaseWindow::on_actionSaveCopyOfSqlAs_triggered()
|
||||
{
|
||||
auto query_tool = GetActiveQueryTool();
|
||||
if (query_tool) {
|
||||
query_tool->saveCopyAs();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionShowConnectionManager_triggered()
|
||||
{
|
||||
m_masterController->showConnectionManager();
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionCopy_triggered()
|
||||
{
|
||||
// What should be copied?
|
||||
|
||||
QWidget *w = QApplication::focusWidget();
|
||||
QTableView *tv = dynamic_cast<QTableView*>(w);
|
||||
if (tv) {
|
||||
copySelectionToClipboard(tv);
|
||||
}
|
||||
else {
|
||||
const QMetaObject *meta = w->metaObject();
|
||||
int i = meta->indexOfSlot("copy");
|
||||
if (i != -1) {
|
||||
QMetaMethod method = meta->method(i);
|
||||
method.invoke(w, Qt::AutoConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue