From 8323f2a1b6ce73126e42c772e5798a405ca4b98a Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sat, 15 Aug 2020 17:25:53 +0200 Subject: [PATCH] Add 'Don't ask again' button to collation message box This adds a button called 'Yes. Don't ask again' to the collation message box which asks you to confirm adding a default collation when your database needs a custom collation. See issue #2356. --- src/MainWindow.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index bc73ee3f..4e0ab1d3 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -3089,17 +3089,34 @@ void MainWindow::fileOpenReadOnly() void MainWindow::requestCollation(const QString& name, int eTextRep) { - QMessageBox::StandardButton reply = QMessageBox::question( - this, - tr("Collation needed! Proceed?"), - tr("A table in this database requires a special collation function '%1' " - "that this application can't provide without further knowledge.\n" - "If you choose to proceed, be aware bad things can happen to your database.\n" - "Create a backup!").arg(name), QMessageBox::Yes | QMessageBox::No); - if(reply == QMessageBox::Yes) { - auto pDb = db.get(tr("creating collation")); - sqlite3_create_collation(pDb.get(), name.toUtf8(), eTextRep, nullptr, collCompare); + // Show message box + if(!Settings::getValue("db", "dont_ask_collation").toBool()) + { + QMessageBox msgbox; + QPushButton* button_dont_ask_again = msgbox.addButton(tr("Yes. Don't ask again"), QMessageBox::ActionRole); + msgbox.addButton(QMessageBox::Yes); + msgbox.addButton(QMessageBox::No); + msgbox.setTextFormat(Qt::RichText); + msgbox.setWindowTitle(tr("Collation needed! Proceed?")); + msgbox.setText(tr("A table in this database requires a special collation function '%1' " + "that this application can't provide without further knowledge.\n" + "If you choose to proceed, be aware bad things can happen to your database.\n" + "Create a backup!").arg(name)); + int reply = msgbox.exec(); + + // Remember Don't ask again setting and proceed if either that button or the Yes button was clicked. + // Cancel here if the No button was clicked + if(msgbox.clickedButton() == button_dont_ask_again) + { + Settings::setValue("db", "dont_ask_collation", true); + } else if(reply == QMessageBox::No) { + return; + } } + + // Add collation + auto pDb = db.get(tr("creating collation")); + sqlite3_create_collation(pDb.get(), name.toUtf8(), eTextRep, nullptr, collCompare); } void MainWindow::renameSqlTab(int index)