diff options
author | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2010-07-15 16:05:43 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2010-07-15 16:24:01 +0200 |
commit | e101d8eccc24b9bdbe102716cf63e01ecd9efca3 (patch) | |
tree | c77c34efd74c3dd66d297514ae7725db0593a5f3 | |
parent | 2c51e0c9da9074a0ee7e9ce4666a777f7a03affd (diff) | |
download | qt-creator-e101d8eccc24b9bdbe102716cf63e01ecd9efca3.tar.gz |
Make the way completion is triggered configurable
Now it's possible to choose between having completion popup manually,
when triggered or always.
-rw-r--r-- | src/plugins/cpptools/completionsettingspage.cpp | 32 | ||||
-rw-r--r-- | src/plugins/cpptools/completionsettingspage.h | 1 | ||||
-rw-r--r-- | src/plugins/cpptools/completionsettingspage.ui | 153 | ||||
-rw-r--r-- | src/plugins/cpptools/cppcodecompletion.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljscodecompletion.cpp | 3 | ||||
-rw-r--r-- | src/plugins/texteditor/completionsettings.cpp | 5 | ||||
-rw-r--r-- | src/plugins/texteditor/completionsettings.h | 7 | ||||
-rw-r--r-- | src/plugins/texteditor/completionsupport.cpp | 10 |
8 files changed, 143 insertions, 70 deletions
diff --git a/src/plugins/cpptools/completionsettingspage.cpp b/src/plugins/cpptools/completionsettingspage.cpp index ae1882b009..2db7dc3087 100644 --- a/src/plugins/cpptools/completionsettingspage.cpp +++ b/src/plugins/cpptools/completionsettingspage.cpp @@ -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; + } +} diff --git a/src/plugins/cpptools/completionsettingspage.h b/src/plugins/cpptools/completionsettingspage.h index 4221811ad6..c2b0c56dc3 100644 --- a/src/plugins/cpptools/completionsettingspage.h +++ b/src/plugins/cpptools/completionsettingspage.h @@ -60,6 +60,7 @@ public: private: TextEditor::CaseSensitivity caseSensitivity() const; + TextEditor::CompletionTrigger completionTrigger() const; Ui_CompletionSettingsPage *m_page; QString m_searchKeywords; diff --git a/src/plugins/cpptools/completionsettingspage.ui b/src/plugins/cpptools/completionsettingspage.ui index 98e0da2bc6..6b4f0a1377 100644 --- a/src/plugins/cpptools/completionsettingspage.ui +++ b/src/plugins/cpptools/completionsettingspage.ui @@ -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>&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>&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/> diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index d3e46ea06c..993aef82e0 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -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) { diff --git a/src/plugins/qmljseditor/qmljscodecompletion.cpp b/src/plugins/qmljseditor/qmljscodecompletion.cpp index 5f28d8acac..9b84cd2dd8 100644 --- a/src/plugins/qmljseditor/qmljscodecompletion.cpp +++ b/src/plugins/qmljseditor/qmljscodecompletion.cpp @@ -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); diff --git a/src/plugins/texteditor/completionsettings.cpp b/src/plugins/texteditor/completionsettings.cpp index dc4bba3116..399415c9d6 100644 --- a/src/plugins/texteditor/completionsettings.cpp +++ b/src/plugins/texteditor/completionsettings.cpp @@ -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 diff --git a/src/plugins/texteditor/completionsettings.h b/src/plugins/texteditor/completionsettings.h index 0d35abf9bb..dcec5cc4f1 100644 --- a/src/plugins/texteditor/completionsettings.h +++ b/src/plugins/texteditor/completionsettings.h @@ -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; diff --git a/src/plugins/texteditor/completionsupport.cpp b/src/plugins/texteditor/completionsupport.cpp index bd6cc6c12e..1ae51b106b 100644 --- a/src/plugins/texteditor/completionsupport.cpp +++ b/src/plugins/texteditor/completionsupport.cpp @@ -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(); |