synedit: added subblocks for codefolding

git-svn-id: trunk@9663 -
This commit is contained in:
mattias 2006-07-22 12:53:15 +00:00
parent e76034130a
commit 06cd9beabc
2 changed files with 36 additions and 16 deletions

View File

@ -216,7 +216,8 @@ type
property CodeFoldRange: TSynCustomHighlighterRange read FCodeFoldRange;
function GetRangeClass: TSynCustomHighlighterRangeClass; virtual;
function TopCodeFoldBlockType: Pointer;
function StartCodeFoldBlock(ABlockType: Pointer): TSynCustomCodeFoldBlock; virtual;
function StartCodeFoldBlock(ABlockType: Pointer; SubBlock: boolean = false
): TSynCustomCodeFoldBlock; virtual;
procedure EndCodeFoldBlock; virtual;
{$ENDIF}
public
@ -1199,17 +1200,31 @@ begin
Result:=nil;
end;
function TSynCustomHighlighter.StartCodeFoldBlock(ABlockType: Pointer
): TSynCustomCodeFoldBlock;
function TSynCustomHighlighter.StartCodeFoldBlock(ABlockType: Pointer;
SubBlock: boolean): TSynCustomCodeFoldBlock;
begin
Result:=CodeFoldRange.Add(ABlockType);
if SubBlock then begin
Result:=CodeFoldRange.Top;
if (Result.BlockType=ABlockType) then
Result.Level:=Result.Level+1
else
Result:=CodeFoldRange.Add(ABlockType);
end else
Result:=CodeFoldRange.Add(ABlockType);
end;
procedure TSynCustomHighlighter.EndCodeFoldBlock;
var
TopBlock: TSynCustomCodeFoldBlock;
begin
CodeFoldRange.Pop;
if FMinimumCodeFoldBlockLevel>CodeFoldRange.CodeFoldStackSize then
FMinimumCodeFoldBlockLevel:=CodeFoldRange.CodeFoldStackSize;
TopBlock:=CodeFoldRange.Top;
if TopBlock.Level>0 then
TopBlock.Level:=TopBlock.Level-1
else begin
CodeFoldRange.Pop;
if FMinimumCodeFoldBlockLevel>CodeFoldRange.CodeFoldStackSize then
FMinimumCodeFoldBlockLevel:=CodeFoldRange.CodeFoldStackSize;
end;
end;
{$ENDIF}

View File

@ -83,8 +83,7 @@ type
TPascalCodeFoldBlockType = (
cfbtNone,
cfbtBeginEnd,
cfbtNestedComment,
cfbtTryEnd
cfbtNestedComment
);
{$ENDIF}
@ -252,8 +251,8 @@ type
function GetIdentChars: TSynIdentChars; override;
function IsFilterStored: boolean; override; //mh 2000-10-08
{$IFDEF SYN_LAZARUS}
function StartPascalCodeFoldBlock(ABlockType: TPascalCodeFoldBlockType
): TSynCustomCodeFoldBlock;
function StartPascalCodeFoldBlock(ABlockType: TPascalCodeFoldBlockType;
SubBlock: boolean = false): TSynCustomCodeFoldBlock;
{$ENDIF}
public
{$IFNDEF SYN_CPPB_1} class {$ENDIF}
@ -635,7 +634,7 @@ begin
{$IFDEF SYN_LAZARUS}
//debugln('TSynPasSyn.Func23 END ',dbgs(ord(TopPascalCodeFoldBlockType)),' LineNumber=',dbgs(fLineNumber));
//CodeFoldRange.WriteDebugReport;
if TopPascalCodeFoldBlockType in [cfbtBeginEnd, cfbtTryEnd] then
if TopPascalCodeFoldBlockType=cfbtBeginEnd then
EndCodeFoldBlock;
{$ENDIF}
end else begin
@ -662,7 +661,12 @@ begin
begin
if fRange = rsProperty then Result := tkKey else Result := tkIdentifier;
end else
if KeyComp('Case') then Result := tkKey else Result := tkIdentifier;
if KeyComp('Case') then begin
{$IFDEF SYN_LAZARUS}
StartPascalCodeFoldBlock(cfbtBeginEnd,true);
{$ENDIF}
Result := tkKey;
end else Result := tkIdentifier;
end;
{$IFDEF SYN_LAZARUS}
@ -815,7 +819,7 @@ begin
if KeyComp('Try') then
{$IFDEF SYN_LAZARUS}
begin
StartPascalCodeFoldBlock(cfbtTryEnd);
StartPascalCodeFoldBlock(cfbtBeginEnd,true);
Result := tkKey;
end else
{$ELSE}
@ -1816,10 +1820,11 @@ begin
end;
function TSynPasSyn.StartPascalCodeFoldBlock(
ABlockType: TPascalCodeFoldBlockType): TSynCustomCodeFoldBlock;
ABlockType: TPascalCodeFoldBlockType;
SubBlock: boolean): TSynCustomCodeFoldBlock;
begin
Result:=TSynCustomCodeFoldBlock(
inherited StartCodeFoldBlock(Pointer(PtrInt(ABlockType))));
inherited StartCodeFoldBlock(Pointer(PtrInt(ABlockType)),SubBlock));
end;
{$endif}