forked from qt-creator/qt-creator
		
	Merge remote branch 'origin/2.0'
Conflicts: src/plugins/cpptools/cppcodecompletion.cpp
This commit is contained in:
		@@ -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;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -57,6 +57,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>
 | 
			
		||||
@@ -436,10 +437,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)
 | 
			
		||||
@@ -451,46 +448,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.
 | 
			
		||||
*/
 | 
			
		||||
@@ -1512,7 +1469,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 ||
 | 
			
		||||
@@ -1590,7 +1547,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.
 | 
			
		||||
@@ -1603,8 +1562,8 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
 | 
			
		||||
                        extraChars += QLatin1Char('<');
 | 
			
		||||
                    }
 | 
			
		||||
                } else if (! function->isAmbiguous()) {
 | 
			
		||||
                    if (m_spaceAfterFunctionName)
 | 
			
		||||
                        extraChars += QLatin1Char(' ');
 | 
			
		||||
                    if (completionSettings().m_spaceAfterFunctionName)
 | 
			
		||||
			extraChars += QLatin1Char(' ');
 | 
			
		||||
                    extraChars += QLatin1Char('(');
 | 
			
		||||
 | 
			
		||||
                    // If the function doesn't return anything, automatically place the semicolon,
 | 
			
		||||
@@ -1631,7 +1590,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(')'));
 | 
			
		||||
@@ -1667,7 +1626,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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -86,18 +86,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);
 | 
			
		||||
@@ -159,10 +147,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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user