diff --git a/src/plugins/coreplugin/generalsettings.cpp b/src/plugins/coreplugin/generalsettings.cpp index 5edfda207e87ae8b856609a067ebfd917893c3b8..220561b5a4144bad3f4f67fb788b6a0f95d7277c 100644 --- a/src/plugins/coreplugin/generalsettings.cpp +++ b/src/plugins/coreplugin/generalsettings.cpp @@ -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() diff --git a/src/plugins/cpptools/completionsettingspage.cpp b/src/plugins/cpptools/completionsettingspage.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ad7fa77e739f523a1fa1524e208a01db19055041 --- /dev/null +++ b/src/plugins/cpptools/completionsettingspage.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** +** +** 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; +} diff --git a/src/plugins/cpptools/completionsettingspage.h b/src/plugins/cpptools/completionsettingspage.h new file mode 100644 index 0000000000000000000000000000000000000000..f62acd03e228597d556facc88037582c1fadefe1 --- /dev/null +++ b/src/plugins/cpptools/completionsettingspage.h @@ -0,0 +1,68 @@ +/*************************************************************************** +** +** 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 diff --git a/src/plugins/cpptools/completionsettingspage.ui b/src/plugins/cpptools/completionsettingspage.ui new file mode 100644 index 0000000000000000000000000000000000000000..10e4273f4d64afee36f181c0033c2c9a3810ed7c --- /dev/null +++ b/src/plugins/cpptools/completionsettingspage.ui @@ -0,0 +1,54 @@ +<?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 &case-sensitive</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="autoInsertBraces"> + <property name="text"> + <string>&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> diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index addf5301f79b66f5421217ade1d2a4d0d6b15c57..c7cd3f07a919676e4691cc81a654e4ae0073ad34 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -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 ¯o, doc->definedMacros()) { macroNames.insert(macro.name); } todo += doc->includedFiles(); } } - foreach (const QByteArray macroName, macroNames) { + foreach (const QByteArray ¯oName, 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. diff --git a/src/plugins/cpptools/cppcodecompletion.h b/src/plugins/cpptools/cppcodecompletion.h index 02170482486453a719aa61f4ac7ce9ec146c6bd8..87f84fffff1b1b890b33382399bfd1f53dd7d161 100644 --- a/src/plugins/cpptools/cppcodecompletion.h +++ b/src/plugins/cpptools/cppcodecompletion.h @@ -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; diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 8206acc2c12c23b9fa484d637aeda26f6bd9f001..f86ca6bdd5e08b1048cb9826f4c98999d0c0c34e 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -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 diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index 1aefe3d49e28b219802a4c176f1726c09ee2acb8..d1b9e34216b746b0e1f953bc58304b1c26427e78 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -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) { diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h index a64bfcf9dcdd4da661b55146e92c5095705aafff..8760e6a66f60501bb1d72efcfdc4998efbe83ca9 100644 --- a/src/plugins/cpptools/cpptoolsplugin.h +++ b/src/plugins/cpptools/cpptoolsplugin.h @@ -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; }; diff --git a/src/plugins/quickopen/settingspage.cpp b/src/plugins/quickopen/settingspage.cpp index 4b1f81fc86721ad7b640c6946ed864a2edeffee5..d84253d2b13d78bdd88c61699d7bd209cfa7ebcb 100644 --- a/src/plugins/quickopen/settingspage.cpp +++ b/src/plugins/quickopen/settingspage.cpp @@ -40,8 +40,6 @@ #include <qtconcurrent/QtConcurrentTools> #include <utils/qtcassert.h> -#include <QtGui/QMessageBox> - Q_DECLARE_METATYPE(QuickOpen::IQuickOpenFilter*) using namespace QuickOpen;