forked from qt-creator/qt-creator
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: Daniel Molkentin <daniel.molkentin@nokia.com>
This commit is contained in:
@@ -32,15 +32,15 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <QtCore/QTextStream>
|
#include <QtCore/QTextStream>
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
using namespace CppTools::Internal;
|
using namespace CppTools::Internal;
|
||||||
|
|
||||||
CompletionSettingsPage::CompletionSettingsPage(CppCodeCompletion *completion)
|
CompletionSettingsPage::CompletionSettingsPage()
|
||||||
: m_completion(completion)
|
: m_page(new Ui_CompletionSettingsPage)
|
||||||
, m_page(new Ui_CompletionSettingsPage)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,23 +64,27 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
|
|||||||
QWidget *w = new QWidget(parent);
|
QWidget *w = new QWidget(parent);
|
||||||
m_page->setupUi(w);
|
m_page->setupUi(w);
|
||||||
|
|
||||||
|
const TextEditor::CompletionSettings &settings =
|
||||||
|
TextEditor::TextEditorSettings::instance()->completionSettings();
|
||||||
|
|
||||||
int caseSensitivityIndex = 0;
|
int caseSensitivityIndex = 0;
|
||||||
switch (m_completion->caseSensitivity()) {
|
switch (settings.m_caseSensitivity) {
|
||||||
case CppCodeCompletion::CaseSensitive:
|
case TextEditor::CaseSensitive:
|
||||||
caseSensitivityIndex = 0;
|
caseSensitivityIndex = 0;
|
||||||
break;
|
break;
|
||||||
case CppCodeCompletion::CaseInsensitive:
|
case TextEditor::CaseInsensitive:
|
||||||
caseSensitivityIndex = 1;
|
caseSensitivityIndex = 1;
|
||||||
break;
|
break;
|
||||||
case CppCodeCompletion::FirstLetterCaseSensitive:
|
case TextEditor::FirstLetterCaseSensitive:
|
||||||
caseSensitivityIndex = 2;
|
caseSensitivityIndex = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex);
|
m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex);
|
||||||
m_page->autoInsertBrackets->setChecked(m_completion->autoInsertBrackets());
|
m_page->autoInsertBrackets->setChecked(settings.m_autoInsertBrackets);
|
||||||
m_page->partiallyComplete->setChecked(m_completion->isPartialCompletionEnabled());
|
m_page->partiallyComplete->setChecked(settings.m_partiallyComplete);
|
||||||
m_page->spaceAfterFunctionName->setChecked(m_completion->isSpaceAfterFunctionName());
|
m_page->spaceAfterFunctionName->setChecked(settings.m_spaceAfterFunctionName);
|
||||||
|
|
||||||
if (m_searchKeywords.isEmpty()) {
|
if (m_searchKeywords.isEmpty()) {
|
||||||
QTextStream(&m_searchKeywords) << m_page->caseSensitivityLabel->text()
|
QTextStream(&m_searchKeywords) << m_page->caseSensitivityLabel->text()
|
||||||
<< ' ' << m_page->autoInsertBrackets->text()
|
<< ' ' << m_page->autoInsertBrackets->text()
|
||||||
@@ -88,15 +92,19 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
|
|||||||
<< ' ' << m_page->spaceAfterFunctionName->text();
|
<< ' ' << m_page->spaceAfterFunctionName->text();
|
||||||
m_searchKeywords.remove(QLatin1Char('&'));
|
m_searchKeywords.remove(QLatin1Char('&'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompletionSettingsPage::apply()
|
void CompletionSettingsPage::apply()
|
||||||
{
|
{
|
||||||
m_completion->setCaseSensitivity(caseSensitivity());
|
TextEditor::CompletionSettings settings;
|
||||||
m_completion->setAutoInsertBrackets(m_page->autoInsertBrackets->isChecked());
|
settings.m_caseSensitivity = caseSensitivity();
|
||||||
m_completion->setPartialCompletionEnabled(m_page->partiallyComplete->isChecked());
|
settings.m_autoInsertBrackets = m_page->autoInsertBrackets->isChecked();
|
||||||
m_completion->setSpaceAfterFunctionName(m_page->spaceAfterFunctionName->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
|
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);
|
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
CppCodeCompletion::CaseSensitivity CompletionSettingsPage::caseSensitivity() const
|
TextEditor::CaseSensitivity CompletionSettingsPage::caseSensitivity() const
|
||||||
{
|
{
|
||||||
switch (m_page->caseSensitivity->currentIndex()) {
|
switch (m_page->caseSensitivity->currentIndex()) {
|
||||||
case 0: // Full
|
case 0: // Full
|
||||||
return CppCodeCompletion::CaseSensitive;
|
return TextEditor::CaseSensitive;
|
||||||
case 1: // None
|
case 1: // None
|
||||||
return CppCodeCompletion::CaseInsensitive;
|
return TextEditor::CaseInsensitive;
|
||||||
default: // First letter
|
default: // First letter
|
||||||
return CppCodeCompletion::FirstLetterCaseSensitive;
|
return TextEditor::FirstLetterCaseSensitive;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,10 +30,9 @@
|
|||||||
#ifndef COMPLETIONSETTINGSPAGE_H
|
#ifndef COMPLETIONSETTINGSPAGE_H
|
||||||
#define COMPLETIONSETTINGSPAGE_H
|
#define COMPLETIONSETTINGSPAGE_H
|
||||||
|
|
||||||
|
#include <texteditor/completionsettings.h>
|
||||||
#include <texteditor/texteditoroptionspage.h>
|
#include <texteditor/texteditoroptionspage.h>
|
||||||
|
|
||||||
#include "cppcodecompletion.h"
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class Ui_CompletionSettingsPage;
|
class Ui_CompletionSettingsPage;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
@@ -41,12 +40,14 @@ QT_END_NAMESPACE
|
|||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
// TODO: Move this class to the text editor plugin
|
||||||
|
|
||||||
class CompletionSettingsPage : public TextEditor::TextEditorOptionsPage
|
class CompletionSettingsPage : public TextEditor::TextEditorOptionsPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CompletionSettingsPage(CppCodeCompletion *completion);
|
CompletionSettingsPage();
|
||||||
~CompletionSettingsPage();
|
~CompletionSettingsPage();
|
||||||
|
|
||||||
QString id() const;
|
QString id() const;
|
||||||
@@ -58,9 +59,8 @@ public:
|
|||||||
virtual bool matches(const QString &) const;
|
virtual bool matches(const QString &) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CppCodeCompletion::CaseSensitivity caseSensitivity() const;
|
TextEditor::CaseSensitivity caseSensitivity() const;
|
||||||
|
|
||||||
CppCodeCompletion *m_completion;
|
|
||||||
Ui_CompletionSettingsPage *m_page;
|
Ui_CompletionSettingsPage *m_page;
|
||||||
QString m_searchKeywords;
|
QString m_searchKeywords;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/mimedatabase.h>
|
#include <coreplugin/mimedatabase.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <texteditor/completionsettings.h>
|
||||||
#include <texteditor/itexteditor.h>
|
#include <texteditor/itexteditor.h>
|
||||||
#include <texteditor/itexteditable.h>
|
#include <texteditor/itexteditable.h>
|
||||||
#include <texteditor/basetexteditor.h>
|
#include <texteditor/basetexteditor.h>
|
||||||
@@ -435,10 +436,6 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager)
|
|||||||
m_manager(manager),
|
m_manager(manager),
|
||||||
m_editor(0),
|
m_editor(0),
|
||||||
m_startPosition(-1),
|
m_startPosition(-1),
|
||||||
m_caseSensitivity(FirstLetterCaseSensitive),
|
|
||||||
m_autoInsertBrackets(true),
|
|
||||||
m_partialCompletionEnabled(true),
|
|
||||||
m_spaceAfterFunctionName(false),
|
|
||||||
m_forcedCompletion(false),
|
m_forcedCompletion(false),
|
||||||
m_completionOperator(T_EOF_SYMBOL),
|
m_completionOperator(T_EOF_SYMBOL),
|
||||||
m_objcEnabled(true)
|
m_objcEnabled(true)
|
||||||
@@ -450,46 +447,6 @@ QIcon CppCodeCompletion::iconForSymbol(Symbol *symbol) const
|
|||||||
return m_icons.iconForSymbol(symbol);
|
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.
|
Searches backwards for an access operator.
|
||||||
*/
|
*/
|
||||||
@@ -1459,7 +1416,7 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_completionOperator != T_LPAREN) {
|
if (m_completionOperator != T_LPAREN) {
|
||||||
filter(m_completions, completions, key, m_caseSensitivity);
|
filter(m_completions, completions, key);
|
||||||
|
|
||||||
} else if (m_completionOperator == T_LPAREN ||
|
} else if (m_completionOperator == T_LPAREN ||
|
||||||
m_completionOperator == T_SIGNAL ||
|
m_completionOperator == T_SIGNAL ||
|
||||||
@@ -1537,7 +1494,9 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
|
|||||||
//qDebug() << "current symbol:" << overview.prettyName(symbol->name())
|
//qDebug() << "current symbol:" << overview.prettyName(symbol->name())
|
||||||
//<< overview.prettyType(symbol->type());
|
//<< 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 (Function *function = symbol->type()->asFunctionType()) {
|
||||||
// If the member is a function, automatically place the opening parenthesis,
|
// If the member is a function, automatically place the opening parenthesis,
|
||||||
// except when it might take template parameters.
|
// except when it might take template parameters.
|
||||||
@@ -1550,7 +1509,7 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
|
|||||||
extraChars += QLatin1Char('<');
|
extraChars += QLatin1Char('<');
|
||||||
}
|
}
|
||||||
} else if (! function->isAmbiguous()) {
|
} else if (! function->isAmbiguous()) {
|
||||||
if (m_spaceAfterFunctionName)
|
if (completionSettings().m_spaceAfterFunctionName)
|
||||||
extraChars += QLatin1Char(' ');
|
extraChars += QLatin1Char(' ');
|
||||||
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
|
// everything from the closing parenthesis on are extra chars, to
|
||||||
// make sure an auto-inserted ")" gets replaced by ") const" if necessary
|
// make sure an auto-inserted ")" gets replaced by ") const" if necessary
|
||||||
int closingParen = toInsert.lastIndexOf(QLatin1Char(')'));
|
int closingParen = toInsert.lastIndexOf(QLatin1Char(')'));
|
||||||
@@ -1614,7 +1573,7 @@ bool CppCodeCompletion::partiallyComplete(const QList<TextEditor::CompletionItem
|
|||||||
} else if (completionItems.count() == 1) {
|
} else if (completionItems.count() == 1) {
|
||||||
complete(completionItems.first());
|
complete(completionItems.first());
|
||||||
return true;
|
return true;
|
||||||
} else if (m_partialCompletionEnabled && m_completionOperator != T_LPAREN) {
|
} else if (m_completionOperator != T_LPAREN) {
|
||||||
return TextEditor::ICompletionCollector::partiallyComplete(completionItems);
|
return TextEditor::ICompletionCollector::partiallyComplete(completionItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,18 +79,6 @@ public:
|
|||||||
|
|
||||||
QIcon iconForSymbol(CPlusPlus::Symbol *symbol) const;
|
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:
|
private:
|
||||||
void addKeywords();
|
void addKeywords();
|
||||||
void addMacros(const QString &fileName, const CPlusPlus::Snapshot &snapshot);
|
void addMacros(const QString &fileName, const CPlusPlus::Snapshot &snapshot);
|
||||||
@@ -152,10 +140,6 @@ 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
|
||||||
|
|
||||||
CaseSensitivity m_caseSensitivity;
|
|
||||||
bool m_autoInsertBrackets;
|
|
||||||
bool m_partialCompletionEnabled;
|
|
||||||
bool m_spaceAfterFunctionName;
|
|
||||||
bool m_forcedCompletion;
|
bool m_forcedCompletion;
|
||||||
unsigned m_completionOperator;
|
unsigned m_completionOperator;
|
||||||
bool m_objcEnabled;
|
bool m_objcEnabled;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@
|
|||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
#include <coreplugin/vcsmanager.h>
|
#include <coreplugin/vcsmanager.h>
|
||||||
#include <coreplugin/filemanager.h>
|
#include <coreplugin/filemanager.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <cppeditor/cppeditorconstants.h>
|
#include <cppeditor/cppeditorconstants.h>
|
||||||
|
|
||||||
#include <QtCore/QtConcurrentRun>
|
#include <QtCore/QtConcurrentRun>
|
||||||
@@ -109,8 +110,8 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
m_modelManager, SLOT(updateSourceFiles(QStringList)));
|
m_modelManager, SLOT(updateSourceFiles(QStringList)));
|
||||||
addAutoReleasedObject(m_modelManager);
|
addAutoReleasedObject(m_modelManager);
|
||||||
|
|
||||||
m_completion = new CppCodeCompletion(m_modelManager);
|
CppCodeCompletion *completion = new CppCodeCompletion(m_modelManager);
|
||||||
addAutoReleasedObject(m_completion);
|
addAutoReleasedObject(completion);
|
||||||
|
|
||||||
CppLocatorFilter *locatorFilter = new CppLocatorFilter(m_modelManager,
|
CppLocatorFilter *locatorFilter = new CppLocatorFilter(m_modelManager,
|
||||||
core->editorManager());
|
core->editorManager());
|
||||||
@@ -118,7 +119,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
addAutoReleasedObject(new CppClassesFilter(m_modelManager, core->editorManager()));
|
addAutoReleasedObject(new CppClassesFilter(m_modelManager, core->editorManager()));
|
||||||
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, core->editorManager()));
|
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, core->editorManager()));
|
||||||
addAutoReleasedObject(new CppCurrentDocumentFilter(m_modelManager, core->editorManager()));
|
addAutoReleasedObject(new CppCurrentDocumentFilter(m_modelManager, core->editorManager()));
|
||||||
addAutoReleasedObject(new CompletionSettingsPage(m_completion));
|
addAutoReleasedObject(new CompletionSettingsPage);
|
||||||
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
|
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
|
||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
@@ -139,17 +140,11 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
mcpptools->addAction(command);
|
mcpptools->addAction(command);
|
||||||
connect(switchAction, SIGNAL(triggered()), this, SLOT(switchHeaderSource()));
|
connect(switchAction, SIGNAL(triggered()), this, SLOT(switchHeaderSource()));
|
||||||
|
|
||||||
// Restore settings
|
// Set completion settings and keep them up to date
|
||||||
QSettings *settings = Core::ICore::instance()->settings();
|
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
|
||||||
settings->beginGroup(QLatin1String("CppTools"));
|
completion->setCompletionSettings(textEditorSettings->completionSettings());
|
||||||
settings->beginGroup(QLatin1String("Completion"));
|
connect(textEditorSettings, SIGNAL(completionSettingsChanged(TextEditor::CompletionSettings)),
|
||||||
const int caseSensitivity = settings->value(QLatin1String("CaseSensitivity"), m_completion->caseSensitivity()).toInt();
|
completion, SLOT(setCompletionSettings(TextEditor::CompletionSettings)));
|
||||||
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();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -170,16 +165,6 @@ void CppToolsPlugin::extensionsInitialized()
|
|||||||
|
|
||||||
void CppToolsPlugin::aboutToShutdown()
|
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()
|
void CppToolsPlugin::switchHeaderSource()
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ QT_END_NAMESPACE
|
|||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CppCodeCompletion;
|
|
||||||
class CppModelManager;
|
class CppModelManager;
|
||||||
struct CppFileSettings;
|
struct CppFileSettings;
|
||||||
|
|
||||||
@@ -79,7 +78,6 @@ private:
|
|||||||
|
|
||||||
int m_context;
|
int m_context;
|
||||||
CppModelManager *m_modelManager;
|
CppModelManager *m_modelManager;
|
||||||
CppCodeCompletion *m_completion;
|
|
||||||
QSharedPointer<CppFileSettings> m_fileSettings;
|
QSharedPointer<CppFileSettings> m_fileSettings;
|
||||||
|
|
||||||
static CppToolsPlugin *m_instance;
|
static CppToolsPlugin *m_instance;
|
||||||
|
|||||||
@@ -477,8 +477,7 @@ CodeCompletion::CodeCompletion(ModelManagerInterface *modelManager, QObject *par
|
|||||||
: TextEditor::ICompletionCollector(parent),
|
: TextEditor::ICompletionCollector(parent),
|
||||||
m_modelManager(modelManager),
|
m_modelManager(modelManager),
|
||||||
m_editor(0),
|
m_editor(0),
|
||||||
m_startPosition(0),
|
m_startPosition(0)
|
||||||
m_caseSensitivity(Qt::CaseSensitive)
|
|
||||||
{
|
{
|
||||||
Q_ASSERT(modelManager);
|
Q_ASSERT(modelManager);
|
||||||
}
|
}
|
||||||
@@ -486,12 +485,6 @@ CodeCompletion::CodeCompletion(ModelManagerInterface *modelManager, QObject *par
|
|||||||
CodeCompletion::~CodeCompletion()
|
CodeCompletion::~CodeCompletion()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Qt::CaseSensitivity CodeCompletion::caseSensitivity() const
|
|
||||||
{ return m_caseSensitivity; }
|
|
||||||
|
|
||||||
void CodeCompletion::setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
|
|
||||||
{ m_caseSensitivity = caseSensitivity; }
|
|
||||||
|
|
||||||
TextEditor::ITextEditable *CodeCompletion::editor() const
|
TextEditor::ITextEditable *CodeCompletion::editor() const
|
||||||
{ return m_editor; }
|
{ return m_editor; }
|
||||||
|
|
||||||
@@ -854,7 +847,7 @@ void CodeCompletion::completions(QList<TextEditor::CompletionItem> *completions)
|
|||||||
else if (length > 0) {
|
else if (length > 0) {
|
||||||
const QString key = m_editor->textAt(m_startPosition, length);
|
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 (completions->size() == 1) {
|
||||||
if (key == completions->first().text)
|
if (key == completions->first().text)
|
||||||
|
|||||||
@@ -55,9 +55,6 @@ public:
|
|||||||
CodeCompletion(ModelManagerInterface *modelManager, QObject *parent = 0);
|
CodeCompletion(ModelManagerInterface *modelManager, QObject *parent = 0);
|
||||||
virtual ~CodeCompletion();
|
virtual ~CodeCompletion();
|
||||||
|
|
||||||
Qt::CaseSensitivity caseSensitivity() const;
|
|
||||||
void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
|
|
||||||
|
|
||||||
virtual TextEditor::ITextEditable *editor() const;
|
virtual TextEditor::ITextEditable *editor() const;
|
||||||
virtual int startPosition() const;
|
virtual int startPosition() const;
|
||||||
virtual bool shouldRestartCompletion();
|
virtual bool shouldRestartCompletion();
|
||||||
@@ -81,7 +78,6 @@ private:
|
|||||||
TextEditor::ITextEditable *m_editor;
|
TextEditor::ITextEditable *m_editor;
|
||||||
int m_startPosition;
|
int m_startPosition;
|
||||||
QList<TextEditor::CompletionItem> m_completions;
|
QList<TextEditor::CompletionItem> m_completions;
|
||||||
Qt::CaseSensitivity m_caseSensitivity;
|
|
||||||
|
|
||||||
QList<TextEditor::CompletionItem> m_snippets;
|
QList<TextEditor::CompletionItem> m_snippets;
|
||||||
QDateTime m_snippetFileLastModified;
|
QDateTime m_snippetFileLastModified;
|
||||||
|
|||||||
@@ -77,8 +77,7 @@ QmlJSEditorPlugin::QmlJSEditorPlugin() :
|
|||||||
m_modelManager(0),
|
m_modelManager(0),
|
||||||
m_wizard(0),
|
m_wizard(0),
|
||||||
m_editor(0),
|
m_editor(0),
|
||||||
m_actionHandler(0),
|
m_actionHandler(0)
|
||||||
m_completion(0)
|
|
||||||
{
|
{
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
}
|
}
|
||||||
@@ -148,19 +147,16 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
|||||||
cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
||||||
contextMenu->addAction(cmd);
|
contextMenu->addAction(cmd);
|
||||||
|
|
||||||
m_completion = new CodeCompletion(m_modelManager);
|
CodeCompletion *completion = new CodeCompletion(m_modelManager);
|
||||||
addAutoReleasedObject(m_completion);
|
addAutoReleasedObject(completion);
|
||||||
|
|
||||||
addAutoReleasedObject(new HoverHandler());
|
addAutoReleasedObject(new HoverHandler);
|
||||||
|
|
||||||
// Restore settings
|
// Set completion settings and keep them up to date
|
||||||
QSettings *settings = Core::ICore::instance()->settings();
|
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
|
||||||
settings->beginGroup(QLatin1String("CppTools")); // ### FIXME:
|
completion->setCompletionSettings(textEditorSettings->completionSettings());
|
||||||
settings->beginGroup(QLatin1String("Completion"));
|
connect(textEditorSettings, SIGNAL(completionSettingsChanged(TextEditor::CompletionSettings)),
|
||||||
const bool caseSensitive = settings->value(QLatin1String("CaseSensitive"), true).toBool();
|
completion, SLOT(setCompletionSettings(TextEditor::CompletionSettings)));
|
||||||
m_completion->setCaseSensitivity(caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
|
||||||
settings->endGroup();
|
|
||||||
settings->endGroup();
|
|
||||||
|
|
||||||
error_message->clear();
|
error_message->clear();
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ class QmlFileWizard;
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class QmlJSEditorFactory;
|
class QmlJSEditorFactory;
|
||||||
class CodeCompletion;
|
|
||||||
class QmlJSTextEditor;
|
class QmlJSTextEditor;
|
||||||
class QmlJSPreviewRunner;
|
class QmlJSPreviewRunner;
|
||||||
|
|
||||||
@@ -92,7 +91,6 @@ private:
|
|||||||
QmlFileWizard *m_wizard;
|
QmlFileWizard *m_wizard;
|
||||||
QmlJSEditorFactory *m_editor;
|
QmlJSEditorFactory *m_editor;
|
||||||
TextEditor::TextEditorActionHandler *m_actionHandler;
|
TextEditor::TextEditorActionHandler *m_actionHandler;
|
||||||
CodeCompletion *m_completion;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
86
src/plugins/texteditor/completionsettings.cpp
Normal file
86
src/plugins/texteditor/completionsettings.cpp
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** 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
|
||||||
|
;
|
||||||
|
}
|
||||||
70
src/plugins/texteditor/completionsettings.h
Normal file
70
src/plugins/texteditor/completionsettings.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "icompletioncollector.h"
|
||||||
|
|
||||||
|
#include "completionsettings.h"
|
||||||
#include "itexteditable.h"
|
#include "itexteditable.h"
|
||||||
|
|
||||||
#include <QtCore/QRegExp>
|
#include <QtCore/QRegExp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace TextEditor;
|
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)
|
bool ICompletionCollector::compareChar(const QChar &l, const QChar &r)
|
||||||
{
|
{
|
||||||
@@ -62,6 +78,27 @@ bool ICompletionCollector::completionItemLessThan(const CompletionItem &i1, cons
|
|||||||
return lessThan(lower1, lower2);
|
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> ICompletionCollector::getCompletions()
|
||||||
{
|
{
|
||||||
QList<CompletionItem> completionItems;
|
QList<CompletionItem> completionItems;
|
||||||
@@ -88,6 +125,9 @@ QList<CompletionItem> ICompletionCollector::getCompletions()
|
|||||||
|
|
||||||
bool ICompletionCollector::partiallyComplete(const QList<TextEditor::CompletionItem> &completionItems)
|
bool ICompletionCollector::partiallyComplete(const QList<TextEditor::CompletionItem> &completionItems)
|
||||||
{
|
{
|
||||||
|
if (! m_d->m_completionSettings.m_partiallyComplete)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Compute common prefix
|
// Compute common prefix
|
||||||
QString firstKey = completionItems.first().text;
|
QString firstKey = completionItems.first().text;
|
||||||
QString lastKey = completionItems.last().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,
|
void ICompletionCollector::filter(const QList<TextEditor::CompletionItem> &items,
|
||||||
QList<TextEditor::CompletionItem> *filteredItems,
|
QList<TextEditor::CompletionItem> *filteredItems,
|
||||||
const QString &key,
|
const QString &key)
|
||||||
ICompletionCollector::CaseSensitivity caseSensitivity)
|
|
||||||
{
|
{
|
||||||
|
const TextEditor::CaseSensitivity caseSensitivity = m_d->m_completionSettings.m_caseSensitivity;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This code builds a regular expression in order to more intelligently match
|
* 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:
|
* 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;
|
bool first = true;
|
||||||
const QLatin1String wordContinuation("[a-z0-9_]*");
|
const QLatin1String wordContinuation("[a-z0-9_]*");
|
||||||
foreach (const QChar &c, key) {
|
foreach (const QChar &c, key) {
|
||||||
if (caseSensitivity == CaseInsensitive ||
|
if (caseSensitivity == TextEditor::CaseInsensitive ||
|
||||||
(caseSensitivity == FirstLetterCaseSensitive && !first)) {
|
(caseSensitivity == TextEditor::FirstLetterCaseSensitive && !first)) {
|
||||||
|
|
||||||
keyRegExp += QLatin1String("(?:");
|
keyRegExp += QLatin1String("(?:");
|
||||||
if (c.isUpper() && !first)
|
if (c.isUpper() && !first)
|
||||||
@@ -158,7 +199,7 @@ void ICompletionCollector::filter(const QList<TextEditor::CompletionItem> &items
|
|||||||
if (hasKey) {
|
if (hasKey) {
|
||||||
if (item.text.startsWith(key, Qt::CaseSensitive)) {
|
if (item.text.startsWith(key, Qt::CaseSensitive)) {
|
||||||
item.relevance = 2;
|
item.relevance = 2;
|
||||||
} else if (caseSensitivity != CaseSensitive
|
} else if (caseSensitivity != TextEditor::CaseSensitive
|
||||||
&& item.text.startsWith(key, Qt::CaseInsensitive)) {
|
&& item.text.startsWith(key, Qt::CaseInsensitive)) {
|
||||||
item.relevance = 1;
|
item.relevance = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,13 @@
|
|||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
class ICompletionCollectorPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
class ICompletionCollector;
|
class ICompletionCollector;
|
||||||
class ITextEditable;
|
class ITextEditable;
|
||||||
|
struct CompletionSettings;
|
||||||
|
|
||||||
struct CompletionItem
|
struct CompletionItem
|
||||||
{
|
{
|
||||||
@@ -73,8 +78,10 @@ class TEXTEDITOR_EXPORT ICompletionCollector : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ICompletionCollector(QObject *parent = 0) : QObject(parent) {}
|
ICompletionCollector(QObject *parent = 0);
|
||||||
virtual ~ICompletionCollector() {}
|
virtual ~ICompletionCollector();
|
||||||
|
|
||||||
|
const CompletionSettings &completionSettings() const;
|
||||||
|
|
||||||
virtual QList<CompletionItem> getCompletions();
|
virtual QList<CompletionItem> getCompletions();
|
||||||
virtual bool shouldRestartCompletion();
|
virtual bool shouldRestartCompletion();
|
||||||
@@ -120,21 +127,20 @@ public:
|
|||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
|
|
||||||
enum CaseSensitivity {
|
|
||||||
CaseInsensitive,
|
|
||||||
CaseSensitive,
|
|
||||||
FirstLetterCaseSensitive
|
|
||||||
};
|
|
||||||
|
|
||||||
void filter(const QList<TextEditor::CompletionItem> &items,
|
void filter(const QList<TextEditor::CompletionItem> &items,
|
||||||
QList<TextEditor::CompletionItem> *filteredItems,
|
QList<TextEditor::CompletionItem> *filteredItems,
|
||||||
const QString &key,
|
const QString &key);
|
||||||
CaseSensitivity caseSensitivity);
|
|
||||||
|
public slots:
|
||||||
|
void setCompletionSettings(const TextEditor::CompletionSettings &);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static bool compareChar(const QChar &item, const QChar &other);
|
static bool compareChar(const QChar &item, const QChar &other);
|
||||||
static bool lessThan(const QString &item, const QString &other);
|
static bool lessThan(const QString &item, const QString &other);
|
||||||
static bool completionItemLessThan(const CompletionItem &item, const CompletionItem &other);
|
static bool completionItemLessThan(const CompletionItem &item, const CompletionItem &other);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Internal::ICompletionCollectorPrivate *m_d;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT IQuickFixCollector : public ICompletionCollector
|
class TEXTEDITOR_EXPORT IQuickFixCollector : public ICompletionCollector
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ SOURCES += texteditorplugin.cpp \
|
|||||||
itexteditor.cpp \
|
itexteditor.cpp \
|
||||||
texteditoroverlay.cpp \
|
texteditoroverlay.cpp \
|
||||||
texteditoroptionspage.cpp \
|
texteditoroptionspage.cpp \
|
||||||
basetextdocumentlayout.cpp
|
basetextdocumentlayout.cpp \
|
||||||
|
completionsettings.cpp
|
||||||
|
|
||||||
HEADERS += texteditorplugin.h \
|
HEADERS += texteditorplugin.h \
|
||||||
textfilewizard.h \
|
textfilewizard.h \
|
||||||
@@ -71,7 +72,8 @@ HEADERS += texteditorplugin.h \
|
|||||||
colorschemeedit.h \
|
colorschemeedit.h \
|
||||||
texteditoroverlay.h \
|
texteditoroverlay.h \
|
||||||
texteditoroptionspage.h \
|
texteditoroptionspage.h \
|
||||||
basetextdocumentlayout.h
|
basetextdocumentlayout.h \
|
||||||
|
completionsettings.h
|
||||||
|
|
||||||
|
|
||||||
FORMS += behaviorsettingspage.ui \
|
FORMS += behaviorsettingspage.ui \
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include "basetexteditor.h"
|
#include "basetexteditor.h"
|
||||||
#include "behaviorsettings.h"
|
#include "behaviorsettings.h"
|
||||||
#include "behaviorsettingspage.h"
|
#include "behaviorsettingspage.h"
|
||||||
|
#include "completionsettings.h"
|
||||||
#include "displaysettings.h"
|
#include "displaysettings.h"
|
||||||
#include "displaysettingspage.h"
|
#include "displaysettingspage.h"
|
||||||
#include "fontsettingspage.h"
|
#include "fontsettingspage.h"
|
||||||
@@ -41,17 +42,54 @@
|
|||||||
#include "texteditorplugin.h"
|
#include "texteditorplugin.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
using namespace TextEditor::Constants;
|
using namespace TextEditor::Constants;
|
||||||
|
using namespace TextEditor::Internal;
|
||||||
|
|
||||||
|
namespace TextEditor {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class TextEditorSettingsPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FontSettingsPage *m_fontSettingsPage;
|
||||||
|
BehaviorSettingsPage *m_behaviorSettingsPage;
|
||||||
|
DisplaySettingsPage *m_displaySettingsPage;
|
||||||
|
|
||||||
|
CompletionSettings m_completionSettings;
|
||||||
|
|
||||||
|
void fontZoomRequested(int pointSize);
|
||||||
|
void zoomResetRequested();
|
||||||
|
};
|
||||||
|
|
||||||
|
void TextEditorSettingsPrivate::fontZoomRequested(int zoom)
|
||||||
|
{
|
||||||
|
FontSettings &fs = const_cast<FontSettings&>(m_fontSettingsPage->fontSettings());
|
||||||
|
fs.setFontZoom(qMax(10, fs.fontZoom() + zoom));
|
||||||
|
m_fontSettingsPage->saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextEditorSettingsPrivate::zoomResetRequested()
|
||||||
|
{
|
||||||
|
FontSettings &fs = const_cast<FontSettings&>(m_fontSettingsPage->fontSettings());
|
||||||
|
fs.setFontZoom(100);
|
||||||
|
m_fontSettingsPage->saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace TextEditor
|
||||||
|
|
||||||
|
|
||||||
TextEditorSettings *TextEditorSettings::m_instance = 0;
|
TextEditorSettings *TextEditorSettings::m_instance = 0;
|
||||||
|
|
||||||
TextEditorSettings::TextEditorSettings(QObject *parent)
|
TextEditorSettings::TextEditorSettings(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
, m_d(new Internal::TextEditorSettingsPrivate)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!m_instance, return);
|
QTC_ASSERT(!m_instance, return);
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
@@ -102,44 +140,50 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
|
|||||||
formatDescriptions.append(FormatDescription(QLatin1String(C_DIFF_FILE), tr("Diff File"), Qt::darkBlue));
|
formatDescriptions.append(FormatDescription(QLatin1String(C_DIFF_FILE), tr("Diff File"), Qt::darkBlue));
|
||||||
formatDescriptions.append(FormatDescription(QLatin1String(C_DIFF_LOCATION), tr("Diff Location"), Qt::blue));
|
formatDescriptions.append(FormatDescription(QLatin1String(C_DIFF_LOCATION), tr("Diff Location"), Qt::blue));
|
||||||
|
|
||||||
m_fontSettingsPage = new FontSettingsPage(formatDescriptions,
|
m_d->m_fontSettingsPage = new FontSettingsPage(formatDescriptions,
|
||||||
QLatin1String("A.FontSettings"),
|
QLatin1String("A.FontSettings"),
|
||||||
this);
|
this);
|
||||||
pm->addObject(m_fontSettingsPage);
|
pm->addObject(m_d->m_fontSettingsPage);
|
||||||
|
|
||||||
// Add the GUI used to configure the tab, storage and interaction settings
|
// Add the GUI used to configure the tab, storage and interaction settings
|
||||||
TextEditor::BehaviorSettingsPageParameters behaviorSettingsPageParameters;
|
TextEditor::BehaviorSettingsPageParameters behaviorSettingsPageParameters;
|
||||||
behaviorSettingsPageParameters.id = QLatin1String("B.BehaviourSettings");
|
behaviorSettingsPageParameters.id = QLatin1String("B.BehaviourSettings");
|
||||||
behaviorSettingsPageParameters.displayName = tr("Behavior");
|
behaviorSettingsPageParameters.displayName = tr("Behavior");
|
||||||
behaviorSettingsPageParameters.settingsPrefix = QLatin1String("text");
|
behaviorSettingsPageParameters.settingsPrefix = QLatin1String("text");
|
||||||
m_behaviorSettingsPage = new BehaviorSettingsPage(behaviorSettingsPageParameters, this);
|
m_d->m_behaviorSettingsPage = new BehaviorSettingsPage(behaviorSettingsPageParameters, this);
|
||||||
pm->addObject(m_behaviorSettingsPage);
|
pm->addObject(m_d->m_behaviorSettingsPage);
|
||||||
|
|
||||||
TextEditor::DisplaySettingsPageParameters displaySettingsPageParameters;
|
TextEditor::DisplaySettingsPageParameters displaySettingsPageParameters;
|
||||||
displaySettingsPageParameters.id = QLatin1String("D.DisplaySettings"),
|
displaySettingsPageParameters.id = QLatin1String("D.DisplaySettings"),
|
||||||
displaySettingsPageParameters.displayName = tr("Display");
|
displaySettingsPageParameters.displayName = tr("Display");
|
||||||
displaySettingsPageParameters.settingsPrefix = QLatin1String("text");
|
displaySettingsPageParameters.settingsPrefix = QLatin1String("text");
|
||||||
m_displaySettingsPage = new DisplaySettingsPage(displaySettingsPageParameters, this);
|
m_d->m_displaySettingsPage = new DisplaySettingsPage(displaySettingsPageParameters, this);
|
||||||
pm->addObject(m_displaySettingsPage);
|
pm->addObject(m_d->m_displaySettingsPage);
|
||||||
|
|
||||||
connect(m_fontSettingsPage, SIGNAL(changed(TextEditor::FontSettings)),
|
connect(m_d->m_fontSettingsPage, SIGNAL(changed(TextEditor::FontSettings)),
|
||||||
this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)));
|
this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)));
|
||||||
connect(m_behaviorSettingsPage, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
|
connect(m_d->m_behaviorSettingsPage, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
|
||||||
this, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)));
|
this, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)));
|
||||||
connect(m_behaviorSettingsPage, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
|
connect(m_d->m_behaviorSettingsPage, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
|
||||||
this, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)));
|
this, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)));
|
||||||
connect(m_behaviorSettingsPage, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
|
connect(m_d->m_behaviorSettingsPage, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
|
||||||
this, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)));
|
this, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)));
|
||||||
connect(m_displaySettingsPage, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
|
connect(m_d->m_displaySettingsPage, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
|
||||||
this, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)));
|
this, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)));
|
||||||
|
|
||||||
|
// TODO: Move these settings to TextEditor category
|
||||||
|
if (QSettings *s = Core::ICore::instance()->settings())
|
||||||
|
m_d->m_completionSettings.fromSettings(QLatin1String("CppTools/"), s);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorSettings::~TextEditorSettings()
|
TextEditorSettings::~TextEditorSettings()
|
||||||
{
|
{
|
||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||||
pm->removeObject(m_fontSettingsPage);
|
pm->removeObject(m_d->m_fontSettingsPage);
|
||||||
pm->removeObject(m_behaviorSettingsPage);
|
pm->removeObject(m_d->m_behaviorSettingsPage);
|
||||||
pm->removeObject(m_displaySettingsPage);
|
pm->removeObject(m_d->m_displaySettingsPage);
|
||||||
|
|
||||||
|
delete m_d;
|
||||||
|
|
||||||
m_instance = 0;
|
m_instance = 0;
|
||||||
}
|
}
|
||||||
@@ -181,41 +225,46 @@ void TextEditorSettings::initializeEditor(BaseTextEditor *editor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TextEditorSettings::fontZoomRequested(int zoom)
|
|
||||||
{
|
|
||||||
FontSettings &fs = const_cast<FontSettings&>(fontSettings());
|
|
||||||
fs.setFontZoom(qMax(10, fs.fontZoom() + zoom));
|
|
||||||
m_fontSettingsPage->saveSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextEditorSettings::zoomResetRequested()
|
|
||||||
{
|
|
||||||
FontSettings &fs = const_cast<FontSettings&>(fontSettings());
|
|
||||||
fs.setFontZoom(100);
|
|
||||||
m_fontSettingsPage->saveSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
const FontSettings &TextEditorSettings::fontSettings() const
|
const FontSettings &TextEditorSettings::fontSettings() const
|
||||||
{
|
{
|
||||||
return m_fontSettingsPage->fontSettings();
|
return m_d->m_fontSettingsPage->fontSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
const TabSettings &TextEditorSettings::tabSettings() const
|
const TabSettings &TextEditorSettings::tabSettings() const
|
||||||
{
|
{
|
||||||
return m_behaviorSettingsPage->tabSettings();
|
return m_d->m_behaviorSettingsPage->tabSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
const StorageSettings &TextEditorSettings::storageSettings() const
|
const StorageSettings &TextEditorSettings::storageSettings() const
|
||||||
{
|
{
|
||||||
return m_behaviorSettingsPage->storageSettings();
|
return m_d->m_behaviorSettingsPage->storageSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
const BehaviorSettings &TextEditorSettings::behaviorSettings() const
|
const BehaviorSettings &TextEditorSettings::behaviorSettings() const
|
||||||
{
|
{
|
||||||
return m_behaviorSettingsPage->behaviorSettings();
|
return m_d->m_behaviorSettingsPage->behaviorSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
const DisplaySettings &TextEditorSettings::displaySettings() const
|
const DisplaySettings &TextEditorSettings::displaySettings() const
|
||||||
{
|
{
|
||||||
return m_displaySettingsPage->displaySettings();
|
return m_d->m_displaySettingsPage->displaySettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CompletionSettings &TextEditorSettings::completionSettings() const
|
||||||
|
{
|
||||||
|
return m_d->m_completionSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextEditorSettings::setCompletionSettings(const TextEditor::CompletionSettings &settings)
|
||||||
|
{
|
||||||
|
if (m_d->m_completionSettings == settings)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_d->m_completionSettings = settings;
|
||||||
|
if (QSettings *s = Core::ICore::instance()->settings())
|
||||||
|
m_d->m_completionSettings.toSettings(QLatin1String("CppTools/"), s);
|
||||||
|
|
||||||
|
emit completionSettingsChanged(m_d->m_completionSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "moc_texteditorsettings.cpp"
|
||||||
|
|||||||
@@ -45,11 +45,16 @@ struct TabSettings;
|
|||||||
struct StorageSettings;
|
struct StorageSettings;
|
||||||
struct BehaviorSettings;
|
struct BehaviorSettings;
|
||||||
struct DisplaySettings;
|
struct DisplaySettings;
|
||||||
|
struct CompletionSettings;
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
class TextEditorSettingsPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a central place for basic text editor settings. These
|
* This class provides a central place for basic text editor settings. These
|
||||||
* settings include font settings, tab settings, storage settings, behavior
|
* settings include font settings, tab settings, storage settings, behavior
|
||||||
* settings and display settings.
|
* settings, display settings and completion settings.
|
||||||
*/
|
*/
|
||||||
class TEXTEDITOR_EXPORT TextEditorSettings : public QObject
|
class TEXTEDITOR_EXPORT TextEditorSettings : public QObject
|
||||||
{
|
{
|
||||||
@@ -68,6 +73,9 @@ public:
|
|||||||
const StorageSettings &storageSettings() const;
|
const StorageSettings &storageSettings() const;
|
||||||
const BehaviorSettings &behaviorSettings() const;
|
const BehaviorSettings &behaviorSettings() const;
|
||||||
const DisplaySettings &displaySettings() const;
|
const DisplaySettings &displaySettings() const;
|
||||||
|
const CompletionSettings &completionSettings() const;
|
||||||
|
|
||||||
|
void setCompletionSettings(const TextEditor::CompletionSettings &);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void fontSettingsChanged(const TextEditor::FontSettings &);
|
void fontSettingsChanged(const TextEditor::FontSettings &);
|
||||||
@@ -75,15 +83,12 @@ signals:
|
|||||||
void storageSettingsChanged(const TextEditor::StorageSettings &);
|
void storageSettingsChanged(const TextEditor::StorageSettings &);
|
||||||
void behaviorSettingsChanged(const TextEditor::BehaviorSettings &);
|
void behaviorSettingsChanged(const TextEditor::BehaviorSettings &);
|
||||||
void displaySettingsChanged(const TextEditor::DisplaySettings &);
|
void displaySettingsChanged(const TextEditor::DisplaySettings &);
|
||||||
|
void completionSettingsChanged(const TextEditor::CompletionSettings &);
|
||||||
private slots:
|
|
||||||
void fontZoomRequested(int pointSize);
|
|
||||||
void zoomResetRequested();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FontSettingsPage *m_fontSettingsPage;
|
Internal::TextEditorSettingsPrivate *m_d;
|
||||||
BehaviorSettingsPage *m_behaviorSettingsPage;
|
Q_PRIVATE_SLOT(m_d, void fontZoomRequested(int pointSize));
|
||||||
DisplaySettingsPage *m_displaySettingsPage;
|
Q_PRIVATE_SLOT(m_d, void zoomResetRequested());
|
||||||
|
|
||||||
static TextEditorSettings *m_instance;
|
static TextEditorSettings *m_instance;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user