diff --git a/src/plugins/texteditor/behaviorsettingspage.cpp b/src/plugins/texteditor/behaviorsettingspage.cpp index 9595415fb09..57a911a8deb 100644 --- a/src/plugins/texteditor/behaviorsettingspage.cpp +++ b/src/plugins/texteditor/behaviorsettingspage.cpp @@ -158,6 +158,7 @@ void BehaviorSettingsPage::settingsFromUI(TabSettings &tabSettings, tabSettings.m_doubleIndentBlocks = m_d->m_page.indentBlocksBehavior->currentIndex() >= 2; tabSettings.m_tabKeyBehavior = (TabSettings::TabKeyBehavior)m_d->m_page.tabKeyBehavior->currentIndex(); + tabSettings.m_paddingMode = (TabSettings::PaddingMode)m_d->m_page.paddingMode->currentIndex(); storageSettings.m_cleanWhitespace = m_d->m_page.cleanWhitespace->isChecked(); storageSettings.m_inEntireDocument = m_d->m_page.inEntireDocument->isChecked(); @@ -181,6 +182,7 @@ void BehaviorSettingsPage::settingsToUI() (tabSettings.m_doubleIndentBlocks ? 2 : 1) : 0); m_d->m_page.tabKeyBehavior->setCurrentIndex(tabSettings.m_tabKeyBehavior); + m_d->m_page.paddingMode->setCurrentIndex(tabSettings.m_paddingMode); const StorageSettings &storageSettings = m_d->m_storageSettings; m_d->m_page.cleanWhitespace->setChecked(storageSettings.m_cleanWhitespace); diff --git a/src/plugins/texteditor/behaviorsettingspage.ui b/src/plugins/texteditor/behaviorsettingspage.ui index 8ccf21d5070..2b5d2bd7959 100644 --- a/src/plugins/texteditor/behaviorsettingspage.ui +++ b/src/plugins/texteditor/behaviorsettingspage.ui @@ -6,8 +6,8 @@ 0 0 - 550 - 464 + 576 + 538 @@ -179,14 +179,14 @@ - + Tab key performs auto-indent: - + @@ -205,6 +205,41 @@ + + + + Padding style: + + + + + + + Padding is the part of indentation exceeding logical indentation and is usually used to align consecutive lines of code. + +Disable Padding: Do not pad at all. Lines will only be indented to the current logical indentation depth. + +Pad With Spaces: Always use spaces for padding, regardless of the choice between tabs and spaces above. + +Pad With Indentation: Padding will be part of the indentation and follow the settings above. + + + + Disable Padding + + + + + Pad With Spaces + + + + + Pad With Indentation + + + + @@ -339,10 +374,6 @@ - groupBoxTabAndIndentSettings - groupBoxStorageSettings - groupBoxMouse - indentBlocksLabel insertSpaces @@ -364,12 +395,12 @@ setEnabled(bool) - 67 - 252 + 87 + 323 - 148 - 281 + 205 + 353 @@ -380,12 +411,12 @@ setEnabled(bool) - 40 - 251 + 60 + 323 - 77 - 310 + 134 + 384 diff --git a/src/plugins/texteditor/tabsettings.cpp b/src/plugins/texteditor/tabsettings.cpp index b9772bb37a2..6277030eb19 100644 --- a/src/plugins/texteditor/tabsettings.cpp +++ b/src/plugins/texteditor/tabsettings.cpp @@ -45,6 +45,7 @@ static const char *indentBracesKey = "IndentBraces"; static const char *doubleIndentBlocksKey = "DoubleIndentBlocks"; static const char *tabKeyBehaviorKey = "TabKeyBehavior"; static const char *groupPostfix = "TabSettings"; +static const char *paddingModeKey = "PaddingMode"; namespace TextEditor { @@ -57,7 +58,8 @@ TabSettings::TabSettings() : m_indentSize(4), m_indentBraces(false), m_doubleIndentBlocks(false), - m_tabKeyBehavior(TabNeverIndents) + m_tabKeyBehavior(TabNeverIndents), + m_paddingMode(PadWithSpaces) { } @@ -76,6 +78,7 @@ void TabSettings::toSettings(const QString &category, QSettings *s) const s->setValue(QLatin1String(indentBracesKey), m_indentBraces); s->setValue(QLatin1String(doubleIndentBlocksKey), m_doubleIndentBlocks); s->setValue(QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior); + s->setValue(QLatin1String(paddingModeKey), m_paddingMode); s->endGroup(); } @@ -99,6 +102,7 @@ void TabSettings::fromSettings(const QString &category, const QSettings *s) = s->value(group + QLatin1String(doubleIndentBlocksKey), m_doubleIndentBlocks).toBool(); m_tabKeyBehavior = (TabKeyBehavior)s->value(group + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt(); + m_paddingMode = (PaddingMode)s->value(group + QLatin1String(paddingModeKey), m_paddingMode).toInt(); } @@ -319,13 +323,20 @@ void TabSettings::indentLine(QTextBlock block, int newIndent, int padding) const const QString text = block.text(); const int oldBlockLength = text.size(); + if (m_paddingMode == DisablePadding) { + newIndent -= padding; + padding = 0; + } else if (m_paddingMode == PadWithIndent) { + padding = 0; + } + // Quickly check whether indenting is required. if (indentationColumn(text) == newIndent) return; QString indentString; - if (!m_spacesForTabs && m_tabSize == m_indentSize) { + if (!m_spacesForTabs) { // user likes tabs for spaces and uses tabs for indentation, preserve padding indentString = indentationString(0, newIndent - padding, block); indentString += QString(padding, QLatin1Char(' ')); @@ -388,7 +399,8 @@ bool TabSettings::equals(const TabSettings &ts) const && m_indentSize == ts.m_indentSize && m_indentBraces == ts.m_indentBraces && m_doubleIndentBlocks == ts.m_doubleIndentBlocks - && m_tabKeyBehavior == ts.m_tabKeyBehavior; + && m_tabKeyBehavior == ts.m_tabKeyBehavior + && m_paddingMode == ts.m_paddingMode; } } // namespace TextEditor diff --git a/src/plugins/texteditor/tabsettings.h b/src/plugins/texteditor/tabsettings.h index 75ec461f0c1..66c7fa0e6aa 100644 --- a/src/plugins/texteditor/tabsettings.h +++ b/src/plugins/texteditor/tabsettings.h @@ -52,6 +52,13 @@ public: TabLeadingWhitespaceIndents = 2 }; + // This enum must match the indexes of paddingMode widget + enum PaddingMode { + DisablePadding = 0, + PadWithSpaces = 1, + PadWithIndent = 2 + }; + TabSettings(); void toSettings(const QString &category, QSettings *s) const; @@ -89,6 +96,7 @@ public: bool m_indentBraces; bool m_doubleIndentBlocks; TabKeyBehavior m_tabKeyBehavior; + PaddingMode m_paddingMode; bool equals(const TabSettings &ts) const; };