Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,16 +424,16 @@ void MainWindow::init()

// Connect tool pragmas
connect(ui->actionIntegrityCheck, &QAction::triggered, [this]() {
runSqlNewTab("PRAGMA integrity_check;", ui->actionIntegrityCheck->text());
runSqlNewTab("PRAGMA integrity_check;", ui->actionIntegrityCheck->text(), "https://www.sqlite.org/pragma.html#pragma_integrity_check");
});
connect(ui->actionQuickCheck, &QAction::triggered, [this]() {
runSqlNewTab("PRAGMA quick_check;", ui->actionQuickCheck->text());
runSqlNewTab("PRAGMA quick_check;", ui->actionQuickCheck->text(), "https://www.sqlite.org/pragma.html#pragma_quick_check");
});
connect(ui->actionForeignKeyCheck, &QAction::triggered, [this]() {
runSqlNewTab("PRAGMA foreign_key_check;", ui->actionForeignKeyCheck->text());
runSqlNewTab("PRAGMA foreign_key_check;", ui->actionForeignKeyCheck->text(), "https://www.sqlite.org/pragma.html#pragma_foreign_key_check");
});
connect(ui->actionOptimize, &QAction::triggered, [this]() {
runSqlNewTab("PRAGMA optimize;", ui->actionOptimize->text());
runSqlNewTab("PRAGMA optimize;", ui->actionOptimize->text(), "https://www.sqlite.org/pragma.html#pragma_optimize");
});

// Action for switching the table via the Database Structure tab
Expand Down Expand Up @@ -902,6 +902,18 @@ void MainWindow::editObject()
EditIndexDialog dialog(db, name, false, this);
if(dialog.exec())
populateTable();
} else if(type == "view") {
sqlb::ViewPtr view = db.getObjectByName<sqlb::View>(name);
runSqlNewTab(QString("DROP VIEW %1;\n%2").arg(QString::fromStdString(name.toString())).arg(QString::fromStdString(view->sql())),
tr("Edit View %1").arg(QString::fromStdString(name.toDisplayString())),
"https://www.sqlite.org/lang_createview.html",
/* autoRun */ false);
} else if(type == "trigger") {
sqlb::TriggerPtr trigger = db.getObjectByName<sqlb::Trigger>(name);
runSqlNewTab(QString("DROP TRIGGER %1;\n%2").arg(QString::fromStdString(name.toString())).arg(QString::fromStdString(trigger->sql())),
tr("Edit Trigger %1").arg(QString::fromStdString(name.toDisplayString())),
"https://www.sqlite.org/lang_createtrigger.html",
/* autoRun */ false);
}
}

Expand Down Expand Up @@ -1502,13 +1514,9 @@ void MainWindow::changeTreeSelection()
ui->editModifyObjectAction->setVisible(true);

// Activate actions
if(type == "table" || type == "index")
{
ui->editDeleteObjectAction->setEnabled(!db.readOnly());
ui->editModifyObjectAction->setEnabled(!db.readOnly());
} else if(type == "view" || type == "trigger") {
ui->editDeleteObjectAction->setEnabled(!db.readOnly());
}
ui->editDeleteObjectAction->setEnabled(!db.readOnly());
ui->editModifyObjectAction->setEnabled(!db.readOnly());

if(type == "table" || type == "view")
{
ui->actionEditBrowseTable->setEnabled(true);
Expand Down Expand Up @@ -3110,11 +3118,18 @@ void MainWindow::saveAsView(const std::string& query)
QMessageBox::warning(this, qApp->applicationName(), tr("Error creating view: %1").arg(db.lastError()));
}

void MainWindow::runSqlNewTab(const QString& query, const QString& title)
void MainWindow::runSqlNewTab(const QString& query, const QString& title, const QString& helpUrl, const bool autoRun)
{
QString message = tr("This action will open a new SQL tab for running:") +
QString("<br/><tt>%1</tt><p/>").arg(query) +
tr("Press Help for opening the corresponding SQLite reference page.");
QString message;

if(autoRun)
message = tr("This action will open a new SQL tab for running:");
else
message = tr("This action will open a new SQL tab with the following statements for you to edit and run:");

message += QString("<blockquote><tt>%1</tt></blockquote>").arg(query) +
tr("Press Help for opening the corresponding SQLite reference page.");

QString windowTitle = title;
windowTitle.remove('&');

Expand All @@ -3127,13 +3142,12 @@ void MainWindow::runSqlNewTab(const QString& query, const QString& title)
int index = openSqlTab();
ui->tabSqlAreas->setTabText(index, title);
qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->widget(index))->getEditor()->setText(query);
executeQuery();
if(autoRun)
executeQuery();
break;
}
case QMessageBox::Help: {
QString anchor = query.toLower();
anchor.replace(" ", "_").chop(1);
QDesktopServices::openUrl(QUrl(QString("https://www.sqlite.org/pragma.html#") + anchor));
QDesktopServices::openUrl(QUrl(helpUrl));
break;
}
default:
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private slots:
void openFindReplaceDialog();
void toggleSqlBlockComment();
void openSqlPrintDialog();
void runSqlNewTab(const QString& query, const QString& title);
void runSqlNewTab(const QString& query, const QString& title, const QString& helpUrl, const bool autoRun = true);
void printDbStructure();
void updateDatabaseBusyStatus(bool busy, const QString& user);
void openPreferences();
Expand Down