pgLab/pglab/QueryToolModule.cpp
eelke a704332342 Work on plugin mechanism
Context actions have become normal actions in the pluginwidget so the widget knows abot them and
can easily do things like enable/disable.
2019-02-08 10:10:11 +01:00

50 lines
1.6 KiB
C++

#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());
{
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);
}
}
void QueryToolModule::staticAction_new(IPluginContentWidgetContext* context)
{
auto *ct = new QueryTool(context, nullptr);
context->addContentWidget(this, ct);
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, nullptr);
context->addContentWidget(this, ct);
ct->load(file_name);
}
}
REGISTER_PLUGIN_MODULE_CAT(QueryToolModule, "Query tool", "pglab.querytool", "database")