diff --git a/src/libs/utils/uncommentselection.cpp b/src/libs/utils/uncommentselection.cpp index 185293c07a2..2a9bf682f55 100644 --- a/src/libs/utils/uncommentselection.cpp +++ b/src/libs/utils/uncommentselection.cpp @@ -74,7 +74,8 @@ static bool isComment(const QString &text, int index, } -void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &definition) +void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &definition, + bool preferSingleLine) { if (!definition.isValid()) return; @@ -103,7 +104,7 @@ void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &de bool hasSelection = cursor.hasSelection(); - if (hasSelection && definition.hasMultiLineStyle()) { + if (hasSelection && definition.hasMultiLineStyle() && !preferSingleLine) { QString startText = startBlock.text(); int startPos = start - startBlock.position(); @@ -145,6 +146,7 @@ void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &de } else if (!hasSelection && !definition.hasSingleLineStyle()) { QString text = startBlock.text().trimmed(); + doMultiLineStyleUncomment = text.startsWith(definition.multiLineStart) && text.endsWith(definition.multiLineEnd); doMultiLineStyleComment = !doMultiLineStyleUncomment && !text.isEmpty(); diff --git a/src/libs/utils/uncommentselection.h b/src/libs/utils/uncommentselection.h index b61fce48c91..9a27c46c1bc 100644 --- a/src/libs/utils/uncommentselection.h +++ b/src/libs/utils/uncommentselection.h @@ -58,6 +58,7 @@ public: QTCREATOR_UTILS_EXPORT void unCommentSelection(QPlainTextEdit *edit, - const CommentDefinition &definiton = CommentDefinition()); + const CommentDefinition &definiton = CommentDefinition(), + bool preferSingleLine = false); } // namespace Utils diff --git a/src/plugins/texteditor/behaviorsettingswidget.cpp b/src/plugins/texteditor/behaviorsettingswidget.cpp index fe7e983fade..510796afab9 100644 --- a/src/plugins/texteditor/behaviorsettingswidget.cpp +++ b/src/plugins/texteditor/behaviorsettingswidget.cpp @@ -175,6 +175,8 @@ void BehaviorSettingsWidget::setAssignedTypingSettings(const TypingSettings &typ d->m_ui.autoIndent->setChecked(typingSettings.m_autoIndent); d->m_ui.smartBackspaceBehavior->setCurrentIndex(typingSettings.m_smartBackspaceBehavior); d->m_ui.tabKeyBehavior->setCurrentIndex(typingSettings.m_tabKeyBehavior); + + d->m_ui.preferSingleLineComments->setChecked(typingSettings.m_preferSingleLineComments); } void BehaviorSettingsWidget::assignedTypingSettings(TypingSettings *typingSettings) const @@ -184,6 +186,8 @@ void BehaviorSettingsWidget::assignedTypingSettings(TypingSettings *typingSettin (TypingSettings::SmartBackspaceBehavior)(d->m_ui.smartBackspaceBehavior->currentIndex()); typingSettings->m_tabKeyBehavior = (TypingSettings::TabKeyBehavior)(d->m_ui.tabKeyBehavior->currentIndex()); + + typingSettings->m_preferSingleLineComments = d->m_ui.preferSingleLineComments->isChecked(); } void BehaviorSettingsWidget::setAssignedStorageSettings(const StorageSettings &storageSettings) diff --git a/src/plugins/texteditor/behaviorsettingswidget.ui b/src/plugins/texteditor/behaviorsettingswidget.ui index d6d9fed5c60..3b7e7a206cd 100644 --- a/src/plugins/texteditor/behaviorsettingswidget.ui +++ b/src/plugins/texteditor/behaviorsettingswidget.ui @@ -37,21 +37,32 @@ false - - - - Enable automatic &indentation + + + + + 0 + 0 + + + + Never + + + + + Always + + + + + In Leading White Space + + - - - - Backspace indentation: - - - - + @@ -92,14 +103,28 @@ Specifies how backspace interacts with indentation. - + + + + Enable automatic &indentation + + + + Tab key performs auto-indent: - + + + + Backspace indentation: + + + + Qt::Horizontal @@ -115,29 +140,11 @@ Specifies how backspace interacts with indentation. - - - - - 0 - 0 - + + + + Prefer single line comments - - - Never - - - - - Always - - - - - In Leading White Space - - diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 1dada6a2956..e5b5a2b2ea5 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -7310,7 +7310,8 @@ void TextEditorWidget::rewrapParagraph() void TextEditorWidget::unCommentSelection() { - Utils::unCommentSelection(this, d->m_commentDefinition); + Utils::unCommentSelection(this, d->m_commentDefinition, + d->m_document->typingSettings().m_preferSingleLineComments); } void TextEditorWidget::autoFormat() diff --git a/src/plugins/texteditor/typingsettings.cpp b/src/plugins/texteditor/typingsettings.cpp index 13440c259f4..588235bd204 100644 --- a/src/plugins/texteditor/typingsettings.cpp +++ b/src/plugins/texteditor/typingsettings.cpp @@ -32,6 +32,7 @@ static const char autoIndentKey[] = "AutoIndent"; static const char tabKeyBehaviorKey[] = "TabKeyBehavior"; static const char smartBackspaceBehaviorKey[] = "SmartBackspaceBehavior"; +static const char preferSingleLineCommentsKey[] = "PreferSingleLineComments"; static const char groupPostfix[] = "TypingSettings"; @@ -40,7 +41,8 @@ namespace TextEditor { TypingSettings::TypingSettings(): m_autoIndent(true), m_tabKeyBehavior(TabNeverIndents), - m_smartBackspaceBehavior(BackspaceNeverIndents) + m_smartBackspaceBehavior(BackspaceNeverIndents), + m_preferSingleLineComments(false) { } @@ -60,24 +62,31 @@ void TypingSettings::toMap(const QString &prefix, QVariantMap *map) const map->insert(prefix + QLatin1String(autoIndentKey), m_autoIndent); map->insert(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior); map->insert(prefix + QLatin1String(smartBackspaceBehaviorKey), m_smartBackspaceBehavior); + + map->insert(prefix + QLatin1String(preferSingleLineCommentsKey), m_preferSingleLineComments); } void TypingSettings::fromMap(const QString &prefix, const QVariantMap &map) { - m_autoIndent = map.value(prefix + QLatin1String(autoIndentKey), m_autoIndent).toBool(); + m_autoIndent = + map.value(prefix + QLatin1String(autoIndentKey), m_autoIndent).toBool(); m_tabKeyBehavior = (TabKeyBehavior) map.value(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt(); m_smartBackspaceBehavior = (SmartBackspaceBehavior) map.value(prefix + QLatin1String(smartBackspaceBehaviorKey), m_smartBackspaceBehavior).toInt(); + m_preferSingleLineComments = + map.value(prefix + QLatin1String(preferSingleLineCommentsKey), m_preferSingleLineComments).toBool(); + } bool TypingSettings::equals(const TypingSettings &ts) const { return m_autoIndent == ts.m_autoIndent && m_tabKeyBehavior == ts.m_tabKeyBehavior - && m_smartBackspaceBehavior == ts.m_smartBackspaceBehavior; + && m_smartBackspaceBehavior == ts.m_smartBackspaceBehavior + && m_preferSingleLineComments == ts.m_preferSingleLineComments; } bool TypingSettings::tabShouldIndent(const QTextDocument *document, const QTextCursor &cursor, int *suggestedPosition) const diff --git a/src/plugins/texteditor/typingsettings.h b/src/plugins/texteditor/typingsettings.h index 2fd37f016e6..5f71d84d207 100644 --- a/src/plugins/texteditor/typingsettings.h +++ b/src/plugins/texteditor/typingsettings.h @@ -69,6 +69,8 @@ public: bool m_autoIndent; TabKeyBehavior m_tabKeyBehavior; SmartBackspaceBehavior m_smartBackspaceBehavior; + + bool m_preferSingleLineComments; }; inline bool operator==(const TypingSettings &t1, const TypingSettings &t2) { return t1.equals(t2); }