From fa281be8bffe5ef3c19814984eb546c8cff6d4cf Mon Sep 17 00:00:00 2001 From: Leandro Melo Date: Wed, 14 Sep 2011 12:14:15 +0200 Subject: [PATCH] Editor: New option for surrounding auto brackets Notice that this option already existed in the auto completer. However, from the user perspective it was synchronized with auto insert brackets. Task-number: QTCREATORBUG-5835 Change-Id: Ia87a2ca38d89dba51380a4fdb58a5a3689ed9265 Reviewed-on: http://codereview.qt-project.org/4885 Reviewed-by: Qt Sanity Bot Reviewed-by: hjk --- .../cpptools/completionsettingspage.cpp | 3 + .../cpptools/completionsettingspage.ui | 137 +++++++++++++----- src/plugins/texteditor/basetexteditor.cpp | 3 +- src/plugins/texteditor/completionsettings.cpp | 5 + src/plugins/texteditor/completionsettings.h | 1 + 5 files changed, 114 insertions(+), 35 deletions(-) diff --git a/src/plugins/cpptools/completionsettingspage.cpp b/src/plugins/cpptools/completionsettingspage.cpp index 17e2b42f8a3..9ae1b077b92 100644 --- a/src/plugins/cpptools/completionsettingspage.cpp +++ b/src/plugins/cpptools/completionsettingspage.cpp @@ -100,12 +100,14 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent) m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex); m_page->completionTrigger->setCurrentIndex(completionTriggerIndex); m_page->autoInsertBrackets->setChecked(settings.m_autoInsertBrackets); + m_page->surroundSelectedText->setChecked(settings.m_surroundingAutoBrackets); m_page->partiallyComplete->setChecked(settings.m_partiallyComplete); m_page->spaceAfterFunctionName->setChecked(settings.m_spaceAfterFunctionName); if (m_searchKeywords.isEmpty()) { QTextStream(&m_searchKeywords) << m_page->caseSensitivityLabel->text() << ' ' << m_page->autoInsertBrackets->text() + << ' ' << m_page->surroundSelectedText->text() << ' ' << m_page->completionTriggerLabel->text() << ' ' << m_page->partiallyComplete->text() << ' ' << m_page->spaceAfterFunctionName->text(); @@ -123,6 +125,7 @@ void CompletionSettingsPage::apply() settings.m_caseSensitivity = caseSensitivity(); settings.m_completionTrigger = completionTrigger(); settings.m_autoInsertBrackets = m_page->autoInsertBrackets->isChecked(); + settings.m_surroundingAutoBrackets = m_page->surroundSelectedText->isChecked(); settings.m_partiallyComplete = m_page->partiallyComplete->isChecked(); settings.m_spaceAfterFunctionName = m_page->spaceAfterFunctionName->isChecked(); diff --git a/src/plugins/cpptools/completionsettingspage.ui b/src/plugins/cpptools/completionsettingspage.ui index 8570db4d0d1..7c2e2eff606 100644 --- a/src/plugins/cpptools/completionsettingspage.ui +++ b/src/plugins/cpptools/completionsettingspage.ui @@ -6,8 +6,8 @@ 0 0 - 359 - 244 + 363 + 241 @@ -27,7 +27,7 @@ - + @@ -52,7 +52,7 @@ - + Qt::Horizontal @@ -65,14 +65,14 @@ - + Activate completion: - + @@ -91,7 +91,7 @@ - + Qt::Horizontal @@ -104,29 +104,6 @@ - - - - Automatically insert brackets and semicolons when appropriate. - - - &Automatically insert brackets - - - true - - - - - - - true - - - Insert &space after function name - - - @@ -140,6 +117,82 @@ + + + + Automatically insert brackets and semicolons when appropriate. + + + &Automatically insert brackets + + + true + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 30 + 20 + + + + + + + + Automatically surround text selections with brackets. + + + Surround selected &text + + + true + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 30 + 20 + + + + + + + + true + + + Insert &space after function name + + + + + @@ -167,12 +220,28 @@ setEnabled(bool) - 248 - 132 + 267 + 131 - 246 - 164 + 265 + 182 + + + + + autoInsertBrackets + toggled(bool) + surroundSelectedText + setEnabled(bool) + + + 109 + 123 + + + 119 + 156 diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 03c0b963441..913d4112761 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -5536,7 +5536,8 @@ void BaseTextEditorWidget::setStorageSettings(const StorageSettings &storageSett void BaseTextEditorWidget::setCompletionSettings(const TextEditor::CompletionSettings &completionSettings) { d->m_autoCompleter->setAutoParenthesesEnabled(completionSettings.m_autoInsertBrackets); - d->m_autoCompleter->setSurroundWithEnabled(completionSettings.m_autoInsertBrackets); + d->m_autoCompleter->setSurroundWithEnabled(completionSettings.m_autoInsertBrackets + && completionSettings.m_surroundingAutoBrackets); } void BaseTextEditorWidget::setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings) diff --git a/src/plugins/texteditor/completionsettings.cpp b/src/plugins/texteditor/completionsettings.cpp index d72bd1acf8a..d96f338c372 100644 --- a/src/plugins/texteditor/completionsettings.cpp +++ b/src/plugins/texteditor/completionsettings.cpp @@ -38,6 +38,7 @@ static const char groupPostfix[] = "Completion"; static const char caseSensitivityKey[] = "CaseSensitivity"; static const char completionTriggerKey[] = "CompletionTrigger"; static const char autoInsertBracesKey[] = "AutoInsertBraces"; +static const char surroundingAutoBracketsKey[] = "SurroundingAutoBrackets"; static const char partiallyCompleteKey[] = "PartiallyComplete"; static const char spaceAfterFunctionNameKey[] = "SpaceAfterFunctionName"; @@ -47,6 +48,7 @@ CompletionSettings::CompletionSettings() : m_caseSensitivity(CaseInsensitive) , m_completionTrigger(AutomaticCompletion) , m_autoInsertBrackets(true) + , m_surroundingAutoBrackets(true) , m_partiallyComplete(true) , m_spaceAfterFunctionName(false) { @@ -62,6 +64,7 @@ void CompletionSettings::toSettings(const QString &category, QSettings *s) const s->setValue(QLatin1String(caseSensitivityKey), (int) m_caseSensitivity); s->setValue(QLatin1String(completionTriggerKey), (int) m_completionTrigger); s->setValue(QLatin1String(autoInsertBracesKey), m_autoInsertBrackets); + s->setValue(QLatin1String(surroundingAutoBracketsKey), m_surroundingAutoBrackets); s->setValue(QLatin1String(partiallyCompleteKey), m_partiallyComplete); s->setValue(QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName); s->endGroup(); @@ -79,6 +82,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_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(); m_spaceAfterFunctionName = s->value(group + QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName).toBool(); } @@ -88,6 +92,7 @@ bool CompletionSettings::equals(const CompletionSettings &cs) const return m_caseSensitivity == cs.m_caseSensitivity && m_completionTrigger == cs.m_completionTrigger && m_autoInsertBrackets == cs.m_autoInsertBrackets + && m_surroundingAutoBrackets == cs.m_surroundingAutoBrackets && 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 16c2d03a714..b3d8ace7b08 100644 --- a/src/plugins/texteditor/completionsettings.h +++ b/src/plugins/texteditor/completionsettings.h @@ -69,6 +69,7 @@ public: CaseSensitivity m_caseSensitivity; CompletionTrigger m_completionTrigger; bool m_autoInsertBrackets; + bool m_surroundingAutoBrackets; bool m_partiallyComplete; bool m_spaceAfterFunctionName; };