forked from qt-creator/qt-creator
Adding indented braces option.
Merge-request: 1949 Reviewed-by: Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
This commit is contained in:
committed by
Thorbjørn Lindeijer
parent
a5252a4463
commit
fa5f9246c2
@@ -1573,6 +1573,7 @@ static void indentCPPBlock(const CPPEditor::TabSettings &ts,
|
|||||||
Indenter &indenter = Indenter::instance();
|
Indenter &indenter = Indenter::instance();
|
||||||
indenter.setIndentSize(ts.m_indentSize);
|
indenter.setIndentSize(ts.m_indentSize);
|
||||||
indenter.setTabSize(ts.m_tabSize);
|
indenter.setTabSize(ts.m_tabSize);
|
||||||
|
indenter.setIndentBraces(ts.m_indentBraces);
|
||||||
|
|
||||||
const TextEditor::TextBlockIterator current(block);
|
const TextEditor::TextBlockIterator current(block);
|
||||||
const int indent = indenter.indentForBottomLine(current, programBegin, programEnd, typedChar);
|
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_smartBackspace = m_d->m_page.smartBackspace->isChecked();
|
||||||
tabSettings.m_tabSize = m_d->m_page.tabSize->value();
|
tabSettings.m_tabSize = m_d->m_page.tabSize->value();
|
||||||
tabSettings.m_indentSize = m_d->m_page.indentSize->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();
|
tabSettings.m_tabKeyBehavior = (TabSettings::TabKeyBehavior)m_d->m_page.tabKeyBehavior->currentIndex();
|
||||||
|
|
||||||
storageSettings.m_cleanWhitespace = m_d->m_page.cleanWhitespace->isChecked();
|
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.smartBackspace->setChecked(tabSettings.m_smartBackspace);
|
||||||
m_d->m_page.tabSize->setValue(tabSettings.m_tabSize);
|
m_d->m_page.tabSize->setValue(tabSettings.m_tabSize);
|
||||||
m_d->m_page.indentSize->setValue(tabSettings.m_indentSize);
|
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);
|
m_d->m_page.tabKeyBehavior->setCurrentIndex(tabSettings.m_tabKeyBehavior);
|
||||||
|
|
||||||
const StorageSettings &storageSettings = m_d->m_storageSettings;
|
const StorageSettings &storageSettings = m_d->m_storageSettings;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>463</width>
|
<width>615</width>
|
||||||
<height>421</height>
|
<height>421</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1" rowspan="3">
|
<item row="0" column="1" rowspan="4">
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="4" rowspan="3">
|
<item row="0" column="4" rowspan="4">
|
||||||
<spacer name="horizontalSpacer_3">
|
<spacer name="horizontalSpacer_3">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
@@ -133,6 +133,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</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&s</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ static const char *smartBackspaceKey = "SmartBackspace";
|
|||||||
static const char *autoIndentKey = "AutoIndent";
|
static const char *autoIndentKey = "AutoIndent";
|
||||||
static const char *tabSizeKey = "TabSize";
|
static const char *tabSizeKey = "TabSize";
|
||||||
static const char *indentSizeKey = "IndentSize";
|
static const char *indentSizeKey = "IndentSize";
|
||||||
|
static const char *indentBracesKey = "IndentBraces";
|
||||||
static const char *tabKeyBehaviorKey = "TabKeyBehavior";
|
static const char *tabKeyBehaviorKey = "TabKeyBehavior";
|
||||||
static const char *groupPostfix = "TabSettings";
|
static const char *groupPostfix = "TabSettings";
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ TabSettings::TabSettings() :
|
|||||||
m_smartBackspace(false),
|
m_smartBackspace(false),
|
||||||
m_tabSize(8),
|
m_tabSize(8),
|
||||||
m_indentSize(4),
|
m_indentSize(4),
|
||||||
|
m_indentBraces(false),
|
||||||
m_tabKeyBehavior(TabNeverIndents)
|
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(smartBackspaceKey), m_smartBackspace);
|
||||||
s->setValue(QLatin1String(tabSizeKey), m_tabSize);
|
s->setValue(QLatin1String(tabSizeKey), m_tabSize);
|
||||||
s->setValue(QLatin1String(indentSizeKey), m_indentSize);
|
s->setValue(QLatin1String(indentSizeKey), m_indentSize);
|
||||||
|
s->setValue(QLatin1String(indentBracesKey), m_indentBraces);
|
||||||
s->setValue(QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior);
|
s->setValue(QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior);
|
||||||
s->endGroup();
|
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_smartBackspace = s->value(group + QLatin1String(smartBackspaceKey), m_smartBackspace).toBool();
|
||||||
m_tabSize = s->value(group + QLatin1String(tabSizeKey), m_tabSize).toInt();
|
m_tabSize = s->value(group + QLatin1String(tabSizeKey), m_tabSize).toInt();
|
||||||
m_indentSize = s->value(group + QLatin1String(indentSizeKey), m_indentSize).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();
|
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_smartBackspace == ts.m_smartBackspace
|
||||||
&& m_tabSize == ts.m_tabSize
|
&& m_tabSize == ts.m_tabSize
|
||||||
&& m_indentSize == ts.m_indentSize
|
&& m_indentSize == ts.m_indentSize
|
||||||
|
&& m_indentBraces == ts.m_indentBraces
|
||||||
&& m_tabKeyBehavior == ts.m_tabKeyBehavior;
|
&& m_tabKeyBehavior == ts.m_tabKeyBehavior;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ struct TEXTEDITOR_EXPORT TabSettings
|
|||||||
bool m_smartBackspace;
|
bool m_smartBackspace;
|
||||||
int m_tabSize;
|
int m_tabSize;
|
||||||
int m_indentSize;
|
int m_indentSize;
|
||||||
|
bool m_indentBraces;
|
||||||
TabKeyBehavior m_tabKeyBehavior;
|
TabKeyBehavior m_tabKeyBehavior;
|
||||||
|
|
||||||
bool equals(const TabSettings &ts) const;
|
bool equals(const TabSettings &ts) const;
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ public:
|
|||||||
|
|
||||||
void setIndentSize(int size);
|
void setIndentSize(int size);
|
||||||
void setTabSize(int size );
|
void setTabSize(int size );
|
||||||
|
void setIndentBraces(bool indent);
|
||||||
|
|
||||||
/* Return indentation for the last line of the sequence
|
/* Return indentation for the last line of the sequence
|
||||||
* based on the previous lines. */
|
* based on the previous lines. */
|
||||||
@@ -123,6 +124,7 @@ private:
|
|||||||
IndenterInternal::Constants m_constants;
|
IndenterInternal::Constants m_constants;
|
||||||
int ppHardwareTabSize;
|
int ppHardwareTabSize;
|
||||||
int ppIndentSize;
|
int ppIndentSize;
|
||||||
|
bool ppIndentBraces;
|
||||||
int ppContinuationIndentSize;
|
int ppContinuationIndentSize;
|
||||||
|
|
||||||
Iterator yyProgramBegin;
|
Iterator yyProgramBegin;
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ namespace {
|
|||||||
line.
|
line.
|
||||||
* ppCommentOffset is the indentation within a C-style comment,
|
* ppCommentOffset is the indentation within a C-style comment,
|
||||||
when it cannot be picked up.
|
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() :
|
Indenter<Iterator>::Indenter() :
|
||||||
ppHardwareTabSize(8),
|
ppHardwareTabSize(8),
|
||||||
ppIndentSize(4),
|
ppIndentSize(4),
|
||||||
|
ppIndentBraces(false),
|
||||||
ppContinuationIndentSize(8),
|
ppContinuationIndentSize(8),
|
||||||
yyLinizerState(new LinizerState),
|
yyLinizerState(new LinizerState),
|
||||||
yyLine(0),
|
yyLine(0),
|
||||||
@@ -138,6 +141,12 @@ void Indenter<Iterator>::setTabSize(int size )
|
|||||||
{
|
{
|
||||||
ppHardwareTabSize = 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
|
Returns the first non-space character in the string t, or
|
||||||
QChar::null if the string is made only of white space.
|
QChar::null if the string is made only of white space.
|
||||||
@@ -1044,6 +1053,7 @@ int Indenter<Iterator>::indentForBottomLine(const Iterator ¤t,
|
|||||||
int indent;
|
int indent;
|
||||||
|
|
||||||
const QChar hash = QLatin1Char('#');
|
const QChar hash = QLatin1Char('#');
|
||||||
|
const QChar openingBrace = QLatin1Char('{');
|
||||||
const QChar closingBrace = QLatin1Char('}');
|
const QChar closingBrace = QLatin1Char('}');
|
||||||
const QChar colon = QLatin1Char(':');
|
const QChar colon = QLatin1Char(':');
|
||||||
|
|
||||||
@@ -1070,7 +1080,9 @@ int Indenter<Iterator>::indentForBottomLine(const Iterator ¤t,
|
|||||||
indent = indentForStandaloneLine();
|
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
|
A closing brace is one level more to the left than the
|
||||||
code it follows.
|
code it follows.
|
||||||
@@ -1098,6 +1110,10 @@ int Indenter<Iterator>::indentForBottomLine(const Iterator ¤t,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( ppIndentBraces && indent == ppIndentSize &&
|
||||||
|
(firstCh == openingBrace || firstCh == closingBrace ) ) {
|
||||||
|
indent = 0;
|
||||||
|
}
|
||||||
return qMax( 0, indent );
|
return qMax( 0, indent );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user