Commit fa5f9246 authored by Jeffrey Baumes's avatar Jeffrey Baumes Committed by Thorbjørn Lindeijer
Browse files

Adding indented braces option.



Merge-request: 1949
Reviewed-by: default avatarThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
parent a5252a44
......@@ -1573,6 +1573,7 @@ static void indentCPPBlock(const CPPEditor::TabSettings &ts,
Indenter &indenter = Indenter::instance();
indenter.setIndentSize(ts.m_indentSize);
indenter.setTabSize(ts.m_tabSize);
indenter.setIndentBraces(ts.m_indentBraces);
const TextEditor::TextBlockIterator current(block);
const int indent = indenter.indentForBottomLine(current, programBegin, programEnd, typedChar);
......
......@@ -163,6 +163,7 @@ void BehaviorSettingsPage::settingsFromUI(TabSettings &tabSettings,
tabSettings.m_smartBackspace = m_d->m_page.smartBackspace->isChecked();
tabSettings.m_tabSize = m_d->m_page.tabSize->value();
tabSettings.m_indentSize = m_d->m_page.indentSize->value();
tabSettings.m_indentBraces = m_d->m_page.indentBraces->isChecked();
tabSettings.m_tabKeyBehavior = (TabSettings::TabKeyBehavior)m_d->m_page.tabKeyBehavior->currentIndex();
storageSettings.m_cleanWhitespace = m_d->m_page.cleanWhitespace->isChecked();
......@@ -182,6 +183,7 @@ void BehaviorSettingsPage::settingsToUI()
m_d->m_page.smartBackspace->setChecked(tabSettings.m_smartBackspace);
m_d->m_page.tabSize->setValue(tabSettings.m_tabSize);
m_d->m_page.indentSize->setValue(tabSettings.m_indentSize);
m_d->m_page.indentBraces->setChecked(tabSettings.m_indentBraces);
m_d->m_page.tabKeyBehavior->setCurrentIndex(tabSettings.m_tabKeyBehavior);
const StorageSettings &storageSettings = m_d->m_storageSettings;
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>463</width>
<width>615</width>
<height>421</height>
</rect>
</property>
......@@ -107,7 +107,7 @@
</property>
</widget>
</item>
<item row="0" column="1" rowspan="3">
<item row="0" column="1" rowspan="4">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -120,7 +120,7 @@
</property>
</spacer>
</item>
<item row="0" column="4" rowspan="3">
<item row="0" column="4" rowspan="4">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -133,6 +133,16 @@
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="indentBraces">
<property name="toolTip">
<string>Braces will be flush with indented block, except first indent level.</string>
</property>
<property name="text">
<string>Indent brace&amp;s</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
......
......@@ -40,6 +40,7 @@ static const char *smartBackspaceKey = "SmartBackspace";
static const char *autoIndentKey = "AutoIndent";
static const char *tabSizeKey = "TabSize";
static const char *indentSizeKey = "IndentSize";
static const char *indentBracesKey = "IndentBraces";
static const char *tabKeyBehaviorKey = "TabKeyBehavior";
static const char *groupPostfix = "TabSettings";
......@@ -51,6 +52,7 @@ TabSettings::TabSettings() :
m_smartBackspace(false),
m_tabSize(8),
m_indentSize(4),
m_indentBraces(false),
m_tabKeyBehavior(TabNeverIndents)
{
}
......@@ -66,6 +68,7 @@ void TabSettings::toSettings(const QString &category, QSettings *s) const
s->setValue(QLatin1String(smartBackspaceKey), m_smartBackspace);
s->setValue(QLatin1String(tabSizeKey), m_tabSize);
s->setValue(QLatin1String(indentSizeKey), m_indentSize);
s->setValue(QLatin1String(indentBracesKey), m_indentBraces);
s->setValue(QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior);
s->endGroup();
}
......@@ -84,6 +87,7 @@ void TabSettings::fromSettings(const QString &category, const QSettings *s)
m_smartBackspace = s->value(group + QLatin1String(smartBackspaceKey), m_smartBackspace).toBool();
m_tabSize = s->value(group + QLatin1String(tabSizeKey), m_tabSize).toInt();
m_indentSize = s->value(group + QLatin1String(indentSizeKey), m_indentSize).toInt();
m_indentBraces = s->value(group + QLatin1String(indentBracesKey), m_indentBraces).toBool();
m_tabKeyBehavior = (TabKeyBehavior)s->value(group + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt();
}
......@@ -296,6 +300,7 @@ bool TabSettings::equals(const TabSettings &ts) const
&& m_smartBackspace == ts.m_smartBackspace
&& m_tabSize == ts.m_tabSize
&& m_indentSize == ts.m_indentSize
&& m_indentBraces == ts.m_indentBraces
&& m_tabKeyBehavior == ts.m_tabKeyBehavior;
}
......
......@@ -80,6 +80,7 @@ struct TEXTEDITOR_EXPORT TabSettings
bool m_smartBackspace;
int m_tabSize;
int m_indentSize;
bool m_indentBraces;
TabKeyBehavior m_tabKeyBehavior;
bool equals(const TabSettings &ts) const;
......
......@@ -93,6 +93,7 @@ public:
void setIndentSize(int size);
void setTabSize(int size );
void setIndentBraces(bool indent);
/* Return indentation for the last line of the sequence
* based on the previous lines. */
......@@ -123,6 +124,7 @@ private:
IndenterInternal::Constants m_constants;
int ppHardwareTabSize;
int ppIndentSize;
bool ppIndentBraces;
int ppContinuationIndentSize;
Iterator yyProgramBegin;
......
......@@ -95,6 +95,8 @@ namespace {
line.
* ppCommentOffset is the indentation within a C-style comment,
when it cannot be picked up.
* ppIndentBraces will indent braces flush with an indented code
block.
*/
......@@ -105,6 +107,7 @@ template <class Iterator>
Indenter<Iterator>::Indenter() :
ppHardwareTabSize(8),
ppIndentSize(4),
ppIndentBraces(false),
ppContinuationIndentSize(8),
yyLinizerState(new LinizerState),
yyLine(0),
......@@ -138,6 +141,12 @@ void Indenter<Iterator>::setTabSize(int size )
{
ppHardwareTabSize = size;
}
template <class Iterator>
void Indenter<Iterator>::setIndentBraces(bool indent)
{
ppIndentBraces = indent;
}
/*
Returns the first non-space character in the string t, or
QChar::null if the string is made only of white space.
......@@ -1044,6 +1053,7 @@ int Indenter<Iterator>::indentForBottomLine(const Iterator &current,
int indent;
const QChar hash = QLatin1Char('#');
const QChar openingBrace = QLatin1Char('{');
const QChar closingBrace = QLatin1Char('}');
const QChar colon = QLatin1Char(':');
......@@ -1070,7 +1080,9 @@ int Indenter<Iterator>::indentForBottomLine(const Iterator &current,
indent = indentForStandaloneLine();
}
if ( firstCh == closingBrace ) {
if ( ppIndentBraces && firstCh == openingBrace ) {
indent += ppIndentSize;
} else if ( !ppIndentBraces && firstCh == closingBrace ) {
/*
A closing brace is one level more to the left than the
code it follows.
......@@ -1098,6 +1110,10 @@ int Indenter<Iterator>::indentForBottomLine(const Iterator &current,
}
}
}
if ( ppIndentBraces && indent == ppIndentSize &&
(firstCh == openingBrace || firstCh == closingBrace ) ) {
indent = 0;
}
return qMax( 0, indent );
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment