DatabaseWindow has no knowledge more of the existence of QueryTab but user can still create and use them within that window.

This commit is contained in:
eelke 2019-01-05 11:12:47 +01:00
parent fd603a7434
commit d0c4dabe8b
8 changed files with 327 additions and 451 deletions

View file

@ -627,23 +627,15 @@ std::vector<QAction*> QueryTab::getToolbarActions()
{
if (actions.empty()) {
QAction *action;
// New
// action = new QAction(QIcon(":/icons/new_query_tab.png"), tr("New"), this);
// action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
// connect(action, &QAction::triggered, this, &QueryTab::);
// actions.push_back(action);
// Load
// Save
action = new QAction(QIcon(":/icons/script_save.png"), tr("Save SQL"), this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
connect(action, &QAction::triggered, this, &QueryTab::save);
actions.push_back(action);
// Save as (menu only)
// action = new QAction(QIcon(":/icons/script_save.png"), tr("Save SQL as"), this);
// //action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
// connect(action, &QAction::triggered, this, &QueryTab::saveAs);
// actions.push_back(action);
action = new QAction(QIcon(":/icons/script_save.png"), tr("Save SQL as"), this);
connect(action, &QAction::triggered, this, &QueryTab::saveAs);
actions.push_back(action);
// Save copy as
// Copy
// Copy as C-string
@ -677,12 +669,21 @@ std::vector<QAction*> QueryTab::getToolbarActions()
void QueryToolModule::init()
{
MenuAction ma_new("New", [this] (IPluginContentWidgetContext* context)
{ menuAction_new(context); });
ma_new.setMenuLocation(MenuPath("File/New"));
ma_new.setIcon(QIcon(":/icons/new_query_tab.png"));
ma_new.setShortCut(QKeySequence(Qt::CTRL + Qt::Key_N));
registerMenuAction(ma_new);
{
MenuAction ma("New SQL", [this] (IPluginContentWidgetContext* context)
{ menuAction_new(context); });
ma.setMenuLocation(MenuPath("File/New"));
ma.setIcon(QIcon(":/icons/new_query_tab.png"));
ma.setShortCut(QKeySequence(Qt::CTRL + Qt::Key_N));
registerMenuAction(ma);
}
{
MenuAction ma("Open SQL", [this] (IPluginContentWidgetContext* context)
{ menuAction_open(context); });
ma.setMenuLocation(MenuPath("File/Open"));
ma.setIcon(QIcon(":/icons/folder.png"));
registerMenuAction(ma);
}
}
void QueryToolModule::menuAction_new(IPluginContentWidgetContext* context)
@ -692,4 +693,16 @@ void QueryToolModule::menuAction_new(IPluginContentWidgetContext* context)
ct->newdoc();
}
void QueryToolModule::menuAction_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 QueryTab(context, nullptr);
context->addContentWidget(ct);
ct->load(file_name);
}
}
REGISTER_PLUGIN_MODULE(QueryToolModule, "Query tool", "pglab.querytool")