From b99edacc9febc324ee361b3e2fc70a6bc1cf43af Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sat, 6 Jan 2018 21:53:15 +0100 Subject: [PATCH] Automatic completion of SQL keywords in upper case Added a new setting for completing the SQL keywords in upper case (default being true). Scintilla setAutoCompletionCaseSensitivity is set to false. Otherwise the completion is only done in lowercase when both case versions are added, or if only upper case version is added, writing lower case letters does not use the upper case version of the word in the completion list. This change doesn't have apparently any downside, since SQL is actually case insensitive. Consequently the list of keywords is only added in one of the two letter case versions, depending on the new setting value. The new preference check-box is only enabled when the auto-complete check-box is checked. See issues #1238 and #1287. --- src/ExtendedScintilla.cpp | 2 +- src/PreferencesDialog.cpp | 3 + src/PreferencesDialog.ui | 116 +++++++++++++++++++++++++------------- src/Settings.cpp | 4 ++ src/SqlUiLexer.cpp | 8 ++- 5 files changed, 90 insertions(+), 43 deletions(-) diff --git a/src/ExtendedScintilla.cpp b/src/ExtendedScintilla.cpp index 5e9e3aa1..266bddaf 100644 --- a/src/ExtendedScintilla.cpp +++ b/src/ExtendedScintilla.cpp @@ -111,7 +111,7 @@ void ExtendedScintilla::reloadSettings() if(Settings::getValue("editor", "auto_completion").toBool()) { setAutoCompletionThreshold(3); - setAutoCompletionCaseSensitivity(true); + setAutoCompletionCaseSensitivity(false); setAutoCompletionShowSingle(true); setAutoCompletionSource(QsciScintilla::AcsAPIs); } else { diff --git a/src/PreferencesDialog.cpp b/src/PreferencesDialog.cpp index a80edacf..003fcf03 100644 --- a/src/PreferencesDialog.cpp +++ b/src/PreferencesDialog.cpp @@ -166,6 +166,8 @@ void PreferencesDialog::loadSettings() ui->spinTabSize->setValue(Settings::getValue("editor", "tabsize").toInt()); ui->spinLogFontSize->setValue(Settings::getValue("log", "fontsize").toInt()); ui->checkAutoCompletion->setChecked(Settings::getValue("editor", "auto_completion").toBool()); + ui->checkCompleteUpper->setEnabled(Settings::getValue("editor", "auto_completion").toBool()); + ui->checkCompleteUpper->setChecked(Settings::getValue("editor", "upper_keywords").toBool()); ui->checkErrorIndicators->setChecked(Settings::getValue("editor", "error_indicators").toBool()); ui->checkHorizontalTiling->setChecked(Settings::getValue("editor", "horizontal_tiling").toBool()); @@ -216,6 +218,7 @@ void PreferencesDialog::saveSettings() Settings::setValue("editor", "tabsize", ui->spinTabSize->value()); Settings::setValue("log", "fontsize", ui->spinLogFontSize->value()); Settings::setValue("editor", "auto_completion", ui->checkAutoCompletion->isChecked()); + Settings::setValue("editor", "upper_keywords", ui->checkCompleteUpper->isChecked()); Settings::setValue("editor", "error_indicators", ui->checkErrorIndicators->isChecked()); Settings::setValue("editor", "horizontal_tiling", ui->checkHorizontalTiling->isChecked()); diff --git a/src/PreferencesDialog.ui b/src/PreferencesDialog.ui index bb2519f6..8f9f7736 100644 --- a/src/PreferencesDialog.ui +++ b/src/PreferencesDialog.ui @@ -960,46 +960,6 @@ - - - - Error indicators - - - checkErrorIndicators - - - - - - - When set, the SQL code lines that caused errors during the last execution are highlighted and the results frame indicates the error in the background - - - enabled - - - - - - - Hori&zontal tiling - - - checkHorizontalTiling - - - - - - - If enabled the SQL code editor and the result table view are shown side by side instead of one over the other. - - - enabled - - - @@ -1017,6 +977,66 @@ + + + + Keywords in &UPPER CASE + + + checkCompleteUpper + + + + + + + When set, the SQL keywords are completed in UPPER CASE letters. + + + enabled + + + + + + + Error indicators + + + checkErrorIndicators + + + + + + + When set, the SQL code lines that caused errors during the last execution are highlighted and the results frame indicates the error in the background + + + enabled + + + + + + + Hori&zontal tiling + + + checkHorizontalTiling + + + + + + + If enabled the SQL code editor and the result table view are shown side by side instead of one over the other. + + + enabled + + + @@ -1573,6 +1593,22 @@ + + checkAutoCompletion + toggled(bool) + checkCompleteUpper + setEnabled(bool) + + + 474 + 464 + + + 474 + 492 + + + saveSettings() diff --git a/src/Settings.cpp b/src/Settings.cpp index 6d6efbaa..dd8c4c88 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -260,6 +260,10 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name) if(group == "editor" && name == "auto_completion") return true; + // editor/upper_keywords? + if(group == "editor" && name == "upper_keywords") + return true; + // editor/error_indicators? if(group == "editor" && name == "error_indicators") return true; diff --git a/src/SqlUiLexer.cpp b/src/SqlUiLexer.cpp index 9e7fc6c9..c0884540 100644 --- a/src/SqlUiLexer.cpp +++ b/src/SqlUiLexer.cpp @@ -1,5 +1,6 @@ #include "SqlUiLexer.h" #include "Qsci/qsciapis.h" +#include "Settings.h" SqlUiLexer::SqlUiLexer(QObject* parent) : QsciLexerSQL(parent) @@ -47,10 +48,13 @@ void SqlUiLexer::setupAutoCompletion() << "WHERE" << "WITH" << "WITHOUT" // Data types << "INT" << "INTEGER" << "REAL" << "TEXT" << "BLOB" << "NUMERIC" << "CHAR"; + bool upperKeywords = Settings::getValue("editor", "upper_keywords").toBool(); for(const QString& keyword : keywordPatterns) { - autocompleteApi->add(keyword + "?" + QString::number(ApiCompleterIconIdKeyword)); - autocompleteApi->add(keyword.toLower() + "?" + QString::number(ApiCompleterIconIdKeyword)); + if (upperKeywords) + autocompleteApi->add(keyword + "?" + QString::number(ApiCompleterIconIdKeyword)); + else + autocompleteApi->add(keyword.toLower() + "?" + QString::number(ApiCompleterIconIdKeyword)); } // Functions