forked from qt-creator/qt-creator
TextEditor: Make automatic completion timeout configurable
Allow to configure the timeout in the range from 0 to 500ms. Task-number: QTCREATORBUG-13393 Change-Id: I3e421109db919ab0dd5d63b8cbb9339fce132dbb Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
@@ -64,6 +64,10 @@ QWidget *CompletionSettingsPage::widget()
|
||||
m_page = new Ui::CompletionSettingsPage;
|
||||
m_page->setupUi(m_widget);
|
||||
|
||||
connect(m_page->completionTrigger,
|
||||
static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
this, &CompletionSettingsPage::onCompletionTriggerChanged);
|
||||
|
||||
const TextEditor::CompletionSettings &settings =
|
||||
TextEditor::TextEditorSettings::completionSettings();
|
||||
|
||||
@@ -95,6 +99,7 @@ QWidget *CompletionSettingsPage::widget()
|
||||
|
||||
m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex);
|
||||
m_page->completionTrigger->setCurrentIndex(completionTriggerIndex);
|
||||
m_page->automaticProposalTimeoutSpinBox->setValue(settings.m_automaticProposalTimeoutInMs);
|
||||
m_page->autoInsertBrackets->setChecked(settings.m_autoInsertBrackets);
|
||||
m_page->surroundSelectedText->setChecked(settings.m_surroundingAutoBrackets);
|
||||
m_page->partiallyComplete->setChecked(settings.m_partiallyComplete);
|
||||
@@ -115,6 +120,7 @@ void CompletionSettingsPage::apply()
|
||||
TextEditor::CompletionSettings settings;
|
||||
settings.m_caseSensitivity = caseSensitivity();
|
||||
settings.m_completionTrigger = completionTrigger();
|
||||
settings.m_automaticProposalTimeoutInMs = m_page->automaticProposalTimeoutSpinBox->value();
|
||||
settings.m_autoInsertBrackets = m_page->autoInsertBrackets->isChecked();
|
||||
settings.m_surroundingAutoBrackets = m_page->surroundSelectedText->isChecked();
|
||||
settings.m_partiallyComplete = m_page->partiallyComplete->isChecked();
|
||||
@@ -158,6 +164,13 @@ TextEditor::CompletionTrigger CompletionSettingsPage::completionTrigger() const
|
||||
}
|
||||
}
|
||||
|
||||
void CompletionSettingsPage::onCompletionTriggerChanged()
|
||||
{
|
||||
const bool enableTimeoutWidgets = completionTrigger() == TextEditor::AutomaticCompletion;
|
||||
m_page->automaticProposalTimeoutLabel->setEnabled(enableTimeoutWidgets);
|
||||
m_page->automaticProposalTimeoutSpinBox->setEnabled(enableTimeoutWidgets);
|
||||
}
|
||||
|
||||
void CompletionSettingsPage::finish()
|
||||
{
|
||||
delete m_widget;
|
||||
|
||||
@@ -66,6 +66,8 @@ private:
|
||||
TextEditor::CaseSensitivity caseSensitivity() const;
|
||||
TextEditor::CompletionTrigger completionTrigger() const;
|
||||
|
||||
void onCompletionTriggerChanged();
|
||||
|
||||
bool requireCommentsSettingsUpdate() const;
|
||||
|
||||
Ui::CompletionSettingsPage *m_page;
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
<string>Behavior</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item row="5" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
@@ -36,53 +36,17 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="surroundSelectedText">
|
||||
<property name="toolTip">
|
||||
<string>When typing a matching character and there is a text selection, instead of removing the selection, surrounds it with the corresponding characters.</string>
|
||||
<widget class="QCheckBox" name="spaceAfterFunctionName">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Surround &text selections</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
<string>Insert &space after function name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="2" 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">
|
||||
<widget class="QLabel" name="completionTriggerLabel">
|
||||
<property name="text">
|
||||
<string>Activate completion:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<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="0" column="0">
|
||||
<widget class="QLabel" name="caseSensitivityLabel">
|
||||
<property name="text">
|
||||
@@ -118,6 +82,39 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="surroundSelectedText">
|
||||
<property name="toolTip">
|
||||
<string>When typing a matching character and there is a text selection, instead of removing the selection, surrounds it with the corresponding characters.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Surround &text selections</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QCheckBox" name="autoSplitStrings">
|
||||
<property name="toolTip">
|
||||
@@ -130,6 +127,32 @@ In addition, Shift+Enter inserts an escape character at the cursor position and
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="5">
|
||||
<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="0" column="2" colspan="4">
|
||||
<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="1" colspan="2">
|
||||
<widget class="QComboBox" name="completionTrigger">
|
||||
<item>
|
||||
@@ -149,6 +172,13 @@ In addition, Shift+Enter inserts an escape character at the cursor position and
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLabel" name="automaticProposalTimeoutLabel">
|
||||
<property name="text">
|
||||
<string>Timeout in ms:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="partiallyComplete">
|
||||
<property name="toolTip">
|
||||
@@ -162,6 +192,13 @@ In addition, Shift+Enter inserts an escape character at the cursor position and
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="completionTriggerLabel">
|
||||
<property name="text">
|
||||
<string>Activate completion:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="autoInsertBrackets">
|
||||
<property name="toolTip">
|
||||
@@ -175,37 +212,20 @@ In addition, Shift+Enter inserts an escape character at the cursor position and
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<item row="1" column="4">
|
||||
<widget class="QSpinBox" name="automaticProposalTimeoutSpinBox">
|
||||
<property name="maximum">
|
||||
<number>500</number>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
<property name="singleStep">
|
||||
<number>50</number>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="spaceAfterFunctionName">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Insert &space after function name</string>
|
||||
<property name="value">
|
||||
<number>400</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
void startAutomaticProposalTimer();
|
||||
void automaticProposalTimeout();
|
||||
void clearAbortedPosition();
|
||||
void updateCompletionSettings(const TextEditor::CompletionSettings &settings);
|
||||
void updateFromCompletionSettings(const TextEditor::CompletionSettings &settings);
|
||||
|
||||
virtual bool eventFilter(QObject *o, QEvent *e);
|
||||
|
||||
@@ -115,8 +115,6 @@ private:
|
||||
// --------------------
|
||||
const QChar CodeAssistantPrivate::m_null;
|
||||
|
||||
static const int AutomaticProposalTimerInterval = 400;
|
||||
|
||||
CodeAssistantPrivate::CodeAssistantPrivate(CodeAssistant *assistant)
|
||||
: q(assistant)
|
||||
, m_editorWidget(0)
|
||||
@@ -125,17 +123,14 @@ CodeAssistantPrivate::CodeAssistantPrivate(CodeAssistant *assistant)
|
||||
, m_assistKind(TextEditor::Completion)
|
||||
, m_proposalWidget(0)
|
||||
, m_receivedContentWhileWaiting(false)
|
||||
, m_settings(TextEditorSettings::completionSettings())
|
||||
, m_abortedBasePosition(-1)
|
||||
{
|
||||
m_automaticProposalTimer.setSingleShot(true);
|
||||
m_automaticProposalTimer.setInterval(AutomaticProposalTimerInterval);
|
||||
|
||||
connect(&m_automaticProposalTimer, &QTimer::timeout,
|
||||
this, &CodeAssistantPrivate::automaticProposalTimeout);
|
||||
|
||||
connect(TextEditorSettings::instance(), &TextEditorSettings::completionSettingsChanged,
|
||||
this, &CodeAssistantPrivate::updateCompletionSettings);
|
||||
this, &CodeAssistantPrivate::updateFromCompletionSettings);
|
||||
|
||||
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
||||
this, &CodeAssistantPrivate::clearAbortedPosition);
|
||||
@@ -456,9 +451,11 @@ void CodeAssistantPrivate::stopAutomaticProposalTimer()
|
||||
m_automaticProposalTimer.stop();
|
||||
}
|
||||
|
||||
void CodeAssistantPrivate::updateCompletionSettings(const TextEditor::CompletionSettings &settings)
|
||||
void CodeAssistantPrivate::updateFromCompletionSettings(
|
||||
const TextEditor::CompletionSettings &settings)
|
||||
{
|
||||
m_settings = settings;
|
||||
m_automaticProposalTimer.setInterval(m_settings.m_automaticProposalTimeoutInMs);
|
||||
}
|
||||
|
||||
void CodeAssistantPrivate::explicitlyAborted()
|
||||
@@ -520,6 +517,11 @@ void CodeAssistant::configure(TextEditorWidget *editorWidget)
|
||||
d->configure(editorWidget);
|
||||
}
|
||||
|
||||
void CodeAssistant::updateFromCompletionSettings(const CompletionSettings &settings)
|
||||
{
|
||||
d->updateFromCompletionSettings(settings);
|
||||
}
|
||||
|
||||
void CodeAssistant::process()
|
||||
{
|
||||
d->process();
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
namespace TextEditor {
|
||||
|
||||
class CodeAssistantPrivate;
|
||||
class CompletionSettings;
|
||||
class IAssistProvider;
|
||||
class TextEditorWidget;
|
||||
|
||||
@@ -52,6 +53,7 @@ public:
|
||||
~CodeAssistant();
|
||||
|
||||
void configure(TextEditorWidget *editorWidget);
|
||||
void updateFromCompletionSettings(const TextEditor::CompletionSettings &settings);
|
||||
|
||||
void process();
|
||||
void notifyChange();
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
static const char groupPostfix[] = "Completion";
|
||||
static const char caseSensitivityKey[] = "CaseSensitivity";
|
||||
static const char completionTriggerKey[] = "CompletionTrigger";
|
||||
static const char automaticProposalTimeoutKey[] = "AutomaticProposalTimeout";
|
||||
static const char autoInsertBracesKey[] = "AutoInsertBraces";
|
||||
static const char surroundingAutoBracketsKey[] = "SurroundingAutoBrackets";
|
||||
static const char partiallyCompleteKey[] = "PartiallyComplete";
|
||||
@@ -46,6 +47,7 @@ using namespace TextEditor;
|
||||
CompletionSettings::CompletionSettings()
|
||||
: m_caseSensitivity(CaseInsensitive)
|
||||
, m_completionTrigger(AutomaticCompletion)
|
||||
, m_automaticProposalTimeoutInMs(400)
|
||||
, m_autoInsertBrackets(true)
|
||||
, m_surroundingAutoBrackets(true)
|
||||
, m_partiallyComplete(true)
|
||||
@@ -63,6 +65,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(automaticProposalTimeoutKey), m_automaticProposalTimeoutInMs);
|
||||
s->setValue(QLatin1String(autoInsertBracesKey), m_autoInsertBrackets);
|
||||
s->setValue(QLatin1String(surroundingAutoBracketsKey), m_surroundingAutoBrackets);
|
||||
s->setValue(QLatin1String(partiallyCompleteKey), m_partiallyComplete);
|
||||
@@ -82,6 +85,7 @@ void CompletionSettings::fromSettings(const QString &category, const QSettings *
|
||||
|
||||
m_caseSensitivity = (CaseSensitivity) s->value(group + QLatin1String(caseSensitivityKey), m_caseSensitivity).toInt();
|
||||
m_completionTrigger = (CompletionTrigger) s->value(group + QLatin1String(completionTriggerKey), m_completionTrigger).toInt();
|
||||
m_automaticProposalTimeoutInMs = s->value(group + QLatin1String(automaticProposalTimeoutKey), m_automaticProposalTimeoutInMs).toInt();
|
||||
m_autoInsertBrackets = s->value(group + QLatin1String(autoInsertBracesKey), m_autoInsertBrackets).toBool();
|
||||
m_surroundingAutoBrackets = s->value(group + QLatin1String(surroundingAutoBracketsKey), m_surroundingAutoBrackets).toBool();
|
||||
m_partiallyComplete = s->value(group + QLatin1String(partiallyCompleteKey), m_partiallyComplete).toBool();
|
||||
@@ -93,6 +97,7 @@ bool CompletionSettings::equals(const CompletionSettings &cs) const
|
||||
{
|
||||
return m_caseSensitivity == cs.m_caseSensitivity
|
||||
&& m_completionTrigger == cs.m_completionTrigger
|
||||
&& m_automaticProposalTimeoutInMs == cs.m_automaticProposalTimeoutInMs
|
||||
&& m_autoInsertBrackets == cs.m_autoInsertBrackets
|
||||
&& m_surroundingAutoBrackets == cs.m_surroundingAutoBrackets
|
||||
&& m_partiallyComplete == cs.m_partiallyComplete
|
||||
|
||||
@@ -66,6 +66,7 @@ public:
|
||||
|
||||
CaseSensitivity m_caseSensitivity;
|
||||
CompletionTrigger m_completionTrigger;
|
||||
int m_automaticProposalTimeoutInMs;
|
||||
bool m_autoInsertBrackets;
|
||||
bool m_surroundingAutoBrackets;
|
||||
bool m_partiallyComplete;
|
||||
|
||||
@@ -6210,6 +6210,7 @@ void TextEditorWidget::setCompletionSettings(const CompletionSettings &completio
|
||||
d->m_autoCompleter->setAutoParenthesesEnabled(completionSettings.m_autoInsertBrackets);
|
||||
d->m_autoCompleter->setSurroundWithEnabled(completionSettings.m_autoInsertBrackets
|
||||
&& completionSettings.m_surroundingAutoBrackets);
|
||||
d->m_codeAssistant.updateFromCompletionSettings(completionSettings);
|
||||
}
|
||||
|
||||
void TextEditorWidget::setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings)
|
||||
|
||||
Reference in New Issue
Block a user