2021-04-29 20:54:44 +08:00
|
|
|
#include "CodeFolding.h"
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
int SynEditFoldRegions::count()
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
|
|
|
return fRegions.size();
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
int SynEditFoldRegions::add(bool addEnding, const QChar &openSymbol, const QChar &closeSymbol, const QString &highlight)
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
2021-05-06 20:55:55 +08:00
|
|
|
PSynEditFoldRegion region = std::make_shared<SynEditFoldRegion>();
|
2021-04-29 20:54:44 +08:00
|
|
|
region->addEnding = addEnding;
|
|
|
|
region->openSymbol = openSymbol;
|
|
|
|
region->closeSymbol = closeSymbol;
|
|
|
|
region->highlight = highlight;
|
|
|
|
fRegions.push_back(region);
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
PSynEditFoldRegion SynEditFoldRegions::get(int index)
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
|
|
|
return fRegions.at(index);
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
SynEditCodeFolding::SynEditCodeFolding():
|
2021-04-29 20:54:44 +08:00
|
|
|
indentGuides(true),
|
|
|
|
showCollapsedLine(true),
|
|
|
|
collapsedLineColor(QColor("black")),
|
|
|
|
folderBarLinesColor(QColor("black")),
|
|
|
|
indentGuidesColor("gray")
|
|
|
|
{
|
|
|
|
foldRegions.add(true,'{','}',"Symbol");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
bool SynEditFoldRange::parentCollapsed()
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
|
|
|
PSynEditFoldRange parentFold = parent;
|
|
|
|
// Find first parent that is collapsed
|
|
|
|
while (parentFold) {
|
|
|
|
if (parentFold->collapsed) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
parentFold = parentFold->parent;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
void SynEditFoldRange::move(int count)
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
|
|
|
fromLine += count;
|
|
|
|
toLine += count;
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
SynEditFoldRange::SynEditFoldRange(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold, int aFromLine, PSynEditFoldRegion aFoldRegion, int aToLine):
|
2021-04-29 20:54:44 +08:00
|
|
|
fromLine(aFromLine),
|
|
|
|
toLine(aToLine),
|
|
|
|
linesCollapsed(0),
|
|
|
|
collapsed(false),
|
|
|
|
allFoldRanges(aAllFold),
|
|
|
|
foldRegion(aFoldRegion),
|
|
|
|
hintMarkLeft(0),
|
|
|
|
parent(aParent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
PSynEditFoldRange SynEditFoldRanges::foldRange(int index)
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
|
|
|
return ranges[index];
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
int SynEditFoldRanges::count()
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
|
|
|
return ranges.size();
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
SynEditFoldRanges::SynEditFoldRanges()
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
PSynEditFoldRange SynEditFoldRanges::addByParts(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold, int aFromLine, PSynEditFoldRegion aFoldRegion, int aToLine)
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
2021-05-06 20:55:55 +08:00
|
|
|
PSynEditFoldRange range=std::make_shared<SynEditFoldRange>(aParent,aAllFold, aFromLine,aFoldRegion,aToLine);
|
2021-04-29 20:54:44 +08:00
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
int SynEditFoldRanges::remove(int index)
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
|
|
|
ranges.erase(ranges.begin()+index);
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:55:55 +08:00
|
|
|
void SynEditFoldRanges::addObject(PSynEditFoldRange foldRange)
|
2021-04-29 20:54:44 +08:00
|
|
|
{
|
|
|
|
ranges.push_back(foldRange);
|
|
|
|
}
|