Commit e101d8ec authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Make the way completion is triggered configurable

Now it's possible to choose between having completion popup manually,
when triggered or always.
parent 2c51e0c9
......@@ -80,7 +80,21 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
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->completionTrigger->setCurrentIndex(completionTriggerIndex);
m_page->autoInsertBrackets->setChecked(settings.m_autoInsertBrackets);
m_page->partiallyComplete->setChecked(settings.m_partiallyComplete);
m_page->spaceAfterFunctionName->setChecked(settings.m_spaceAfterFunctionName);
......@@ -88,8 +102,9 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
if (m_searchKeywords.isEmpty()) {
QTextStream(&m_searchKeywords) << m_page->caseSensitivityLabel->text()
<< ' ' << m_page->autoInsertBrackets->text()
<< ' ' << m_page->partiallyComplete->text()
<< ' ' << m_page->spaceAfterFunctionName->text();
<< ' ' << m_page->completionTriggerLabel->text()
<< ' ' << m_page->partiallyComplete->text()
<< ' ' << m_page->spaceAfterFunctionName->text();
m_searchKeywords.remove(QLatin1Char('&'));
}
......@@ -100,6 +115,7 @@ void CompletionSettingsPage::apply()
{
TextEditor::CompletionSettings settings;
settings.m_caseSensitivity = caseSensitivity();
settings.m_completionTrigger = completionTrigger();
settings.m_autoInsertBrackets = m_page->autoInsertBrackets->isChecked();
settings.m_partiallyComplete = m_page->partiallyComplete->isChecked();
settings.m_spaceAfterFunctionName = m_page->spaceAfterFunctionName->isChecked();
......@@ -123,3 +139,15 @@ TextEditor::CaseSensitivity CompletionSettingsPage::caseSensitivity() const
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:
TextEditor::CaseSensitivity caseSensitivity() const;
TextEditor::CompletionTrigger completionTrigger() const;
Ui_CompletionSettingsPage *m_page;
QString m_searchKeywords;
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>359</width>
<height>244</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
......@@ -16,76 +16,95 @@
<property name="title">
<string>Behavior</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="caseSensitivityLabel">
<property name="text">
<string>&amp;Case-sensitivity:</string>
</property>
<property name="buddy">
<cstring>caseSensitivity</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="caseSensitivity">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<widget class="QLabel" name="caseSensitivityLabel">
<property name="text">
<string>&amp;Case-sensitivity:</string>
</property>
<property name="buddy">
<cstring>caseSensitivity</cstring>
</property>
</widget>
<property name="text">
<string>Full</string>
</property>
</item>
<item>
<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>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<widget class="QComboBox" name="caseSensitivity">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Full</string>
</property>
</item>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>First Letter</string>
</property>
</item>
</widget>
<property name="text">
<string>First Letter</string>
</property>
</item>
</widget>
</item>
<item row="0" column="3" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>70</width>
<height>24</height>
</size>
</property>
</spacer>
</item>
<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>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
<property name="text">
<string>Manually</string>
</property>
</item>
</layout>
<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>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="autoInsertBrackets">
<property name="toolTip">
<string>Automatically insert (, ) and ; when appropriate.</string>
......@@ -98,7 +117,7 @@
</property>
</widget>
</item>
<item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="partiallyComplete">
<property name="toolTip">
<string>Insert the common prefix of available completion items.</string>
......@@ -111,7 +130,7 @@
</property>
</widget>
</item>
<item>
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="spaceAfterFunctionName">
<property name="enabled">
<bool>true</bool>
......@@ -138,6 +157,10 @@
</spacer>
</item>
</layout>
<zorder>groupBox</zorder>
<zorder>autoInsertBrackets</zorder>
<zorder>partiallyComplete</zorder>
<zorder>spaceAfterFunctionName</zorder>
</widget>
<resources/>
<connections/>
......
......@@ -655,7 +655,7 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
}
return true;
} else {
} else if (completionSettings().m_completionTrigger == TextEditor::AutomaticCompletion) {
// Trigger completion after at least three characters of a name have been typed
const int startOfName = findStartOfName(pos);
if (pos - startOfName > 2) {
......
......@@ -40,6 +40,7 @@
#include <qmljs/qmljsscopebuilder.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/completionsettings.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
......@@ -546,6 +547,8 @@ bool CodeCompletion::maybeTriggersCompletion(TextEditor::ITextEditable *editor)
if (ch == QLatin1Char('(') || ch == QLatin1Char('.'))
return true;
if (completionSettings().m_completionTrigger != TextEditor::AutomaticCompletion)
return false;
const QChar characterUnderCursor = editor->characterAt(cursorPosition);
......
......@@ -33,6 +33,7 @@
static const char * const groupPostfix = "Completion";
static const char * const caseSensitivityKey = "CaseSensitivity";
static const char * const completionTriggerKey = "CompletionTrigger";
static const char * const autoInsertBracesKey = "AutoInsertBraces";
static const char * const partiallyCompleteKey = "PartiallyComplete";
static const char * const spaceAfterFunctionNameKey = "SpaceAfterFunctionName";
......@@ -41,6 +42,7 @@ using namespace TextEditor;
CompletionSettings::CompletionSettings()
: m_caseSensitivity(CaseInsensitive)
, m_completionTrigger(AutomaticCompletion)
, m_autoInsertBrackets(true)
, m_partiallyComplete(true)
, m_spaceAfterFunctionName(false)
......@@ -55,6 +57,7 @@ void CompletionSettings::toSettings(const QString &category, QSettings *s) const
s->beginGroup(group);
s->setValue(QLatin1String(caseSensitivityKey), (int) m_caseSensitivity);
s->setValue(QLatin1String(completionTriggerKey), (int) m_completionTrigger);
s->setValue(QLatin1String(autoInsertBracesKey), m_autoInsertBrackets);
s->setValue(QLatin1String(partiallyCompleteKey), m_partiallyComplete);
s->setValue(QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName);
......@@ -71,6 +74,7 @@ void CompletionSettings::fromSettings(const QString &category, const QSettings *
*this = CompletionSettings(); // Assign defaults
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_partiallyComplete = s->value(group + QLatin1String(partiallyCompleteKey), m_partiallyComplete).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
{
return m_caseSensitivity == cs.m_caseSensitivity
&& m_completionTrigger == cs.m_completionTrigger
&& m_autoInsertBrackets == cs.m_autoInsertBrackets
&& m_partiallyComplete == cs.m_partiallyComplete
&& m_spaceAfterFunctionName == cs.m_spaceAfterFunctionName
......
......@@ -44,6 +44,12 @@ enum CaseSensitivity {
FirstLetterCaseSensitive
};
enum CompletionTrigger {
ManualCompletion,
TriggeredCompletion,
AutomaticCompletion
};
/**
* Settings that describe how the code completion behaves.
*/
......@@ -57,6 +63,7 @@ struct TEXTEDITOR_EXPORT CompletionSettings
bool equals(const CompletionSettings &bs) const;
CaseSensitivity m_caseSensitivity;
CompletionTrigger m_completionTrigger;
bool m_autoInsertBrackets;
bool m_partiallyComplete;
bool m_spaceAfterFunctionName;
......
......@@ -34,6 +34,7 @@
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/itexteditable.h>
#include <texteditor/completionsettings.h>
#include <utils/qtcassert.h>
#include <QtCore/QString>
......@@ -126,8 +127,13 @@ void CompletionSupport::autoComplete_helper(ITextEditable *editor, bool forced,
QList<CompletionItem> completionItems;
if (!m_completionList) {
if (!forced && !m_completionCollector->triggersCompletion(editor))
return;
if (!forced) {
const CompletionSettings &completionSettings = m_completionCollector->completionSettings();
if (completionSettings.m_completionTrigger == ManualCompletion)
return;
if (!m_completionCollector->triggersCompletion(editor))
return;
}
m_startPosition = m_completionCollector->startCompletion(editor);
completionItems = getCompletions();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment