#include "QueryToolModule.h" #include "QueryTool.h" #include "plugin_support/IPluginContentWidgetContext.h" #include "plugin_support/PluginRegister.h" #include #include void QueryToolModule::init() { std::string slot_name = SLOT(QueryTool::execute()); { StaticAction ma("New SQL", [this] (IPluginContentWidgetContext* context) { staticAction_new(context); }); ma.setMenuLocation(MenuPath("File/New")); ma.setToolbarLocation(ToolbarLocation("main", "new")); ma.setIcon(QIcon(":/icons/new_query_tab.png")); ma.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); registerStaticAction(ma); } { StaticAction ma("Open SQL", [this] (IPluginContentWidgetContext* context) { staticAction_open(context); }); ma.setMenuLocation(MenuPath("File/Open")); ma.setToolbarLocation(ToolbarLocation("main", "open")); ma.setIcon(QIcon(":/icons/folder.png")); registerStaticAction(ma); } { auto ca = makeContextAction(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(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(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 QueryToolModule::staticAction_new(IPluginContentWidgetContext* context) { 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. ct->newdoc(); } void QueryToolModule::staticAction_open(IPluginContentWidgetContext* context) { 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()) { auto *ct = new QueryTool(context, this); context->addContentWidget(ct); if (!ct->load(file_name)) { // TODO load has failed remove widget or never add it? } } } REGISTER_PLUGIN_MODULE_CAT(QueryToolModule, "Query tool", "pglab.querytool", "database")