From 20ab82ce73bd2570f138a9359ff602a96e15c471 Mon Sep 17 00:00:00 2001 From: mae Date: Tue, 15 Sep 2009 17:15:11 +0200 Subject: [PATCH] make auto parentheses opt-in for individual editors. Currently its only turned on in the cpp editor. --- src/plugins/cppeditor/cppeditor.cpp | 1 + src/plugins/texteditor/basetexteditor.cpp | 15 +++++++++++++-- src/plugins/texteditor/basetexteditor.h | 3 +++ src/plugins/texteditor/basetexteditor_p.h | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 597a2769e85..3ba2967a9b0 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -536,6 +536,7 @@ CPPEditor::CPPEditor(QWidget *parent) m_semanticHighlighter->start(); setParenthesesMatchingEnabled(true); + setAutoParenthesesEnabled(true); setMarksVisible(true); setCodeFoldingSupported(true); setCodeFoldingVisible(true); diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 3572bf446d0..4a446fd2543 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -178,6 +178,7 @@ BaseTextEditor::BaseTextEditor(QWidget *parent) // (void) new QShortcut(tr("F11"), this, SLOT(slotToggleBlockVisible())); + d->m_autoParenthesesEnabled = false; // parentheses matcher d->m_parenthesesMatchingEnabled = false; d->m_formatRange = true; @@ -890,7 +891,7 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) const TabSettings &ts = d->m_document->tabSettings(); cursor.beginEditBlock(); - if (ts.m_autoParentheses + if (d->m_autoParenthesesEnabled && ts.m_autoParentheses && characterAt(cursor.position()) == QLatin1Char('}')) { int pos = cursor.position(); if (ts.m_autoIndent) { @@ -1059,7 +1060,7 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) QTextCursor cursor = textCursor(); QString text = e->text(); QString autoText; - if (d->m_document->tabSettings().m_autoParentheses) { + if (d->m_autoParenthesesEnabled && d->m_document->tabSettings().m_autoParentheses) { foreach(QChar c, text) { QChar close; if (c == QLatin1Char('{')) @@ -1312,6 +1313,16 @@ bool BaseTextEditor::isParenthesesMatchingEnabled() const return d->m_parenthesesMatchingEnabled; } +void BaseTextEditor::setAutoParenthesesEnabled(bool b) +{ + d->m_autoParenthesesEnabled = b; +} + +bool BaseTextEditor::isAutoParenthesesEnabled() const +{ + return d->m_autoParenthesesEnabled; +} + void BaseTextEditor::setHighlightCurrentLine(bool b) { d->m_highlightCurrentLine = b; diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 556df22488d..691365cecd2 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -322,6 +322,9 @@ public: void setParenthesesMatchingEnabled(bool b); bool isParenthesesMatchingEnabled() const; + void setAutoParenthesesEnabled(bool b); + bool isAutoParenthesesEnabled() const; + void setHighlightCurrentLine(bool b); bool highlightCurrentLine() const; diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h index 1956f858800..0ef9a1272c2 100644 --- a/src/plugins/texteditor/basetexteditor_p.h +++ b/src/plugins/texteditor/basetexteditor_p.h @@ -163,6 +163,7 @@ public: QString m_displayName; bool m_parenthesesMatchingEnabled; + bool m_autoParenthesesEnabled; QTimer *m_updateTimer; // parentheses matcher