Commit 3f1b45b0 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Implemented first-letter case-sensitive for completion as default



By default now only the first letter is case-sensitive. It is still
possible to choose full or no case-sensitivity as well.

Task-number: QTCREATORBUG-236
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent 33bdf429
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
**************************************************************************/ **************************************************************************/
#include "completionsettingspage.h" #include "completionsettingspage.h"
#include "cppcodecompletion.h"
#include "ui_completionsettingspage.h" #include "ui_completionsettingspage.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
...@@ -63,7 +62,6 @@ QString CompletionSettingsPage::trName() const ...@@ -63,7 +62,6 @@ QString CompletionSettingsPage::trName() const
QString CompletionSettingsPage::category() const QString CompletionSettingsPage::category() const
{ {
return QLatin1String(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY); return QLatin1String(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY);
} }
...@@ -77,11 +75,24 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent) ...@@ -77,11 +75,24 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
QWidget *w = new QWidget(parent); QWidget *w = new QWidget(parent);
m_page->setupUi(w); m_page->setupUi(w);
m_page->caseSensitive->setChecked(m_completion->caseSensitivity() == Qt::CaseSensitive); int caseSensitivityIndex;
switch (m_completion->caseSensitivity()) {
case CppCodeCompletion::CaseSensitive:
caseSensitivityIndex = 0;
break;
case CppCodeCompletion::CaseInsensitive:
caseSensitivityIndex = 1;
break;
case CppCodeCompletion::FirstLetterCaseSensitive:
caseSensitivityIndex = 2;
break;
}
m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex);
m_page->autoInsertBrackets->setChecked(m_completion->autoInsertBrackets()); m_page->autoInsertBrackets->setChecked(m_completion->autoInsertBrackets());
m_page->partiallyComplete->setChecked(m_completion->isPartialCompletionEnabled()); m_page->partiallyComplete->setChecked(m_completion->isPartialCompletionEnabled());
if (m_searchKeywords.isEmpty()) { if (m_searchKeywords.isEmpty()) {
QTextStream(&m_searchKeywords) << m_page->caseSensitive->text() QTextStream(&m_searchKeywords) << m_page->caseSensitivityLabel->text()
<< ' ' << m_page->autoInsertBrackets->text() << ' ' << m_page->autoInsertBrackets->text()
<< ' ' << m_page->partiallyComplete->text(); << ' ' << m_page->partiallyComplete->text();
m_searchKeywords.remove(QLatin1Char('&')); m_searchKeywords.remove(QLatin1Char('&'));
...@@ -91,8 +102,7 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent) ...@@ -91,8 +102,7 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
void CompletionSettingsPage::apply() void CompletionSettingsPage::apply()
{ {
m_completion->setCaseSensitivity( m_completion->setCaseSensitivity(caseSensitivity());
m_page->caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);
m_completion->setAutoInsertBrackets(m_page->autoInsertBrackets->isChecked()); m_completion->setAutoInsertBrackets(m_page->autoInsertBrackets->isChecked());
m_completion->setPartialCompletionEnabled(m_page->partiallyComplete->isChecked()); m_completion->setPartialCompletionEnabled(m_page->partiallyComplete->isChecked());
} }
...@@ -101,3 +111,15 @@ bool CompletionSettingsPage::matches(const QString &s) const ...@@ -101,3 +111,15 @@ bool CompletionSettingsPage::matches(const QString &s) const
{ {
return m_searchKeywords.contains(s, Qt::CaseInsensitive); return m_searchKeywords.contains(s, Qt::CaseInsensitive);
} }
CppCodeCompletion::CaseSensitivity CompletionSettingsPage::caseSensitivity() const
{
switch (m_page->caseSensitivity->currentIndex()) {
case 0: // Full
return CppCodeCompletion::CaseSensitive;
case 1: // None
return CppCodeCompletion::CaseInsensitive;
default: // First letter
return CppCodeCompletion::FirstLetterCaseSensitive;
}
}
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include "cppcodecompletion.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class Ui_CompletionSettingsPage; class Ui_CompletionSettingsPage;
QT_END_NAMESPACE QT_END_NAMESPACE
...@@ -39,8 +41,6 @@ QT_END_NAMESPACE ...@@ -39,8 +41,6 @@ QT_END_NAMESPACE
namespace CppTools { namespace CppTools {
namespace Internal { namespace Internal {
class CppCodeCompletion;
class CompletionSettingsPage : public Core::IOptionsPage class CompletionSettingsPage : public Core::IOptionsPage
{ {
Q_OBJECT Q_OBJECT
...@@ -60,6 +60,8 @@ public: ...@@ -60,6 +60,8 @@ public:
virtual bool matches(const QString &) const; virtual bool matches(const QString &) const;
private: private:
CppCodeCompletion::CaseSensitivity caseSensitivity() const;
CppCodeCompletion *m_completion; CppCodeCompletion *m_completion;
Ui_CompletionSettingsPage *m_page; Ui_CompletionSettingsPage *m_page;
QString m_searchKeywords; QString m_searchKeywords;
......
...@@ -13,19 +13,77 @@ ...@@ -13,19 +13,77 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Behavior</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QCheckBox" name="caseSensitive"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="toolTip"> <item>
<string>Do a case-sensitive match for completion items.</string> <widget class="QLabel" name="caseSensitivityLabel">
</property> <property name="text">
<property name="text"> <string>&amp;Case-sensitivity:</string>
<string>&amp;Case-sensitive completion</string> </property>
</property> <property name="buddy">
<property name="checked"> <cstring>caseSensitivity</cstring>
<bool>true</bool> </property>
</property> </widget>
</widget> </item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="caseSensitivity">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Full</string>
</property>
</item>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>First letter</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="autoInsertBrackets"> <widget class="QCheckBox" name="autoInsertBrackets">
......
...@@ -476,7 +476,7 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager) ...@@ -476,7 +476,7 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager)
m_manager(manager), m_manager(manager),
m_editor(0), m_editor(0),
m_startPosition(-1), m_startPosition(-1),
m_caseSensitivity(Qt::CaseSensitive), m_caseSensitivity(FirstLetterCaseSensitive),
m_autoInsertBrackets(true), m_autoInsertBrackets(true),
m_partialCompletionEnabled(true), m_partialCompletionEnabled(true),
m_forcedCompletion(false), m_forcedCompletion(false),
...@@ -490,12 +490,12 @@ QIcon CppCodeCompletion::iconForSymbol(Symbol *symbol) const ...@@ -490,12 +490,12 @@ QIcon CppCodeCompletion::iconForSymbol(Symbol *symbol) const
return m_icons.iconForSymbol(symbol); return m_icons.iconForSymbol(symbol);
} }
Qt::CaseSensitivity CppCodeCompletion::caseSensitivity() const CppCodeCompletion::CaseSensitivity CppCodeCompletion::caseSensitivity() const
{ {
return m_caseSensitivity; return m_caseSensitivity;
} }
void CppCodeCompletion::setCaseSensitivity(Qt::CaseSensitivity caseSensitivity) void CppCodeCompletion::setCaseSensitivity(CaseSensitivity caseSensitivity)
{ {
m_caseSensitivity = caseSensitivity; m_caseSensitivity = caseSensitivity;
} }
...@@ -1438,20 +1438,29 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio ...@@ -1438,20 +1438,29 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
* *
* Meaning it allows any sequence of lower-case characters to preceed an * Meaning it allows any sequence of lower-case characters to preceed an
* upper-case character. So for example gAC matches getActionController. * upper-case character. So for example gAC matches getActionController.
*
* It also implements the first-letter-only case sensitivity.
*/ */
QString keyRegExp; QString keyRegExp;
keyRegExp += QLatin1Char('^'); keyRegExp += QLatin1Char('^');
bool first = true; bool first = true;
foreach (const QChar &c, key) { foreach (const QChar &c, key) {
if (c.isUpper() && !first) { if (c.isUpper() && !first)
keyRegExp += QLatin1String("[a-z0-9_]*"); keyRegExp += QLatin1String("[a-z0-9_]*");
keyRegExp += c;
if (m_caseSensitivity == FirstLetterCaseSensitive && !first) {
keyRegExp += QLatin1Char('[');
keyRegExp += QRegExp::escape(c.toLower());
keyRegExp += QRegExp::escape(c.toUpper());
keyRegExp += QLatin1Char(']');
} else { } else {
keyRegExp += QRegExp::escape(c); keyRegExp += QRegExp::escape(c);
} }
first = false; first = false;
} }
const QRegExp regExp(keyRegExp, m_caseSensitivity); const QRegExp regExp(keyRegExp, (m_caseSensitivity == CaseInsensitive)
? Qt::CaseInsensitive : Qt::CaseSensitive);
foreach (TextEditor::CompletionItem item, m_completions) { foreach (TextEditor::CompletionItem item, m_completions) {
if (regExp.indexIn(item.text) == 0) { if (regExp.indexIn(item.text) == 0) {
......
...@@ -76,8 +76,14 @@ public: ...@@ -76,8 +76,14 @@ public:
QIcon iconForSymbol(CPlusPlus::Symbol *symbol) const; QIcon iconForSymbol(CPlusPlus::Symbol *symbol) const;
Qt::CaseSensitivity caseSensitivity() const; enum CaseSensitivity {
void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity); CaseInsensitive,
CaseSensitive,
FirstLetterCaseSensitive
};
CaseSensitivity caseSensitivity() const;
void setCaseSensitivity(CaseSensitivity caseSensitivity);
bool autoInsertBrackets() const; bool autoInsertBrackets() const;
void setAutoInsertBrackets(bool autoInsertBrackets); void setAutoInsertBrackets(bool autoInsertBrackets);
...@@ -136,7 +142,7 @@ private: ...@@ -136,7 +142,7 @@ private:
TextEditor::ITextEditable *m_editor; TextEditor::ITextEditable *m_editor;
int m_startPosition; // Position of the cursor from which completion started int m_startPosition; // Position of the cursor from which completion started
Qt::CaseSensitivity m_caseSensitivity; CaseSensitivity m_caseSensitivity;
bool m_autoInsertBrackets; bool m_autoInsertBrackets;
bool m_partialCompletionEnabled; bool m_partialCompletionEnabled;
bool m_forcedCompletion; bool m_forcedCompletion;
......
...@@ -139,8 +139,8 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error) ...@@ -139,8 +139,8 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
QSettings *settings = Core::ICore::instance()->settings(); QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(QLatin1String("CppTools")); settings->beginGroup(QLatin1String("CppTools"));
settings->beginGroup(QLatin1String("Completion")); settings->beginGroup(QLatin1String("Completion"));
const bool caseSensitive = settings->value(QLatin1String("CaseSensitive"), true).toBool(); const int caseSensitivity = settings->value(QLatin1String("CaseSensitivity"), m_completion->caseSensitivity()).toInt();
m_completion->setCaseSensitivity(caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); m_completion->setCaseSensitivity((CppCodeCompletion::CaseSensitivity) caseSensitivity);
m_completion->setAutoInsertBrackets(settings->value(QLatin1String("AutoInsertBraces"), true).toBool()); m_completion->setAutoInsertBrackets(settings->value(QLatin1String("AutoInsertBraces"), true).toBool());
m_completion->setPartialCompletionEnabled(settings->value(QLatin1String("PartiallyComplete"), true).toBool()); m_completion->setPartialCompletionEnabled(settings->value(QLatin1String("PartiallyComplete"), true).toBool());
settings->endGroup(); settings->endGroup();
...@@ -169,7 +169,7 @@ void CppToolsPlugin::shutdown() ...@@ -169,7 +169,7 @@ void CppToolsPlugin::shutdown()
QSettings *settings = Core::ICore::instance()->settings(); QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(QLatin1String("CppTools")); settings->beginGroup(QLatin1String("CppTools"));
settings->beginGroup(QLatin1String("Completion")); settings->beginGroup(QLatin1String("Completion"));
settings->setValue(QLatin1String("CaseSensitive"), m_completion->caseSensitivity() == Qt::CaseSensitive); settings->setValue(QLatin1String("CaseSensitivity"), (int) m_completion->caseSensitivity());
settings->setValue(QLatin1String("AutoInsertBraces"), m_completion->autoInsertBrackets()); settings->setValue(QLatin1String("AutoInsertBraces"), m_completion->autoInsertBrackets());
settings->setValue(QLatin1String("PartiallyComplete"), m_completion->isPartialCompletionEnabled()); settings->setValue(QLatin1String("PartiallyComplete"), m_completion->isPartialCompletionEnabled());
settings->endGroup(); settings->endGroup();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment