Commit e53b5bc9 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Fixed completion settings to also apply to the QML code completion

By moving the completion settings into the TextEditor plugin, so that
both the CppTools and the QmlJSEditor plugins can access the settings.

The user-interface to edit the settings is still in the CppTools plugin,
since we're in string freeze at the moment. It should be moved to the
TextEditor plugin later.

For now the QML completion only supports the case-sensitivity and
partial completion options, since there is no automatic insertion of
brackets.

Task-number: QTCREATORBUG-1327
Reviewed-by: default avatarDaniel Molkentin <daniel.molkentin@nokia.com>
parent b8f7d447
......@@ -32,15 +32,15 @@
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/texteditorsettings.h>
#include <QtCore/QTextStream>
#include <QtCore/QCoreApplication>
using namespace CppTools::Internal;
CompletionSettingsPage::CompletionSettingsPage(CppCodeCompletion *completion)
: m_completion(completion)
, m_page(new Ui_CompletionSettingsPage)
CompletionSettingsPage::CompletionSettingsPage()
: m_page(new Ui_CompletionSettingsPage)
{
}
......@@ -64,23 +64,27 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
QWidget *w = new QWidget(parent);
m_page->setupUi(w);
const TextEditor::CompletionSettings &settings =
TextEditor::TextEditorSettings::instance()->completionSettings();
int caseSensitivityIndex = 0;
switch (m_completion->caseSensitivity()) {
case CppCodeCompletion::CaseSensitive:
switch (settings.m_caseSensitivity) {
case TextEditor::CaseSensitive:
caseSensitivityIndex = 0;
break;
case CppCodeCompletion::CaseInsensitive:
case TextEditor::CaseInsensitive:
caseSensitivityIndex = 1;
break;
case CppCodeCompletion::FirstLetterCaseSensitive:
case TextEditor::FirstLetterCaseSensitive:
caseSensitivityIndex = 2;
break;
}
m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex);
m_page->autoInsertBrackets->setChecked(m_completion->autoInsertBrackets());
m_page->partiallyComplete->setChecked(m_completion->isPartialCompletionEnabled());
m_page->spaceAfterFunctionName->setChecked(m_completion->isSpaceAfterFunctionName());
m_page->autoInsertBrackets->setChecked(settings.m_autoInsertBrackets);
m_page->partiallyComplete->setChecked(settings.m_partiallyComplete);
m_page->spaceAfterFunctionName->setChecked(settings.m_spaceAfterFunctionName);
if (m_searchKeywords.isEmpty()) {
QTextStream(&m_searchKeywords) << m_page->caseSensitivityLabel->text()
<< ' ' << m_page->autoInsertBrackets->text()
......@@ -88,15 +92,19 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
<< ' ' << m_page->spaceAfterFunctionName->text();
m_searchKeywords.remove(QLatin1Char('&'));
}
return w;
}
void CompletionSettingsPage::apply()
{
m_completion->setCaseSensitivity(caseSensitivity());
m_completion->setAutoInsertBrackets(m_page->autoInsertBrackets->isChecked());
m_completion->setPartialCompletionEnabled(m_page->partiallyComplete->isChecked());
m_completion->setSpaceAfterFunctionName(m_page->spaceAfterFunctionName->isChecked());
TextEditor::CompletionSettings settings;
settings.m_caseSensitivity = caseSensitivity();
settings.m_autoInsertBrackets = m_page->autoInsertBrackets->isChecked();
settings.m_partiallyComplete = m_page->partiallyComplete->isChecked();
settings.m_spaceAfterFunctionName = m_page->spaceAfterFunctionName->isChecked();
TextEditor::TextEditorSettings::instance()->setCompletionSettings(settings);
}
bool CompletionSettingsPage::matches(const QString &s) const
......@@ -104,14 +112,14 @@ bool CompletionSettingsPage::matches(const QString &s) const
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}
CppCodeCompletion::CaseSensitivity CompletionSettingsPage::caseSensitivity() const
TextEditor::CaseSensitivity CompletionSettingsPage::caseSensitivity() const
{
switch (m_page->caseSensitivity->currentIndex()) {
case 0: // Full
return CppCodeCompletion::CaseSensitive;
return TextEditor::CaseSensitive;
case 1: // None
return CppCodeCompletion::CaseInsensitive;
return TextEditor::CaseInsensitive;
default: // First letter
return CppCodeCompletion::FirstLetterCaseSensitive;
return TextEditor::FirstLetterCaseSensitive;
}
}
......@@ -30,10 +30,9 @@
#ifndef COMPLETIONSETTINGSPAGE_H
#define COMPLETIONSETTINGSPAGE_H
#include <texteditor/completionsettings.h>
#include <texteditor/texteditoroptionspage.h>
#include "cppcodecompletion.h"
QT_BEGIN_NAMESPACE
class Ui_CompletionSettingsPage;
QT_END_NAMESPACE
......@@ -41,12 +40,14 @@ QT_END_NAMESPACE
namespace CppTools {
namespace Internal {
// TODO: Move this class to the text editor plugin
class CompletionSettingsPage : public TextEditor::TextEditorOptionsPage
{
Q_OBJECT
public:
CompletionSettingsPage(CppCodeCompletion *completion);
CompletionSettingsPage();
~CompletionSettingsPage();
QString id() const;
......@@ -58,9 +59,8 @@ public:
virtual bool matches(const QString &) const;
private:
CppCodeCompletion::CaseSensitivity caseSensitivity() const;
TextEditor::CaseSensitivity caseSensitivity() const;
CppCodeCompletion *m_completion;
Ui_CompletionSettingsPage *m_page;
QString m_searchKeywords;
};
......
......@@ -56,6 +56,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/editormanager/editormanager.h>
#include <texteditor/completionsettings.h>
#include <texteditor/itexteditor.h>
#include <texteditor/itexteditable.h>
#include <texteditor/basetexteditor.h>
......@@ -435,10 +436,6 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager)
m_manager(manager),
m_editor(0),
m_startPosition(-1),
m_caseSensitivity(FirstLetterCaseSensitive),
m_autoInsertBrackets(true),
m_partialCompletionEnabled(true),
m_spaceAfterFunctionName(false),
m_forcedCompletion(false),
m_completionOperator(T_EOF_SYMBOL),
m_objcEnabled(true)
......@@ -450,46 +447,6 @@ QIcon CppCodeCompletion::iconForSymbol(Symbol *symbol) const
return m_icons.iconForSymbol(symbol);
}
CppCodeCompletion::CaseSensitivity CppCodeCompletion::caseSensitivity() const
{
return m_caseSensitivity;
}
void CppCodeCompletion::setCaseSensitivity(CaseSensitivity caseSensitivity)
{
m_caseSensitivity = caseSensitivity;
}
bool CppCodeCompletion::autoInsertBrackets() const
{
return m_autoInsertBrackets;
}
void CppCodeCompletion::setAutoInsertBrackets(bool autoInsertBrackets)
{
m_autoInsertBrackets = autoInsertBrackets;
}
bool CppCodeCompletion::isPartialCompletionEnabled() const
{
return m_partialCompletionEnabled;
}
void CppCodeCompletion::setPartialCompletionEnabled(bool partialCompletionEnabled)
{
m_partialCompletionEnabled = partialCompletionEnabled;
}
bool CppCodeCompletion::isSpaceAfterFunctionName() const
{
return m_spaceAfterFunctionName;
}
void CppCodeCompletion::setSpaceAfterFunctionName(bool spaceAfterFunctionName)
{
m_spaceAfterFunctionName = spaceAfterFunctionName;
}
/*
Searches backwards for an access operator.
*/
......@@ -1459,7 +1416,7 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
return;
if (m_completionOperator != T_LPAREN) {
filter(m_completions, completions, key, m_caseSensitivity);
filter(m_completions, completions, key);
} else if (m_completionOperator == T_LPAREN ||
m_completionOperator == T_SIGNAL ||
......@@ -1537,7 +1494,9 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
//qDebug() << "current symbol:" << overview.prettyName(symbol->name())
//<< overview.prettyType(symbol->type());
if (m_autoInsertBrackets && symbol && symbol->type()) {
const bool autoInsertBrackets = completionSettings().m_autoInsertBrackets;
if (autoInsertBrackets && symbol && symbol->type()) {
if (Function *function = symbol->type()->asFunctionType()) {
// If the member is a function, automatically place the opening parenthesis,
// except when it might take template parameters.
......@@ -1550,7 +1509,7 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
extraChars += QLatin1Char('<');
}
} else if (! function->isAmbiguous()) {
if (m_spaceAfterFunctionName)
if (completionSettings().m_spaceAfterFunctionName)
extraChars += QLatin1Char(' ');
extraChars += QLatin1Char('(');
......@@ -1578,7 +1537,7 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
}
}
if (m_autoInsertBrackets && item.data.canConvert<CompleteFunctionDeclaration>()) {
if (autoInsertBrackets && item.data.canConvert<CompleteFunctionDeclaration>()) {
// everything from the closing parenthesis on are extra chars, to
// make sure an auto-inserted ")" gets replaced by ") const" if necessary
int closingParen = toInsert.lastIndexOf(QLatin1Char(')'));
......@@ -1614,7 +1573,7 @@ bool CppCodeCompletion::partiallyComplete(const QList<TextEditor::CompletionItem
} else if (completionItems.count() == 1) {
complete(completionItems.first());
return true;
} else if (m_partialCompletionEnabled && m_completionOperator != T_LPAREN) {
} else if (m_completionOperator != T_LPAREN) {
return TextEditor::ICompletionCollector::partiallyComplete(completionItems);
}
......
......@@ -79,18 +79,6 @@ public:
QIcon iconForSymbol(CPlusPlus::Symbol *symbol) const;
CaseSensitivity caseSensitivity() const;
void setCaseSensitivity(CaseSensitivity caseSensitivity);
bool autoInsertBrackets() const;
void setAutoInsertBrackets(bool autoInsertBrackets);
bool isPartialCompletionEnabled() const;
void setPartialCompletionEnabled(bool partialCompletionEnabled);
bool isSpaceAfterFunctionName() const;
void setSpaceAfterFunctionName(bool spaceAfterFunctionName);
private:
void addKeywords();
void addMacros(const QString &fileName, const CPlusPlus::Snapshot &snapshot);
......@@ -152,10 +140,6 @@ private:
TextEditor::ITextEditable *m_editor;
int m_startPosition; // Position of the cursor from which completion started
CaseSensitivity m_caseSensitivity;
bool m_autoInsertBrackets;
bool m_partialCompletionEnabled;
bool m_spaceAfterFunctionName;
bool m_forcedCompletion;
unsigned m_completionOperator;
bool m_objcEnabled;
......
......@@ -51,6 +51,7 @@
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/filemanager.h>
#include <texteditor/texteditorsettings.h>
#include <cppeditor/cppeditorconstants.h>
#include <QtCore/QtConcurrentRun>
......@@ -109,8 +110,8 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
m_modelManager, SLOT(updateSourceFiles(QStringList)));
addAutoReleasedObject(m_modelManager);
m_completion = new CppCodeCompletion(m_modelManager);
addAutoReleasedObject(m_completion);
CppCodeCompletion *completion = new CppCodeCompletion(m_modelManager);
addAutoReleasedObject(completion);
CppLocatorFilter *locatorFilter = new CppLocatorFilter(m_modelManager,
core->editorManager());
......@@ -118,7 +119,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
addAutoReleasedObject(new CppClassesFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CppCurrentDocumentFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CompletionSettingsPage(m_completion));
addAutoReleasedObject(new CompletionSettingsPage);
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
// Menus
......@@ -139,17 +140,11 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
mcpptools->addAction(command);
connect(switchAction, SIGNAL(triggered()), this, SLOT(switchHeaderSource()));
// Restore settings
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(QLatin1String("CppTools"));
settings->beginGroup(QLatin1String("Completion"));
const int caseSensitivity = settings->value(QLatin1String("CaseSensitivity"), m_completion->caseSensitivity()).toInt();
m_completion->setCaseSensitivity((CppCodeCompletion::CaseSensitivity) caseSensitivity);
m_completion->setAutoInsertBrackets(settings->value(QLatin1String("AutoInsertBraces"), true).toBool());
m_completion->setPartialCompletionEnabled(settings->value(QLatin1String("PartiallyComplete"), true).toBool());
m_completion->setSpaceAfterFunctionName(settings->value(QLatin1String("SpaceAfterFunctionName"), false).toBool());
settings->endGroup();
settings->endGroup();
// Set completion settings and keep them up to date
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
completion->setCompletionSettings(textEditorSettings->completionSettings());
connect(textEditorSettings, SIGNAL(completionSettingsChanged(TextEditor::CompletionSettings)),
completion, SLOT(setCompletionSettings(TextEditor::CompletionSettings)));
return true;
}
......@@ -170,16 +165,6 @@ void CppToolsPlugin::extensionsInitialized()
void CppToolsPlugin::aboutToShutdown()
{
// Save settings
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(QLatin1String("CppTools"));
settings->beginGroup(QLatin1String("Completion"));
settings->setValue(QLatin1String("CaseSensitivity"), (int) m_completion->caseSensitivity());
settings->setValue(QLatin1String("AutoInsertBraces"), m_completion->autoInsertBrackets());
settings->setValue(QLatin1String("PartiallyComplete"), m_completion->isPartialCompletionEnabled());
settings->setValue(QLatin1String("SpaceAfterFunctionName"), m_completion->isSpaceAfterFunctionName());
settings->endGroup();
settings->endGroup();
}
void CppToolsPlugin::switchHeaderSource()
......
......@@ -50,7 +50,6 @@ QT_END_NAMESPACE
namespace CppTools {
namespace Internal {
class CppCodeCompletion;
class CppModelManager;
struct CppFileSettings;
......@@ -79,7 +78,6 @@ private:
int m_context;
CppModelManager *m_modelManager;
CppCodeCompletion *m_completion;
QSharedPointer<CppFileSettings> m_fileSettings;
static CppToolsPlugin *m_instance;
......
......@@ -477,8 +477,7 @@ CodeCompletion::CodeCompletion(ModelManagerInterface *modelManager, QObject *par
: TextEditor::ICompletionCollector(parent),
m_modelManager(modelManager),
m_editor(0),
m_startPosition(0),
m_caseSensitivity(Qt::CaseSensitive)
m_startPosition(0)
{
Q_ASSERT(modelManager);
}
......@@ -486,12 +485,6 @@ CodeCompletion::CodeCompletion(ModelManagerInterface *modelManager, QObject *par
CodeCompletion::~CodeCompletion()
{ }
Qt::CaseSensitivity CodeCompletion::caseSensitivity() const
{ return m_caseSensitivity; }
void CodeCompletion::setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
{ m_caseSensitivity = caseSensitivity; }
TextEditor::ITextEditable *CodeCompletion::editor() const
{ return m_editor; }
......@@ -854,7 +847,7 @@ void CodeCompletion::completions(QList<TextEditor::CompletionItem> *completions)
else if (length > 0) {
const QString key = m_editor->textAt(m_startPosition, length);
filter(m_completions, completions, key, FirstLetterCaseSensitive);
filter(m_completions, completions, key);
if (completions->size() == 1) {
if (key == completions->first().text)
......
......@@ -55,9 +55,6 @@ public:
CodeCompletion(ModelManagerInterface *modelManager, QObject *parent = 0);
virtual ~CodeCompletion();
Qt::CaseSensitivity caseSensitivity() const;
void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
virtual TextEditor::ITextEditable *editor() const;
virtual int startPosition() const;
virtual bool shouldRestartCompletion();
......@@ -81,7 +78,6 @@ private:
TextEditor::ITextEditable *m_editor;
int m_startPosition;
QList<TextEditor::CompletionItem> m_completions;
Qt::CaseSensitivity m_caseSensitivity;
QList<TextEditor::CompletionItem> m_snippets;
QDateTime m_snippetFileLastModified;
......
......@@ -77,8 +77,7 @@ QmlJSEditorPlugin::QmlJSEditorPlugin() :
m_modelManager(0),
m_wizard(0),
m_editor(0),
m_actionHandler(0),
m_completion(0)
m_actionHandler(0)
{
m_instance = this;
}
......@@ -148,19 +147,16 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
contextMenu->addAction(cmd);
m_completion = new CodeCompletion(m_modelManager);
addAutoReleasedObject(m_completion);
CodeCompletion *completion = new CodeCompletion(m_modelManager);
addAutoReleasedObject(completion);
addAutoReleasedObject(new HoverHandler());
addAutoReleasedObject(new HoverHandler);
// Restore settings
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(QLatin1String("CppTools")); // ### FIXME:
settings->beginGroup(QLatin1String("Completion"));
const bool caseSensitive = settings->value(QLatin1String("CaseSensitive"), true).toBool();
m_completion->setCaseSensitivity(caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
settings->endGroup();
settings->endGroup();
// Set completion settings and keep them up to date
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
completion->setCompletionSettings(textEditorSettings->completionSettings());
connect(textEditorSettings, SIGNAL(completionSettingsChanged(TextEditor::CompletionSettings)),
completion, SLOT(setCompletionSettings(TextEditor::CompletionSettings)));
error_message->clear();
......
......@@ -52,7 +52,6 @@ class QmlFileWizard;
namespace Internal {
class QmlJSEditorFactory;
class CodeCompletion;
class QmlJSTextEditor;
class QmlJSPreviewRunner;
......@@ -92,7 +91,6 @@ private:
QmlFileWizard *m_wizard;
QmlJSEditorFactory *m_editor;
TextEditor::TextEditorActionHandler *m_actionHandler;
CodeCompletion *m_completion;
};
} // namespace Internal
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "completionsettings.h"
#include <QtCore/QSettings>
static const char * const groupPostfix = "Completion";
static const char * const caseSensitivityKey = "CaseSensitivity";
static const char * const autoInsertBracesKey = "AutoInsertBraces";
static const char * const partiallyCompleteKey = "PartiallyComplete";
static const char * const spaceAfterFunctionNameKey = "SpaceAfterFunctionName";
using namespace TextEditor;
CompletionSettings::CompletionSettings()
: m_caseSensitivity(FirstLetterCaseSensitive)
, m_autoInsertBrackets(true)
, m_partiallyComplete(true)
, m_spaceAfterFunctionName(false)
{
}
void CompletionSettings::toSettings(const QString &category, QSettings *s) const
{
QString group = QLatin1String(groupPostfix);
if (!category.isEmpty())
group.insert(0, category);
s->beginGroup(group);
s->setValue(QLatin1String(caseSensitivityKey), (int) m_caseSensitivity);
s->setValue(QLatin1String(autoInsertBracesKey), m_autoInsertBrackets);
s->setValue(QLatin1String(partiallyCompleteKey), m_partiallyComplete);
s->setValue(QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName);
s->endGroup();
}
void CompletionSettings::fromSettings(const QString &category, const QSettings *s)
{
QString group = QLatin1String(groupPostfix);
if (!category.isEmpty())
group.insert(0, category);
group += QLatin1Char('/');
*this = CompletionSettings(); // Assign defaults
m_caseSensitivity = (CaseSensitivity) s->value(group + QLatin1String(caseSensitivityKey), m_caseSensitivity).toInt();
m_autoInsertBrackets = s->value(group + QLatin1String(autoInsertBracesKey), m_autoInsertBrackets).toBool();
m_partiallyComplete = s->value(group + QLatin1String(partiallyCompleteKey), m_partiallyComplete).toBool();
m_spaceAfterFunctionName = s->value(group + QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName).toBool();
}
bool CompletionSettings::equals(const CompletionSettings &cs) const
{
return m_caseSensitivity == cs.m_caseSensitivity
&& m_autoInsertBrackets == cs.m_autoInsertBrackets
&& m_partiallyComplete == cs.m_partiallyComplete
&& m_spaceAfterFunctionName == cs.m_spaceAfterFunctionName
;
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef COMPLETIONSETTINGS_H
#define COMPLETIONSETTINGS_H
#include "texteditor_global.h"
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace TextEditor {
enum CaseSensitivity {
CaseInsensitive,
CaseSensitive,
FirstLetterCaseSensitive
};
/**
* Settings that describe how the code completion behaves.
*/
struct TEXTEDITOR_EXPORT CompletionSettings
{
CompletionSettings();
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
bool equals(const CompletionSettings &bs) const;
CaseSensitivity m_caseSensitivity;
bool m_autoInsertBrackets;
bool m_partiallyComplete;
bool m_spaceAfterFunctionName;
};
inline bool operator==(const CompletionSettings &t1, const CompletionSettings &t2) { return t1.equals(t2); }
inline bool operator!=(const CompletionSettings &t1, const CompletionSettings &t2) { return !t1.equals(t2); }
} // namespace TextEditor
#endif // COMPLETIONSETTINGS_H
......@@ -28,11 +28,27 @@
**************************************************************************/
#include "icompletioncollector.h"
#include "completionsettings.h"
#include "itexteditable.h"
#include <QtCore/QRegExp>
#include <algorithm>
using namespace TextEditor;
using namespace TextEditor::Internal;
namespace TextEditor {
namespace Internal {
struct ICompletionCollectorPrivate
{
public:
CompletionSettings m_completionSettings;
};
} // namespace Internal
} // namespace TextEditor
bool ICompletionCollector::compareChar(const QChar &l, const QChar &r)
{
......@@ -62,6 +78,27 @@ bool ICompletionCollector::completionItemLessThan(const CompletionItem &i1, cons
return lessThan(lower1, lower2);
}
ICompletionCollector::ICompletionCollector(QObject *parent)
: QObject(parent)
, m_d(new Internal::ICompletionCollectorPrivate)
{
}
ICompletionCollector::~ICompletionCollector()
{
delete m_d;
}
void ICompletionCollector::setCompletionSettings(const CompletionSettings &settings)
{
m_d->m_completionSettings = settings;
}
const CompletionSettings &ICompletionCollector::completionSettings() const
{
return m_d->m_completionSettings;
}
QList<CompletionItem> ICompletionCollector::getCompletions()
{
QList<CompletionItem> completionItems;
......@@ -88,6 +125,9 @@ QList<CompletionItem> ICompletionCollector::getCompletions()
bool ICompletionCollector::partiallyComplete(const QList<TextEditor::CompletionItem> &completionItems)
{
if (! m_d->m_completionSettings.m_partiallyComplete)
return false;
// Compute common prefix
QString firstKey = completionItems.first().text;
QString lastKey = completionItems.last().text;
......@@ -113,9 +153,10 @@ bool ICompletionCollector::partiallyComplete(const QList<TextEditor::CompletionI
void ICompletionCollector::filter(const QList<TextEditor::CompletionItem> &items,
QList<TextEditor::CompletionItem> *filteredItems,
const QString &key,
ICompletionCollector::CaseSensitivity caseSensitivity)
const QString &key)
{
const TextEditor::CaseSensitivity caseSensitivity = m_d->m_completionSettings.m_caseSensitivity;
/*
* This code builds a regular expression in order to more intelligently match
* camel-case style. This means upper-case characters will be rewritten as follows:
......@@ -132,8 +173,8 @@ void ICompletionCollector::filter(const QList<TextEditor::CompletionItem> &items
bool first = true;
const QLatin1String wordContinuation("[a-z0-9_]*");
foreach (const QChar &c, key) {