diff options
author | Adam Majer <adamm@zombino.com> | 2009-01-26 13:14:28 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2009-01-26 14:32:04 +0100 |
commit | 18952c98b9436e49f849edfd2c4918c36165cc65 (patch) | |
tree | 0a2a1b02f13a6d722af320e0876b7712ea2233f8 /src/plugins/texteditor | |
parent | 62d78bb06244f0b5ba23759c55082626be4c7158 (diff) |
Add explicit option to clean indentation
It is desirable to have removal of trailing whitespace as a separate
option to "tab cleanup". Clean Whitespace option without Clean
Indentation option will now only remove trailing whitespace on file save
and on Clean Whitespace requests. Clean Indentation option is set to
true by default to maintain backward compatibility.
Signed-off-by: Adam Majer <adamm@zombino.com>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r-- | src/plugins/texteditor/basetextdocument.cpp | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/generalsettingspage.cpp | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/generalsettingspage.ui | 36 | ||||
-rw-r--r-- | src/plugins/texteditor/storagesettings.cpp | 9 | ||||
-rw-r--r-- | src/plugins/texteditor/storagesettings.h | 1 |
5 files changed, 47 insertions, 3 deletions
diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp index eb6069df6d..d782ed5ace 100644 --- a/src/plugins/texteditor/basetextdocument.cpp +++ b/src/plugins/texteditor/basetextdocument.cpp @@ -330,7 +330,7 @@ void BaseTextDocument::cleanWhitespace(QTextCursor& cursor, bool inEntireDocumen cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor, trailing); cursor.removeSelectedText(); } - if (!m_tabSettings.isIndentationClean(blockText)) { + if (m_storageSettings.m_cleanIndentation && !m_tabSettings.isIndentationClean(blockText)) { cursor.setPosition(block.position()); int firstNonSpace = m_tabSettings.firstNonSpace(blockText); if (firstNonSpace == blockText.length()) { diff --git a/src/plugins/texteditor/generalsettingspage.cpp b/src/plugins/texteditor/generalsettingspage.cpp index 7482080ab9..28400d10eb 100644 --- a/src/plugins/texteditor/generalsettingspage.cpp +++ b/src/plugins/texteditor/generalsettingspage.cpp @@ -162,6 +162,7 @@ void GeneralSettingsPage::settingsFromUI(TabSettings &rc, storageSettings.m_cleanWhitespace = m_d->m_page.cleanWhitespace->isChecked(); storageSettings.m_inEntireDocument = m_d->m_page.inEntireDocument->isChecked(); + storageSettings.m_cleanIndentation = m_d->m_page.cleanIndentation->isChecked(); storageSettings.m_addFinalNewLine = m_d->m_page.addFinalNewLine->isChecked(); displaySettings.m_displayLineNumbers = m_d->m_page.displayLineNumbers->isChecked(); @@ -187,6 +188,7 @@ void GeneralSettingsPage::settingsToUI() StorageSettings storageSettings = m_d->m_storageSettings; m_d->m_page.cleanWhitespace->setChecked(storageSettings.m_cleanWhitespace); m_d->m_page.inEntireDocument->setChecked(storageSettings.m_inEntireDocument); + m_d->m_page.cleanIndentation->setChecked(storageSettings.m_cleanIndentation); m_d->m_page.addFinalNewLine->setChecked(storageSettings.m_addFinalNewLine); DisplaySettings displaySettings = m_d->m_displaySettings; diff --git a/src/plugins/texteditor/generalsettingspage.ui b/src/plugins/texteditor/generalsettingspage.ui index 58b6bdbc0a..301ee8bdf5 100644 --- a/src/plugins/texteditor/generalsettingspage.ui +++ b/src/plugins/texteditor/generalsettingspage.ui @@ -215,6 +215,36 @@ </layout> </item> <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>30</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QCheckBox" name="cleanIndentation"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Clean indentation</string> + </property> + </widget> + </item> + </layout> + </item> + <item> <widget class="QCheckBox" name="addFinalNewLine"> <property name="text"> <string>&Ensure newline at end of file</string> @@ -339,6 +369,12 @@ </hints> </connection> <connection> + <sender>cleanWhitespace</sender> + <signal>toggled(bool)</signal> + <receiver>cleanIndentation</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> <sender>showWrapColumn</sender> <signal>toggled(bool)</signal> <receiver>wrapColumn</receiver> diff --git a/src/plugins/texteditor/storagesettings.cpp b/src/plugins/texteditor/storagesettings.cpp index b92b497345..c14a28ae6a 100644 --- a/src/plugins/texteditor/storagesettings.cpp +++ b/src/plugins/texteditor/storagesettings.cpp @@ -41,12 +41,14 @@ namespace TextEditor { static const char * const cleanWhitespaceKey = "cleanWhitespace"; static const char * const inEntireDocumentKey = "inEntireDocument"; static const char * const addFinalNewLineKey = "addFinalNewLine"; +static const char * const cleanIndentationKey = "cleanIndentation"; static const char * const groupPostfix = "StorageSettings"; StorageSettings::StorageSettings() : m_cleanWhitespace(true), m_inEntireDocument(false), - m_addFinalNewLine(true) + m_addFinalNewLine(true), + m_cleanIndentation(true) { } @@ -59,6 +61,7 @@ void StorageSettings::toSettings(const QString &category, QSettings *s) const s->setValue(QLatin1String(cleanWhitespaceKey), m_cleanWhitespace); s->setValue(QLatin1String(inEntireDocumentKey), m_inEntireDocument); s->setValue(QLatin1String(addFinalNewLineKey), m_addFinalNewLine); + s->setValue(QLatin1String(cleanIndentationKey), m_cleanIndentation); s->endGroup(); } @@ -71,13 +74,15 @@ void StorageSettings::fromSettings(const QString &category, const QSettings *s) m_cleanWhitespace = s->value(group + QLatin1String(cleanWhitespaceKey), m_cleanWhitespace).toBool(); m_inEntireDocument = s->value(group + QLatin1String(inEntireDocumentKey), m_inEntireDocument).toBool(); m_addFinalNewLine = s->value(group + QLatin1String(addFinalNewLineKey), m_addFinalNewLine).toBool(); + m_cleanIndentation = s->value(group + QLatin1String(cleanIndentationKey), m_cleanIndentation).toBool(); } bool StorageSettings::equals(const StorageSettings &ts) const { return m_addFinalNewLine == ts.m_addFinalNewLine && m_cleanWhitespace == ts.m_cleanWhitespace - && m_inEntireDocument == ts.m_inEntireDocument; + && m_inEntireDocument == ts.m_inEntireDocument + && m_cleanIndentation == ts.m_cleanIndentation; } } // namespace TextEditor diff --git a/src/plugins/texteditor/storagesettings.h b/src/plugins/texteditor/storagesettings.h index d90b462d32..4fca30b284 100644 --- a/src/plugins/texteditor/storagesettings.h +++ b/src/plugins/texteditor/storagesettings.h @@ -54,6 +54,7 @@ struct TEXTEDITOR_EXPORT StorageSettings bool m_cleanWhitespace; bool m_inEntireDocument; bool m_addFinalNewLine; + bool m_cleanIndentation; }; inline bool operator==(const StorageSettings &t1, const StorageSettings &t2) { return t1.equals(t2); } |