2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-05-14 23:56:43 +08:00
|
|
|
#include "CodeFolding.h"
|
|
|
|
#include "Constants.h"
|
|
|
|
|
|
|
|
int SynEditFoldRegions::count()
|
|
|
|
{
|
|
|
|
return fRegions.size();
|
|
|
|
}
|
|
|
|
|
2021-06-21 22:01:35 +08:00
|
|
|
PSynEditFoldRegion SynEditFoldRegions::add(bool addEnding, const QChar &openSymbol, const QChar &closeSymbol, const QString &highlight)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
PSynEditFoldRegion region = std::make_shared<SynEditFoldRegion>();
|
|
|
|
region->addEnding = addEnding;
|
|
|
|
region->openSymbol = openSymbol;
|
|
|
|
region->closeSymbol = closeSymbol;
|
|
|
|
region->highlight = highlight;
|
|
|
|
fRegions.push_back(region);
|
2021-06-21 22:01:35 +08:00
|
|
|
return region;
|
2021-05-14 23:56:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PSynEditFoldRegion SynEditFoldRegions::get(int index)
|
|
|
|
{
|
|
|
|
return fRegions.at(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
SynEditCodeFolding::SynEditCodeFolding():
|
2021-10-20 11:14:49 +08:00
|
|
|
fillIndents(false),
|
2021-05-14 23:56:43 +08:00
|
|
|
indentGuides(true),
|
|
|
|
showCollapsedLine(true),
|
|
|
|
collapsedLineColor(QColor("black")),
|
|
|
|
folderBarLinesColor(QColor("black")),
|
|
|
|
indentGuidesColor("gray")
|
|
|
|
{
|
|
|
|
foldRegions.add(true,'{','}',SYNS_AttrSymbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SynEditFoldRange::parentCollapsed()
|
|
|
|
{
|
|
|
|
PSynEditFoldRange parentFold = parent;
|
|
|
|
// Find first parent that is collapsed
|
|
|
|
while (parentFold) {
|
|
|
|
if (parentFold->collapsed) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
parentFold = parentFold->parent;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditFoldRange::move(int count)
|
|
|
|
{
|
|
|
|
fromLine += count;
|
|
|
|
toLine += count;
|
|
|
|
}
|
|
|
|
|
|
|
|
SynEditFoldRange::SynEditFoldRange(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold, int aFromLine, PSynEditFoldRegion aFoldRegion, int aToLine):
|
|
|
|
fromLine(aFromLine),
|
|
|
|
toLine(aToLine),
|
|
|
|
linesCollapsed(0),
|
|
|
|
collapsed(false),
|
|
|
|
allFoldRanges(aAllFold),
|
|
|
|
foldRegion(aFoldRegion),
|
|
|
|
hintMarkLeft(0),
|
|
|
|
parent(aParent)
|
|
|
|
{
|
|
|
|
subFoldRanges = std::make_shared<SynEditFoldRanges>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PSynEditFoldRange SynEditFoldRanges::range(int index)
|
|
|
|
{
|
|
|
|
return mRanges[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditFoldRanges::clear()
|
|
|
|
{
|
|
|
|
mRanges.clear();
|
|
|
|
}
|
|
|
|
|
2021-06-08 21:41:42 +08:00
|
|
|
int SynEditFoldRanges::count() const
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
return mRanges.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
SynEditFoldRanges::SynEditFoldRanges()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-27 01:05:49 +08:00
|
|
|
PSynEditFoldRange SynEditFoldRanges::addByParts(PSynEditFoldRange aParent,
|
|
|
|
PSynEditFoldRanges aAllFold,
|
|
|
|
int aFromLine,
|
|
|
|
PSynEditFoldRegion aFoldRegion,
|
|
|
|
int aToLine)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
PSynEditFoldRange range=std::make_shared<SynEditFoldRange>(aParent,aAllFold, aFromLine,aFoldRegion,aToLine);
|
2021-05-27 01:05:49 +08:00
|
|
|
mRanges.append(range);
|
|
|
|
if (aAllFold && aAllFold.get()!=this) {
|
|
|
|
aAllFold->add(range);
|
|
|
|
}
|
2021-05-14 23:56:43 +08:00
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditFoldRanges::insert(int index, PSynEditFoldRange range)
|
|
|
|
{
|
|
|
|
mRanges.insert(index,range);
|
|
|
|
}
|
|
|
|
|
2021-06-21 22:01:35 +08:00
|
|
|
void SynEditFoldRanges::remove(int index)
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
mRanges.remove(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SynEditFoldRanges::add(PSynEditFoldRange foldRange)
|
|
|
|
{
|
|
|
|
mRanges.push_back(foldRange);
|
|
|
|
}
|
|
|
|
|
2021-06-08 21:41:42 +08:00
|
|
|
PSynEditFoldRange SynEditFoldRanges::operator[](int index) const
|
2021-05-14 23:56:43 +08:00
|
|
|
{
|
|
|
|
return mRanges[index];
|
|
|
|
}
|