forked from qt-creator/qt-creator
Make the way completion is triggered configurable
Now it's possible to choose between having completion popup manually, when triggered or always.
This commit is contained in:
@@ -80,7 +80,21 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int completionTriggerIndex = 0;
|
||||||
|
switch (settings.m_completionTrigger) {
|
||||||
|
case TextEditor::ManualCompletion:
|
||||||
|
completionTriggerIndex = 0;
|
||||||
|
break;
|
||||||
|
case TextEditor::TriggeredCompletion:
|
||||||
|
completionTriggerIndex = 1;
|
||||||
|
break;
|
||||||
|
case TextEditor::AutomaticCompletion:
|
||||||
|
completionTriggerIndex = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex);
|
m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex);
|
||||||
|
m_page->completionTrigger->setCurrentIndex(completionTriggerIndex);
|
||||||
m_page->autoInsertBrackets->setChecked(settings.m_autoInsertBrackets);
|
m_page->autoInsertBrackets->setChecked(settings.m_autoInsertBrackets);
|
||||||
m_page->partiallyComplete->setChecked(settings.m_partiallyComplete);
|
m_page->partiallyComplete->setChecked(settings.m_partiallyComplete);
|
||||||
m_page->spaceAfterFunctionName->setChecked(settings.m_spaceAfterFunctionName);
|
m_page->spaceAfterFunctionName->setChecked(settings.m_spaceAfterFunctionName);
|
||||||
@@ -88,6 +102,7 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
|
|||||||
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()
|
||||||
|
<< ' ' << m_page->completionTriggerLabel->text()
|
||||||
<< ' ' << m_page->partiallyComplete->text()
|
<< ' ' << m_page->partiallyComplete->text()
|
||||||
<< ' ' << m_page->spaceAfterFunctionName->text();
|
<< ' ' << m_page->spaceAfterFunctionName->text();
|
||||||
m_searchKeywords.remove(QLatin1Char('&'));
|
m_searchKeywords.remove(QLatin1Char('&'));
|
||||||
@@ -100,6 +115,7 @@ void CompletionSettingsPage::apply()
|
|||||||
{
|
{
|
||||||
TextEditor::CompletionSettings settings;
|
TextEditor::CompletionSettings settings;
|
||||||
settings.m_caseSensitivity = caseSensitivity();
|
settings.m_caseSensitivity = caseSensitivity();
|
||||||
|
settings.m_completionTrigger = completionTrigger();
|
||||||
settings.m_autoInsertBrackets = m_page->autoInsertBrackets->isChecked();
|
settings.m_autoInsertBrackets = m_page->autoInsertBrackets->isChecked();
|
||||||
settings.m_partiallyComplete = m_page->partiallyComplete->isChecked();
|
settings.m_partiallyComplete = m_page->partiallyComplete->isChecked();
|
||||||
settings.m_spaceAfterFunctionName = m_page->spaceAfterFunctionName->isChecked();
|
settings.m_spaceAfterFunctionName = m_page->spaceAfterFunctionName->isChecked();
|
||||||
@@ -123,3 +139,15 @@ TextEditor::CaseSensitivity CompletionSettingsPage::caseSensitivity() const
|
|||||||
return TextEditor::FirstLetterCaseSensitive;
|
return TextEditor::FirstLetterCaseSensitive;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextEditor::CompletionTrigger CompletionSettingsPage::completionTrigger() const
|
||||||
|
{
|
||||||
|
switch (m_page->completionTrigger->currentIndex()) {
|
||||||
|
case 0:
|
||||||
|
return TextEditor::ManualCompletion;
|
||||||
|
case 1:
|
||||||
|
return TextEditor::TriggeredCompletion;
|
||||||
|
default:
|
||||||
|
return TextEditor::AutomaticCompletion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
TextEditor::CaseSensitivity caseSensitivity() const;
|
TextEditor::CaseSensitivity caseSensitivity() const;
|
||||||
|
TextEditor::CompletionTrigger completionTrigger() const;
|
||||||
|
|
||||||
Ui_CompletionSettingsPage *m_page;
|
Ui_CompletionSettingsPage *m_page;
|
||||||
QString m_searchKeywords;
|
QString m_searchKeywords;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>359</width>
|
||||||
<height>300</height>
|
<height>244</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
@@ -16,10 +16,8 @@
|
|||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Behavior</string>
|
<string>Behavior</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item>
|
<item row="0" column="0">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="caseSensitivityLabel">
|
<widget class="QLabel" name="caseSensitivityLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Case-sensitivity:</string>
|
<string>&Case-sensitivity:</string>
|
||||||
@@ -29,23 +27,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="0" column="2">
|
||||||
<spacer name="horizontalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Maximum</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QComboBox" name="caseSensitivity">
|
<widget class="QComboBox" name="caseSensitivity">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
@@ -70,22 +52,59 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="0" column="3" colspan="2">
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>0</width>
|
<width>70</width>
|
||||||
<height>0</height>
|
<height>24</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="completionTriggerLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Activate completion:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2" colspan="2">
|
||||||
|
<widget class="QComboBox" name="completionTrigger">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Manually</string>
|
||||||
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>When Triggered</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Always</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="4">
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>24</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="3">
|
||||||
<widget class="QCheckBox" name="autoInsertBrackets">
|
<widget class="QCheckBox" name="autoInsertBrackets">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Automatically insert (, ) and ; when appropriate.</string>
|
<string>Automatically insert (, ) and ; when appropriate.</string>
|
||||||
@@ -98,7 +117,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="3" column="0" colspan="3">
|
||||||
<widget class="QCheckBox" name="partiallyComplete">
|
<widget class="QCheckBox" name="partiallyComplete">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Insert the common prefix of available completion items.</string>
|
<string>Insert the common prefix of available completion items.</string>
|
||||||
@@ -111,7 +130,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="4" column="0" colspan="3">
|
||||||
<widget class="QCheckBox" name="spaceAfterFunctionName">
|
<widget class="QCheckBox" name="spaceAfterFunctionName">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
@@ -138,6 +157,10 @@
|
|||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
<zorder>groupBox</zorder>
|
||||||
|
<zorder>autoInsertBrackets</zorder>
|
||||||
|
<zorder>partiallyComplete</zorder>
|
||||||
|
<zorder>spaceAfterFunctionName</zorder>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
@@ -655,7 +655,7 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else if (completionSettings().m_completionTrigger == TextEditor::AutomaticCompletion) {
|
||||||
// Trigger completion after at least three characters of a name have been typed
|
// Trigger completion after at least three characters of a name have been typed
|
||||||
const int startOfName = findStartOfName(pos);
|
const int startOfName = findStartOfName(pos);
|
||||||
if (pos - startOfName > 2) {
|
if (pos - startOfName > 2) {
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#include <qmljs/qmljsscopebuilder.h>
|
#include <qmljs/qmljsscopebuilder.h>
|
||||||
|
|
||||||
#include <texteditor/basetexteditor.h>
|
#include <texteditor/basetexteditor.h>
|
||||||
|
#include <texteditor/completionsettings.h>
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
@@ -546,6 +547,8 @@ bool CodeCompletion::maybeTriggersCompletion(TextEditor::ITextEditable *editor)
|
|||||||
|
|
||||||
if (ch == QLatin1Char('(') || ch == QLatin1Char('.'))
|
if (ch == QLatin1Char('(') || ch == QLatin1Char('.'))
|
||||||
return true;
|
return true;
|
||||||
|
if (completionSettings().m_completionTrigger != TextEditor::AutomaticCompletion)
|
||||||
|
return false;
|
||||||
|
|
||||||
const QChar characterUnderCursor = editor->characterAt(cursorPosition);
|
const QChar characterUnderCursor = editor->characterAt(cursorPosition);
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
static const char * const groupPostfix = "Completion";
|
static const char * const groupPostfix = "Completion";
|
||||||
static const char * const caseSensitivityKey = "CaseSensitivity";
|
static const char * const caseSensitivityKey = "CaseSensitivity";
|
||||||
|
static const char * const completionTriggerKey = "CompletionTrigger";
|
||||||
static const char * const autoInsertBracesKey = "AutoInsertBraces";
|
static const char * const autoInsertBracesKey = "AutoInsertBraces";
|
||||||
static const char * const partiallyCompleteKey = "PartiallyComplete";
|
static const char * const partiallyCompleteKey = "PartiallyComplete";
|
||||||
static const char * const spaceAfterFunctionNameKey = "SpaceAfterFunctionName";
|
static const char * const spaceAfterFunctionNameKey = "SpaceAfterFunctionName";
|
||||||
@@ -41,6 +42,7 @@ using namespace TextEditor;
|
|||||||
|
|
||||||
CompletionSettings::CompletionSettings()
|
CompletionSettings::CompletionSettings()
|
||||||
: m_caseSensitivity(CaseInsensitive)
|
: m_caseSensitivity(CaseInsensitive)
|
||||||
|
, m_completionTrigger(AutomaticCompletion)
|
||||||
, m_autoInsertBrackets(true)
|
, m_autoInsertBrackets(true)
|
||||||
, m_partiallyComplete(true)
|
, m_partiallyComplete(true)
|
||||||
, m_spaceAfterFunctionName(false)
|
, m_spaceAfterFunctionName(false)
|
||||||
@@ -55,6 +57,7 @@ void CompletionSettings::toSettings(const QString &category, QSettings *s) const
|
|||||||
|
|
||||||
s->beginGroup(group);
|
s->beginGroup(group);
|
||||||
s->setValue(QLatin1String(caseSensitivityKey), (int) m_caseSensitivity);
|
s->setValue(QLatin1String(caseSensitivityKey), (int) m_caseSensitivity);
|
||||||
|
s->setValue(QLatin1String(completionTriggerKey), (int) m_completionTrigger);
|
||||||
s->setValue(QLatin1String(autoInsertBracesKey), m_autoInsertBrackets);
|
s->setValue(QLatin1String(autoInsertBracesKey), m_autoInsertBrackets);
|
||||||
s->setValue(QLatin1String(partiallyCompleteKey), m_partiallyComplete);
|
s->setValue(QLatin1String(partiallyCompleteKey), m_partiallyComplete);
|
||||||
s->setValue(QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName);
|
s->setValue(QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName);
|
||||||
@@ -71,6 +74,7 @@ void CompletionSettings::fromSettings(const QString &category, const QSettings *
|
|||||||
*this = CompletionSettings(); // Assign defaults
|
*this = CompletionSettings(); // Assign defaults
|
||||||
|
|
||||||
m_caseSensitivity = (CaseSensitivity) s->value(group + QLatin1String(caseSensitivityKey), m_caseSensitivity).toInt();
|
m_caseSensitivity = (CaseSensitivity) s->value(group + QLatin1String(caseSensitivityKey), m_caseSensitivity).toInt();
|
||||||
|
m_completionTrigger = (CompletionTrigger) s->value(group + QLatin1String(completionTriggerKey), m_completionTrigger).toInt();
|
||||||
m_autoInsertBrackets = s->value(group + QLatin1String(autoInsertBracesKey), m_autoInsertBrackets).toBool();
|
m_autoInsertBrackets = s->value(group + QLatin1String(autoInsertBracesKey), m_autoInsertBrackets).toBool();
|
||||||
m_partiallyComplete = s->value(group + QLatin1String(partiallyCompleteKey), m_partiallyComplete).toBool();
|
m_partiallyComplete = s->value(group + QLatin1String(partiallyCompleteKey), m_partiallyComplete).toBool();
|
||||||
m_spaceAfterFunctionName = s->value(group + QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName).toBool();
|
m_spaceAfterFunctionName = s->value(group + QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName).toBool();
|
||||||
@@ -79,6 +83,7 @@ void CompletionSettings::fromSettings(const QString &category, const QSettings *
|
|||||||
bool CompletionSettings::equals(const CompletionSettings &cs) const
|
bool CompletionSettings::equals(const CompletionSettings &cs) const
|
||||||
{
|
{
|
||||||
return m_caseSensitivity == cs.m_caseSensitivity
|
return m_caseSensitivity == cs.m_caseSensitivity
|
||||||
|
&& m_completionTrigger == cs.m_completionTrigger
|
||||||
&& m_autoInsertBrackets == cs.m_autoInsertBrackets
|
&& m_autoInsertBrackets == cs.m_autoInsertBrackets
|
||||||
&& m_partiallyComplete == cs.m_partiallyComplete
|
&& m_partiallyComplete == cs.m_partiallyComplete
|
||||||
&& m_spaceAfterFunctionName == cs.m_spaceAfterFunctionName
|
&& m_spaceAfterFunctionName == cs.m_spaceAfterFunctionName
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ enum CaseSensitivity {
|
|||||||
FirstLetterCaseSensitive
|
FirstLetterCaseSensitive
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum CompletionTrigger {
|
||||||
|
ManualCompletion,
|
||||||
|
TriggeredCompletion,
|
||||||
|
AutomaticCompletion
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings that describe how the code completion behaves.
|
* Settings that describe how the code completion behaves.
|
||||||
*/
|
*/
|
||||||
@@ -57,6 +63,7 @@ struct TEXTEDITOR_EXPORT CompletionSettings
|
|||||||
bool equals(const CompletionSettings &bs) const;
|
bool equals(const CompletionSettings &bs) const;
|
||||||
|
|
||||||
CaseSensitivity m_caseSensitivity;
|
CaseSensitivity m_caseSensitivity;
|
||||||
|
CompletionTrigger m_completionTrigger;
|
||||||
bool m_autoInsertBrackets;
|
bool m_autoInsertBrackets;
|
||||||
bool m_partiallyComplete;
|
bool m_partiallyComplete;
|
||||||
bool m_spaceAfterFunctionName;
|
bool m_spaceAfterFunctionName;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <texteditor/itexteditable.h>
|
#include <texteditor/itexteditable.h>
|
||||||
|
#include <texteditor/completionsettings.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
@@ -126,8 +127,13 @@ void CompletionSupport::autoComplete_helper(ITextEditable *editor, bool forced,
|
|||||||
QList<CompletionItem> completionItems;
|
QList<CompletionItem> completionItems;
|
||||||
|
|
||||||
if (!m_completionList) {
|
if (!m_completionList) {
|
||||||
if (!forced && !m_completionCollector->triggersCompletion(editor))
|
if (!forced) {
|
||||||
|
const CompletionSettings &completionSettings = m_completionCollector->completionSettings();
|
||||||
|
if (completionSettings.m_completionTrigger == ManualCompletion)
|
||||||
return;
|
return;
|
||||||
|
if (!m_completionCollector->triggersCompletion(editor))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_startPosition = m_completionCollector->startCompletion(editor);
|
m_startPosition = m_completionCollector->startCompletion(editor);
|
||||||
completionItems = getCompletions();
|
completionItems = getCompletions();
|
||||||
|
|||||||
Reference in New Issue
Block a user