2019-01-05 19:58:23 +01:00
|
|
|
|
#include "QueryToolModule.h"
|
|
|
|
|
|
#include "QueryTool.h"
|
|
|
|
|
|
#include "plugin_support/IPluginContentWidgetContext.h"
|
|
|
|
|
|
#include "plugin_support/PluginRegister.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
|
|
|
|
|
|
void QueryToolModule::init()
|
|
|
|
|
|
{
|
|
|
|
|
|
std::string slot_name = SLOT(QueryTool::execute());
|
|
|
|
|
|
{
|
2019-01-31 19:31:17 +01:00
|
|
|
|
StaticAction ma("New SQL", [this] (IPluginContentWidgetContext* context)
|
2019-02-08 10:10:11 +01:00
|
|
|
|
{ staticAction_new(context); });
|
2019-01-05 19:58:23 +01:00
|
|
|
|
ma.setMenuLocation(MenuPath("File/New"));
|
2019-01-31 19:25:54 +01:00
|
|
|
|
ma.setToolbarLocation(ToolbarLocation("main", "new"));
|
2019-01-05 19:58:23 +01:00
|
|
|
|
ma.setIcon(QIcon(":/icons/new_query_tab.png"));
|
|
|
|
|
|
ma.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
|
2019-01-31 19:31:17 +01:00
|
|
|
|
registerStaticAction(ma);
|
2019-01-05 19:58:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
{
|
2019-01-31 19:31:17 +01:00
|
|
|
|
StaticAction ma("Open SQL", [this] (IPluginContentWidgetContext* context)
|
2019-02-08 10:10:11 +01:00
|
|
|
|
{ staticAction_open(context); });
|
2019-01-05 19:58:23 +01:00
|
|
|
|
ma.setMenuLocation(MenuPath("File/Open"));
|
2019-01-31 19:25:54 +01:00
|
|
|
|
ma.setToolbarLocation(ToolbarLocation("main", "open"));
|
2019-01-05 19:58:23 +01:00
|
|
|
|
ma.setIcon(QIcon(":/icons/folder.png"));
|
2019-01-31 19:31:17 +01:00
|
|
|
|
registerStaticAction(ma);
|
2019-01-05 19:58:23 +01:00
|
|
|
|
}
|
2019-08-14 09:06:48 +02:00
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
2019-01-05 19:58:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-08 10:10:11 +01:00
|
|
|
|
void QueryToolModule::staticAction_new(IPluginContentWidgetContext* context)
|
2019-01-05 19:58:23 +01:00
|
|
|
|
{
|
2019-08-14 09:06:48 +02:00
|
|
|
|
auto *ct = new QueryTool(context, this);
|
|
|
|
|
|
|
|
|
|
|
|
// Should we let constructor of PluginContentWidget do this?
|
|
|
|
|
|
// Saves a line but what if we don't want it.
|
|
|
|
|
|
context->addContentWidget(ct);
|
|
|
|
|
|
|
|
|
|
|
|
// should content widget now to which module it belongs?
|
|
|
|
|
|
// That way the context would not need to keep track of this.
|
|
|
|
|
|
|
2019-01-05 19:58:23 +01:00
|
|
|
|
ct->newdoc();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-08 10:10:11 +01:00
|
|
|
|
void QueryToolModule::staticAction_open(IPluginContentWidgetContext* context)
|
2019-01-05 19:58:23 +01:00
|
|
|
|
{
|
|
|
|
|
|
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
|
|
|
|
|
|
QString file_name = QFileDialog::getOpenFileName(context->container(),
|
|
|
|
|
|
tr("Open sql query"), home_dir, tr("SQL files (*.sql *.txt)"));
|
|
|
|
|
|
if ( ! file_name.isEmpty()) {
|
2019-08-14 09:06:48 +02:00
|
|
|
|
auto *ct = new QueryTool(context, this);
|
|
|
|
|
|
context->addContentWidget(ct);
|
|
|
|
|
|
if (!ct->load(file_name)) {
|
|
|
|
|
|
// TODO load has failed remove widget or never add it?
|
|
|
|
|
|
}
|
2019-01-05 19:58:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-06 10:11:48 +01:00
|
|
|
|
REGISTER_PLUGIN_MODULE_CAT(QueryToolModule, "Query tool", "pglab.querytool", "database")
|