forked from qt-creator/qt-creator
added "auto-fold first comment"-option to the editor
Convenient when you don't want to see all the big license headers.
This commit is contained in:
@@ -611,12 +611,44 @@ bool BaseTextEditor::open(const QString &fileName)
|
||||
{
|
||||
if (d->m_document->open(fileName)) {
|
||||
moveCursor(QTextCursor::Start);
|
||||
if (d->m_displaySettings.m_autoFoldFirstComment)
|
||||
d->collapseLicenseHeader();
|
||||
setReadOnly(d->m_document->hasDecodingError());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Collapses the first comment in a file, if there is only whitespace above
|
||||
*/
|
||||
void BaseTextEditorPrivate::collapseLicenseHeader()
|
||||
{
|
||||
QTextDocument *doc = q->document();
|
||||
TextEditDocumentLayout *documentLayout = qobject_cast<TextEditDocumentLayout*>(doc->documentLayout());
|
||||
QTC_ASSERT(documentLayout, return);
|
||||
QTextBlock block = doc->firstBlock();
|
||||
const TabSettings &ts = m_document->tabSettings();
|
||||
while (block.isValid()) {
|
||||
TextBlockUserData *data = TextBlockUserData::canCollapse(block);
|
||||
if (data && block.next().isVisible()) {
|
||||
QChar character;
|
||||
static_cast<TextBlockUserData*>(data)->collapseAtPos(&character);
|
||||
if (character != QLatin1Char('+'))
|
||||
break; // not a comment
|
||||
TextBlockUserData::doCollapse(block, false);
|
||||
moveCursorVisible();
|
||||
documentLayout->requestUpdate();
|
||||
documentLayout->emitDocumentSizeChanged();
|
||||
break;
|
||||
}
|
||||
QString text = block.text();
|
||||
if (ts.firstNonSpace(text) < text.size())
|
||||
break;
|
||||
block = block.next();
|
||||
}
|
||||
}
|
||||
|
||||
const Utils::ChangeSet &BaseTextEditor::changeSet() const
|
||||
{
|
||||
return d->m_changeSet;
|
||||
@@ -1618,9 +1650,9 @@ int Parenthesis::collapseAtPos(const Parentheses &parentheses, QChar *character)
|
||||
}
|
||||
|
||||
|
||||
int TextBlockUserData::collapseAtPos() const
|
||||
int TextBlockUserData::collapseAtPos(QChar *character) const
|
||||
{
|
||||
return Parenthesis::collapseAtPos(m_parentheses);
|
||||
return Parenthesis::collapseAtPos(m_parentheses, character);
|
||||
}
|
||||
|
||||
int TextBlockUserData::braceDepthDelta() const
|
||||
|
@@ -173,7 +173,7 @@ public:
|
||||
static QTextBlock testCollapse(const QTextBlock& block);
|
||||
static void doCollapse(const QTextBlock& block, bool visible);
|
||||
|
||||
int collapseAtPos() const;
|
||||
int collapseAtPos(QChar *character = 0) const;
|
||||
|
||||
enum MatchType { NoMatch, Match, Mismatch };
|
||||
static MatchType checkOpenParenthesis(QTextCursor *cursor, QChar c);
|
||||
|
@@ -196,6 +196,7 @@ public:
|
||||
int suggestedVisibleCollapsedBlockNumber;
|
||||
void clearVisibleCollapsedBlock();
|
||||
bool m_mouseOnCollapsedMarker;
|
||||
void collapseLicenseHeader();
|
||||
|
||||
QBasicTimer autoScrollTimer;
|
||||
void updateMarksLineNumber();
|
||||
|
@@ -45,6 +45,7 @@ static const char * const highlightBlocksKey = "HighlightBlocksKey";
|
||||
static const char * const animateMatchingParenthesesKey= "AnimateMatchingParenthesesKey";
|
||||
static const char * const mouseNavigationKey = "MouseNavigation";
|
||||
static const char * const markTextChangesKey = "MarkTextChanges";
|
||||
static const char * const autoFoldFirstCommentKey= "AutoFoldFirstComment";
|
||||
static const char * const groupPostfix = "DisplaySettings";
|
||||
|
||||
namespace TextEditor {
|
||||
@@ -60,7 +61,8 @@ DisplaySettings::DisplaySettings() :
|
||||
m_highlightBlocks(false),
|
||||
m_animateMatchingParentheses(true),
|
||||
m_mouseNavigation(true),
|
||||
m_markTextChanges(true)
|
||||
m_markTextChanges(true),
|
||||
m_autoFoldFirstComment(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -81,6 +83,7 @@ void DisplaySettings::toSettings(const QString &category, QSettings *s) const
|
||||
s->setValue(QLatin1String(animateMatchingParenthesesKey), m_animateMatchingParentheses);
|
||||
s->setValue(QLatin1String(mouseNavigationKey), m_mouseNavigation);
|
||||
s->setValue(QLatin1String(markTextChangesKey), m_markTextChanges);
|
||||
s->setValue(QLatin1String(autoFoldFirstCommentKey), m_autoFoldFirstComment);
|
||||
s->endGroup();
|
||||
}
|
||||
|
||||
@@ -104,6 +107,7 @@ void DisplaySettings::fromSettings(const QString &category, const QSettings *s)
|
||||
m_animateMatchingParentheses = s->value(group + QLatin1String(animateMatchingParenthesesKey), m_animateMatchingParentheses).toBool();
|
||||
m_mouseNavigation = s->value(group + QLatin1String(mouseNavigationKey), m_mouseNavigation).toBool();
|
||||
m_markTextChanges = s->value(group + QLatin1String(markTextChangesKey), m_markTextChanges).toBool();
|
||||
m_autoFoldFirstComment = s->value(group + QLatin1String(autoFoldFirstCommentKey), m_autoFoldFirstComment).toBool();
|
||||
}
|
||||
|
||||
bool DisplaySettings::equals(const DisplaySettings &ds) const
|
||||
@@ -119,6 +123,7 @@ bool DisplaySettings::equals(const DisplaySettings &ds) const
|
||||
&& m_animateMatchingParentheses == ds.m_animateMatchingParentheses
|
||||
&& m_mouseNavigation == ds.m_mouseNavigation
|
||||
&& m_markTextChanges == ds.m_markTextChanges
|
||||
&& m_autoFoldFirstComment== ds.m_autoFoldFirstComment
|
||||
;
|
||||
}
|
||||
|
||||
|
@@ -56,6 +56,7 @@ struct TEXTEDITOR_EXPORT DisplaySettings
|
||||
bool m_animateMatchingParentheses;
|
||||
bool m_mouseNavigation;
|
||||
bool m_markTextChanges;
|
||||
bool m_autoFoldFirstComment;
|
||||
|
||||
bool equals(const DisplaySettings &ds) const;
|
||||
};
|
||||
|
@@ -102,7 +102,8 @@ QWidget *DisplaySettingsPage::createPage(QWidget *parent)
|
||||
<< ' ' << m_d->m_page.visualizeWhitespace->text()
|
||||
<< ' ' << m_d->m_page.animateMatchingParentheses->text()
|
||||
<< ' ' << m_d->m_page.enableTextWrapping->text()
|
||||
<< ' ' << m_d->m_page.mouseNavigation->text();
|
||||
<< ' ' << m_d->m_page.mouseNavigation->text()
|
||||
<< ' ' << m_d->m_page.autoFoldFirstComment->text();
|
||||
m_d->m_searchKeywords.remove(QLatin1Char('&'));
|
||||
}
|
||||
return w;
|
||||
@@ -139,6 +140,7 @@ void DisplaySettingsPage::settingsFromUI(DisplaySettings &displaySettings) const
|
||||
displaySettings.m_animateMatchingParentheses = m_d->m_page.animateMatchingParentheses->isChecked();
|
||||
displaySettings.m_mouseNavigation = m_d->m_page.mouseNavigation->isChecked();
|
||||
displaySettings.m_markTextChanges = m_d->m_page.markTextChanges->isChecked();
|
||||
displaySettings.m_autoFoldFirstComment = m_d->m_page.autoFoldFirstComment->isChecked();
|
||||
}
|
||||
|
||||
void DisplaySettingsPage::settingsToUI()
|
||||
@@ -155,6 +157,7 @@ void DisplaySettingsPage::settingsToUI()
|
||||
m_d->m_page.animateMatchingParentheses->setChecked(displaySettings.m_animateMatchingParentheses);
|
||||
m_d->m_page.mouseNavigation->setChecked(displaySettings.m_mouseNavigation);
|
||||
m_d->m_page.markTextChanges->setChecked(displaySettings.m_markTextChanges);
|
||||
m_d->m_page.autoFoldFirstComment->setChecked(displaySettings.m_autoFoldFirstComment);
|
||||
}
|
||||
|
||||
DisplaySettings DisplaySettingsPage::displaySettings() const
|
||||
|
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>448</width>
|
||||
<width>450</width>
|
||||
<height>330</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -61,7 +61,7 @@
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="markTextChanges">
|
||||
<property name="text">
|
||||
<string>Mark text changes</string>
|
||||
<string>Mark &text changes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -78,7 +78,14 @@
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="animateMatchingParentheses">
|
||||
<property name="text">
|
||||
<string>Animate matching parentheses</string>
|
||||
<string>&Animate matching parentheses</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="autoFoldFirstComment">
|
||||
<property name="text">
|
||||
<string>Auto-fold first &comment</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Reference in New Issue
Block a user