Commit 78f1fca9 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Added configuration options for code completion

It is now possible to choose between case-sensitive or case-insensitive
completion. Also, you can now disable the automatic insertion of braces.
parent 5c516771
......@@ -63,7 +63,7 @@ QString GeneralSettings::trCategory() const
QWidget* GeneralSettings::createPage(QWidget *parent)
{
m_page = new Ui_GeneralSettings();
m_page = new Ui_GeneralSettings;
QWidget *w = new QWidget(parent);
m_page->setupUi(w);
......@@ -77,7 +77,6 @@ QWidget* GeneralSettings::createPage(QWidget *parent)
connect(m_page->helpExternalEditorButton, SIGNAL(clicked()),
this, SLOT(showHelpForExternalEditor()));
return w;
}
......@@ -89,7 +88,6 @@ void GeneralSettings::finished(bool accepted)
// Apply the new base color if accepted
StyleHelper::setBaseColor(m_page->colorButton->color());
EditorManager::instance()->setExternalEditor(m_page->externalEditorEdit->text());
}
void GeneralSettings::resetInterfaceColor()
......
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "completionsettingspage.h"
#include "cppcodecompletion.h"
#include "ui_completionsettingspage.h"
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
using namespace CppTools::Internal;
CompletionSettingsPage::CompletionSettingsPage(CppCodeCompletion *completion)
: m_completion(completion)
, m_page(0)
{
}
QString CompletionSettingsPage::name() const
{
return tr("Completion");
}
QString CompletionSettingsPage::category() const
{
return QLatin1String("TextEditor");
}
QString CompletionSettingsPage::trCategory() const
{
return tr("Text Editor");
}
QWidget *CompletionSettingsPage::createPage(QWidget *parent)
{
m_page = new Ui_CompletionSettingsPage;
QWidget *w = new QWidget(parent);
m_page->setupUi(w);
m_page->caseSensitive->setChecked(m_completion->caseSensitivity() == Qt::CaseSensitive);
m_page->autoInsertBraces->setChecked(m_completion->autoInsertBraces());
return w;
}
void CompletionSettingsPage::finished(bool accepted)
{
if (accepted) {
m_completion->setCaseSensitivity(
m_page->caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);
m_completion->setAutoInsertBraces(m_page->autoInsertBraces->isChecked());
}
delete m_page;
m_page = 0;
}
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef COMPLETIONSETTINGSPAGE_H
#define COMPLETIONSETTINGSPAGE_H
#include <coreplugin/dialogs/ioptionspage.h>
QT_BEGIN_NAMESPACE
class Ui_CompletionSettingsPage;
QT_END_NAMESPACE
namespace CppTools {
namespace Internal {
class CppCodeCompletion;
class CompletionSettingsPage : public Core::IOptionsPage
{
public:
CompletionSettingsPage(CppCodeCompletion *completion);
QString name() const;
QString category() const;
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void finished(bool accepted);
private:
CppCodeCompletion *m_completion;
Ui_CompletionSettingsPage *m_page;
};
} // namespace Internal
} // namespace CppTools
#endif // COMPLETIONSETTINGSPAGE_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CompletionSettingsPage</class>
<widget class="QWidget" name="CompletionSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="caseSensitive">
<property name="text">
<string>Match completions &amp;case-sensitive</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoInsertBraces">
<property name="text">
<string>&amp;Automatically insert braces</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -314,12 +314,37 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager, Core::ICore *core
: ICompletionCollector(manager),
m_core(core),
m_manager(manager),
m_caseSensitivity(Qt::CaseSensitive),
m_autoInsertBraces(true),
m_forcedCompletion(false),
m_completionOperator(T_EOF_SYMBOL)
{ }
{
}
QIcon CppCodeCompletion::iconForSymbol(Symbol *symbol) const
{ return m_icons.iconForSymbol(symbol); }
{
return m_icons.iconForSymbol(symbol);
}
Qt::CaseSensitivity CppCodeCompletion::caseSensitivity() const
{
return m_caseSensitivity;
}
void CppCodeCompletion::setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
{
m_caseSensitivity = caseSensitivity;
}
bool CppCodeCompletion::autoInsertBraces() const
{
return m_autoInsertBraces;
}
void CppCodeCompletion::setAutoInsertBraces(bool autoInsertBraces)
{
m_autoInsertBraces = autoInsertBraces;
}
/*
Searches beckward for an access operator.
......@@ -705,14 +730,14 @@ void CppCodeCompletion::addMacros(const LookupContext &context)
continue;
processed.insert(fn);
if (Document::Ptr doc = context.document(fn)) {
foreach (const Macro macro, doc->definedMacros()) {
foreach (const Macro &macro, doc->definedMacros()) {
macroNames.insert(macro.name);
}
todo += doc->includedFiles();
}
}
foreach (const QByteArray macroName, macroNames) {
foreach (const QByteArray &macroName, macroNames) {
TextEditor::CompletionItem item(this);
item.m_text = QString::fromLatin1(macroName.constData(), macroName.length());
item.m_icon = m_icons.macroIcon();
......@@ -889,29 +914,25 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
*
* Meaning it allows any sequence of lower-case characters to preceed an
* upper-case character. So for example gAC matches getActionController.
*
* The match is case-sensitive as soon as at least one upper-case character is
* present.
*/
QString keyRegExp;
keyRegExp += QLatin1Char('^');
bool first = true;
Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive;
foreach (const QChar &c, key) {
if (c.isLower()) {
keyRegExp.append(c);
} else if (c.isUpper()) {
sensitivity = Qt::CaseSensitive;
if (!first) {
keyRegExp.append("[a-z0-9_]*");
}
keyRegExp.append(c);
if (c.isUpper() && !first) {
keyRegExp += QLatin1String("[a-z0-9_]*");
keyRegExp += c;
} else if (m_caseSensitivity == Qt::CaseInsensitive && c.isLower()) {
keyRegExp += QLatin1Char('[');
keyRegExp += c;
keyRegExp += c.toUpper();
keyRegExp += QLatin1Char(']');
} else {
keyRegExp.append(QRegExp::escape(c));
keyRegExp += QRegExp::escape(c);
}
first = false;
}
const QRegExp regExp(keyRegExp, sensitivity);
const QRegExp regExp(keyRegExp, Qt::CaseSensitive);
foreach (TextEditor::CompletionItem item, m_completions) {
if (regExp.indexIn(item.m_text) == 0) {
......@@ -962,7 +983,7 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
//qDebug() << "current symbol:" << overview.prettyName(symbol->name())
//<< overview.prettyType(symbol->type());
if (symbol) {
if (m_autoInsertBraces && symbol) {
if (Function *function = symbol->type()->asFunction()) {
// If the member is a function, automatically place the opening parenthesis,
// except when it might take template parameters.
......
......@@ -78,6 +78,12 @@ public:
QIcon iconForSymbol(CPlusPlus::Symbol *symbol) const;
Qt::CaseSensitivity caseSensitivity() const;
void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
bool autoInsertBraces() const;
void setAutoInsertBraces(bool autoInsertBraces);
private:
void addKeywords();
void addMacros(const CPlusPlus::LookupContext &context);
......@@ -126,6 +132,8 @@ private:
Core::ICore *m_core;
CppModelManager *m_manager;
Qt::CaseSensitivity m_caseSensitivity;
bool m_autoInsertBraces;
bool m_forcedCompletion;
......
......@@ -13,12 +13,14 @@ HEADERS += cpptools_global.h \
cppquickopenfilter.h \
cppclassesfilter.h \
searchsymbols.h \
cppfunctionsfilter.h
cppfunctionsfilter.h \
completionsettingspage.h
SOURCES += cppquickopenfilter.cpp \
cpptoolseditorsupport.cpp \
cppclassesfilter.cpp \
searchsymbols.cpp \
cppfunctionsfilter.cpp
cppfunctionsfilter.cpp \
completionsettingspage.cpp
# Input
SOURCES += cpptoolsplugin.cpp \
......@@ -33,3 +35,4 @@ HEADERS += cpptoolsplugin.h \
cpptoolseditorsupport.h \
cpptoolsconstants.h
RESOURCES += cpptools.qrc
FORMS += completionsettingspage.ui
......@@ -32,6 +32,8 @@
***************************************************************************/
#include "cpptoolsplugin.h"
#include "completionsettingspage.h"
#include "cppclassesfilter.h"
#include "cppcodecompletion.h"
#include "cppfunctionsfilter.h"
......@@ -52,6 +54,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QDebug>
#include <QtCore/QSettings>
#include <QtGui/QMenu>
#include <QtGui/QAction>
......@@ -84,13 +87,14 @@ bool CppToolsPlugin::initialize(const QStringList & /*arguments*/, QString *)
// Objects
m_modelManager = new CppModelManager(this);
addAutoReleasedObject(m_modelManager);
CppCodeCompletion *cppcodecompletion = new CppCodeCompletion(m_modelManager, m_core);
addAutoReleasedObject(cppcodecompletion);
CppCodeCompletion *m_completion = new CppCodeCompletion(m_modelManager, m_core);
addAutoReleasedObject(m_completion);
CppQuickOpenFilter *quickOpenFilter = new CppQuickOpenFilter(m_modelManager,
m_core->editorManager());
addAutoReleasedObject(quickOpenFilter);
addAutoReleasedObject(new CppClassesFilter(m_modelManager, m_core->editorManager()));
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, m_core->editorManager()));
addAutoReleasedObject(new CompletionSettingsPage(m_completion));
// Menus
Core::IActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
......@@ -110,6 +114,16 @@ bool CppToolsPlugin::initialize(const QStringList & /*arguments*/, QString *)
mcpptools->addAction(command);
connect(switchAction, SIGNAL(triggered()), this, SLOT(switchHeaderSource()));
// Restore settings
QSettings *settings = m_core->settings();
settings->beginGroup(QLatin1String("CppTools"));
settings->beginGroup(QLatin1String("Completion"));
const bool caseSensitive = settings->value(QLatin1String("CaseSensitive"), true).toBool();
m_completion->setCaseSensitivity(caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
m_completion->setAutoInsertBraces(settings->value(QLatin1String("AutoInsertBraces"), true).toBool());
settings->endGroup();
settings->endGroup();
return true;
}
......@@ -117,6 +131,18 @@ void CppToolsPlugin::extensionsInitialized()
{
}
void CppToolsPlugin::shutdown()
{
// Save settings
QSettings *settings = m_core->settings();
settings->beginGroup(QLatin1String("CppTools"));
settings->beginGroup(QLatin1String("Completion"));
settings->setValue(QLatin1String("CaseSensitive"), m_completion->caseSensitivity() == Qt::CaseSensitive);
settings->setValue(QLatin1String("AutoInsertBraces"), m_completion->autoInsertBraces());
settings->endGroup();
settings->endGroup();
}
void CppToolsPlugin::switchHeaderSource()
{
if (!m_core)
......@@ -150,7 +176,12 @@ QFileInfo CppToolsPlugin::findFile(const QDir &dir, const QString &name,
}
// Figure out file type
enum FileType { HeaderFile, C_SourceFile, CPP_SourceFile, UnknownType };
enum FileType {
HeaderFile,
C_SourceFile,
CPP_SourceFile,
UnknownType
};
static inline FileType fileType(const Core::MimeDatabase *mimeDatase, const QFileInfo & fi)
{
......
......@@ -64,6 +64,7 @@ public:
bool initialize(const QStringList &arguments, QString *error_message);
void extensionsInitialized();
void shutdown();
CppModelManager *cppModelManager() { return m_modelManager; }
QString correspondingHeaderOrSource(const QString &fileName) const;
......@@ -77,6 +78,7 @@ private:
Core::ICore *m_core;
int m_context;
CppModelManager *m_modelManager;
CppCodeCompletion *m_completion;
static CppToolsPlugin *m_instance;
};
......
......@@ -40,8 +40,6 @@
#include <qtconcurrent/QtConcurrentTools>
#include <utils/qtcassert.h>
#include <QtGui/QMessageBox>
Q_DECLARE_METATYPE(QuickOpen::IQuickOpenFilter*)
using namespace QuickOpen;
......
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