diff options
| author | 2023-04-30 18:30:36 -0400 | |
|---|---|---|
| committer | 2023-04-30 18:30:36 -0400 | |
| commit | 3565aad630864ecdbe53fdaa501ea708555b3c7c (patch) | |
| tree | c743e4ad0bad39ebdb2f514c7cc52d34a257ebbe /SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp | |
| parent | 1fdc150116cad39aae5c5da407c3312b47a59e3a (diff) | |
New upstream version 3.4.4+dfsg.upstream/3.4.4+dfsg
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp index 3ac32ac..4d964c8 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp @@ -8,10 +8,8 @@ #include "services/pluginmanager.h" #include "dbtree/dbtree.h" #include "dbtree/dbtreemodel.h" -#include "dbtree/dbtreeitem.h" #include "iconmanager.h" #include "syntaxhighlighterplugin.h" -#include "sqlitesyntaxhighlighter.h" #include "plugins/scriptingplugin.h" #include "common/userinputfilter.h" #include "selectabledbmodel.h" @@ -19,9 +17,12 @@ #include <QDebug> #include <QDesktopServices> #include <QStyleFactory> +#include <QSyntaxHighlighter> // TODO handle plugin loading/unloading to update editor state +CFG_KEYS_DEFINE(FunctionsEditor) + FunctionsEditor::FunctionsEditor(QWidget *parent) : MdiChild(parent), ui(new Ui::FunctionsEditor) @@ -52,26 +53,26 @@ Icon* FunctionsEditor::getIconNameForMdiWindow() QString FunctionsEditor::getTitleForMdiWindow() { - return tr("SQL function editor"); + return tr("SQL functions editor"); } void FunctionsEditor::createActions() { - createAction(COMMIT, ICONS.COMMIT, tr("Commit all function changes"), this, SLOT(commit()), ui->toolBar); - createAction(ROLLBACK, ICONS.ROLLBACK, tr("Rollback all function changes"), this, SLOT(rollback()), ui->toolBar); + createAction(COMMIT, ICONS.COMMIT, tr("Commit all function changes"), this, SLOT(commit()), ui->toolBar, this); + createAction(ROLLBACK, ICONS.ROLLBACK, tr("Rollback all function changes"), this, SLOT(rollback()), ui->toolBar, this); ui->toolBar->addSeparator(); - createAction(ADD, ICONS.NEW_FUNCTION, tr("Create new function"), this, SLOT(newFunction()), ui->toolBar); - createAction(DELETE, ICONS.DELETE_FUNCTION, tr("Delete selected function"), this, SLOT(deleteFunction()), ui->toolBar); + createAction(ADD, ICONS.NEW_FUNCTION, tr("Create new function"), this, SLOT(newFunction()), ui->toolBar, this); + createAction(DELETE, ICONS.DELETE_FUNCTION, tr("Delete selected function"), this, SLOT(deleteFunction()), ui->toolBar, this); ui->toolBar->addSeparator(); - createAction(HELP, ICONS.HELP, tr("Custom SQL functions manual"), this, SLOT(help()), ui->toolBar); + createAction(HELP, ICONS.HELP, tr("Custom SQL functions manual"), this, SLOT(help()), ui->toolBar, this); // Args toolbar - createAction(ARG_ADD, ICONS.INSERT_FN_ARG, tr("Add function argument"), this, SLOT(addFunctionArg()), ui->argsToolBar); - createAction(ARG_EDIT, ICONS.RENAME_FN_ARG, tr("Rename function argument"), this, SLOT(editFunctionArg()), ui->argsToolBar); - createAction(ARG_DEL, ICONS.DELETE_FN_ARG, tr("Delete function argument"), this, SLOT(delFunctionArg()), ui->argsToolBar); + createAction(ARG_ADD, ICONS.INSERT_FN_ARG, tr("Add function argument"), this, SLOT(addFunctionArg()), ui->argsToolBar, this); + createAction(ARG_EDIT, ICONS.RENAME_FN_ARG, tr("Rename function argument"), this, SLOT(editFunctionArg()), ui->argsToolBar, this); + createAction(ARG_DEL, ICONS.DELETE_FN_ARG, tr("Delete function argument"), this, SLOT(delFunctionArg()), ui->argsToolBar, this); ui->argsToolBar->addSeparator(); - createAction(ARG_MOVE_UP, ICONS.MOVE_UP, tr("Move function argument up"), this, SLOT(moveFunctionArgUp()), ui->argsToolBar); - createAction(ARG_MOVE_DOWN, ICONS.MOVE_DOWN, tr("Move function argument down"), this, SLOT(moveFunctionArgDown()), ui->argsToolBar); + createAction(ARG_MOVE_UP, ICONS.MOVE_UP, tr("Move function argument up"), this, SLOT(moveFunctionArgUp()), ui->argsToolBar, this); + createAction(ARG_MOVE_DOWN, ICONS.MOVE_DOWN, tr("Move function argument down"), this, SLOT(moveFunctionArgDown()), ui->argsToolBar, this); #ifdef Q_OS_MACX QStyle *fusion = QStyleFactory::create("Fusion"); @@ -82,6 +83,9 @@ void FunctionsEditor::createActions() void FunctionsEditor::setupDefShortcuts() { + // Widget context + setShortcutContext({COMMIT, ROLLBACK}, Qt::WidgetWithChildrenShortcut); + BIND_SHORTCUTS(FunctionsEditor, Action); } QToolBar* FunctionsEditor::getToolBar(int toolbar) const @@ -123,11 +127,12 @@ void FunctionsEditor::init() connect(ui->mainCodeEdit, SIGNAL(textChanged()), this, SLOT(updateModified())); connect(ui->finalCodeEdit, SIGNAL(textChanged()), this, SLOT(updateModified())); connect(ui->nameEdit, SIGNAL(textChanged(QString)), this, SLOT(updateModified())); - connect(ui->undefArgsCheck, SIGNAL(clicked()), this, SLOT(updateModified())); + connect(ui->undefArgsCheck, SIGNAL(toggled(bool)), this, SLOT(updateModified())); connect(ui->allDatabasesRadio, SIGNAL(clicked()), this, SLOT(updateModified())); connect(ui->selDatabasesRadio, SIGNAL(clicked()), this, SLOT(updateModified())); connect(ui->langCombo, SIGNAL(currentTextChanged(QString)), this, SLOT(updateModified())); connect(ui->typeCombo, SIGNAL(currentTextChanged(QString)), this, SLOT(updateModified())); + connect(ui->deterministicCheck, SIGNAL(toggled(bool)), this, SLOT(updateModified())); connect(ui->argsList->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateArgsState())); connect(ui->argsList->model(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(updateModified())); @@ -141,13 +146,13 @@ void FunctionsEditor::init() model->setData(FUNCTIONS->getAllScriptFunctions()); // Language plugins - for (ScriptingPlugin* plugin : PLUGINS->getLoadedPlugins<ScriptingPlugin>()) + for (ScriptingPlugin*& plugin : PLUGINS->getLoadedPlugins<ScriptingPlugin>()) scriptingPlugins[plugin->getLanguage()] = plugin; ui->langCombo->addItems(scriptingPlugins.keys()); // Syntax highlighting plugins - for (SyntaxHighlighterPlugin* plugin : PLUGINS->getLoadedPlugins<SyntaxHighlighterPlugin>()) + for (SyntaxHighlighterPlugin*& plugin : PLUGINS->getLoadedPlugins<SyntaxHighlighterPlugin>()) highlighterPlugins[plugin->getLanguageName()] = plugin; updateState(); @@ -170,6 +175,7 @@ void FunctionsEditor::functionDeselected(int row) model->setUndefinedArgs(row, ui->undefArgsCheck->isChecked()); model->setAllDatabases(row, ui->allDatabasesRadio->isChecked()); model->setCode(row, ui->mainCodeEdit->toPlainText()); + model->setDeterministic(row, ui->deterministicCheck->isChecked()); model->setModified(row, currentModified); if (model->isAggregate(row)) @@ -201,6 +207,7 @@ void FunctionsEditor::functionSelected(int row) ui->finalCodeEdit->setPlainText(model->getFinalCode(row)); ui->undefArgsCheck->setChecked(model->getUndefinedArgs(row)); ui->langCombo->setCurrentText(model->getLang(row)); + ui->deterministicCheck->setChecked(model->isDeterministic(row)); // Arguments ui->argsList->clear(); @@ -248,6 +255,7 @@ void FunctionsEditor::clearEdits() ui->allDatabasesRadio->setChecked(true); ui->typeCombo->setCurrentIndex(0); ui->langCombo->setCurrentIndex(-1); + ui->deterministicCheck->setChecked(false); } void FunctionsEditor::selectFunction(int row) @@ -374,9 +382,10 @@ void FunctionsEditor::updateModified() bool argDiff = getCurrentArgList() != model->getArguments(row); bool dbDiff = toSet(getCurrentDatabases()) != toSet(model->getDatabases(row)); // QSet to ignore order bool typeDiff = model->getType(row) != getCurrentFunctionType(); + bool deterministicDiff = model->isDeterministic(row) != ui->deterministicCheck->isChecked(); currentModified = (nameDiff || codeDiff || typeDiff || langDiff || undefArgsDiff || allDatabasesDiff || argDiff || dbDiff || - initCodeDiff || finalCodeDiff); + initCodeDiff || finalCodeDiff || deterministicDiff); } updateCurrentFunctionState(); @@ -415,6 +424,7 @@ void FunctionsEditor::updateCurrentFunctionState() ui->mainCodeGroup->setEnabled(langOk); ui->finalCodeGroup->setEnabled(langOk); ui->argsGroup->setEnabled(langOk); + ui->deterministicCheck->setEnabled(langOk); ui->databasesGroup->setEnabled(langOk); ui->nameEdit->setEnabled(langOk); ui->nameLabel->setEnabled(langOk); @@ -624,7 +634,7 @@ QVariant FunctionsEditor::saveSession() bool FunctionsEditor::isUncommitted() const { - return model->isModified(); + return model->isModified() || currentModified; } QString FunctionsEditor::getQuitUncommittedConfirmMessage() const |
