mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 23:49:28 +02:00
synedit: some changes for marks
- move marks compare functions to the SynEditMarks - return marks sorted by drawing order in GetMarksForLine - increase default gutter width for marks (we did not include LeftOffset of the bookmark options) git-svn-id: trunk@18952 -
This commit is contained in:
parent
d999a5db3b
commit
0103c56f6a
@ -76,6 +76,8 @@ type
|
||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||
end;
|
||||
|
||||
function DoMarksCompareBookmarksFirst(Item1, Item2: Pointer): Integer;
|
||||
function DoMarksCompareBookmarksLast(Item1, Item2: Pointer): Integer;
|
||||
|
||||
implementation
|
||||
uses SynEdit;
|
||||
@ -83,6 +85,73 @@ uses SynEdit;
|
||||
type // This is until InvalidateGutterLines, can be moved to an accessible place
|
||||
SynEditAccess = Class(TCustomSynEdit);
|
||||
|
||||
function DoMarksCompareBookmarksFirst(Item1, Item2: Pointer): Integer;
|
||||
var
|
||||
Mark1: TSynEditMark absolute Item1;
|
||||
Mark2: TSynEditMark absolute Item2;
|
||||
begin
|
||||
Result := 0;
|
||||
if Mark1 = Mark2 then Exit;
|
||||
|
||||
if Mark1.IsBookmark then
|
||||
Result := -1
|
||||
else
|
||||
if Mark2.IsBookmark then
|
||||
Result := 1
|
||||
else
|
||||
if Mark1.Priority < Mark2.Priority then
|
||||
Result := 1
|
||||
else
|
||||
if Mark1.Priority > Mark2.Priority then
|
||||
Result := -1;
|
||||
end;
|
||||
|
||||
function DoMarksCompareBookmarksLast(Item1, Item2: Pointer): Integer;
|
||||
var
|
||||
Mark1: TSynEditMark absolute Item1;
|
||||
Mark2: TSynEditMark absolute Item2;
|
||||
begin
|
||||
Result := 0;
|
||||
if Mark1 = Mark2 then Exit;
|
||||
|
||||
if Mark1.IsBookmark then
|
||||
Result := 1
|
||||
else
|
||||
if Mark2.IsBookmark then
|
||||
Result := -1
|
||||
else
|
||||
if Mark1.Priority < Mark2.Priority then
|
||||
Result := 1
|
||||
else
|
||||
if Mark1.Priority > Mark2.Priority then
|
||||
Result := -1;
|
||||
end;
|
||||
|
||||
procedure SortMarks(var Marks: TSynEditMarks; Compare: TListSortCompare);
|
||||
var
|
||||
i, j, LastMark: Integer;
|
||||
P: Pointer;
|
||||
begin
|
||||
for i := Low(Marks) to High(Marks) do
|
||||
if Marks[i] = nil then
|
||||
begin
|
||||
LastMark := i - 1;
|
||||
break;
|
||||
end;
|
||||
// insert sort is the best for our items count
|
||||
for i := Low(Marks) + 1 to LastMark do
|
||||
begin
|
||||
P := Marks[i];
|
||||
j := i - 1;
|
||||
while (j >= Low(Marks)) and (Compare(P, Marks[j]) < 1) do
|
||||
begin
|
||||
Marks[j + 1] := Marks[j];
|
||||
j := j - 1;
|
||||
end;
|
||||
Marks[j + 1] := TSynEditMark(P);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TSynEditMark }
|
||||
|
||||
procedure TSynEditMark.SetPriority(const AValue: integer);
|
||||
@ -227,6 +296,11 @@ begin
|
||||
if cnt = maxMarks then break;
|
||||
end;
|
||||
end;
|
||||
if Assigned(FEdit) then
|
||||
if TSynEdit(FEdit).BookMarkOptions.DrawBookmarksFirst then
|
||||
SortMarks(marks, @DoMarksCompareBookmarksFirst)
|
||||
else
|
||||
SortMarks(marks, @DoMarksCompareBookmarksLast);
|
||||
end;
|
||||
|
||||
procedure TSynEditMarkList.Insert(Index: Integer; Item: TSynEditMark);
|
||||
|
@ -38,7 +38,7 @@ uses
|
||||
procedure TSynGutterMarks.DoChange(Sender: TObject);
|
||||
begin
|
||||
if AutoSize then
|
||||
FWidth := 22;
|
||||
FWidth := RealGutterWidth(0);
|
||||
inherited DoChange(Sender);
|
||||
end;
|
||||
|
||||
@ -49,7 +49,7 @@ begin
|
||||
FBookMarkOpt := TSynEdit(SynEdit).BookMarkOptions;
|
||||
FInternalImage := nil;
|
||||
|
||||
FWidth := 22;
|
||||
FWidth := 23;
|
||||
end;
|
||||
|
||||
destructor TSynGutterMarks.Destroy;
|
||||
@ -58,60 +58,17 @@ begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TSynGutterMarks.RealGutterWidth(CharWidth : integer) : integer;
|
||||
function TSynGutterMarks.RealGutterWidth(CharWidth: integer) : integer;
|
||||
begin
|
||||
If Visible then
|
||||
Result := Width
|
||||
if Visible then
|
||||
Result := 22 + FBookMarkOpt.LeftMargin
|
||||
else
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function DoMarksCompareBookmarksFirst(Item1, Item2: Pointer): Integer;
|
||||
var
|
||||
Mark1: TSynEditMark absolute Item1;
|
||||
Mark2: TSynEditMark absolute Item2;
|
||||
begin
|
||||
Result := 0;
|
||||
if Mark1 = Mark2 then Exit;
|
||||
|
||||
if Mark1.IsBookmark then
|
||||
Result := -1
|
||||
else
|
||||
if Mark2.IsBookmark then
|
||||
Result := 1
|
||||
else
|
||||
if Mark1.Priority < Mark2.Priority then
|
||||
Result := 1
|
||||
else
|
||||
if Mark1.Priority > Mark2.Priority then
|
||||
Result := -1;
|
||||
end;
|
||||
|
||||
function DoMarksCompareBookmarksLast(Item1, Item2: Pointer): Integer;
|
||||
var
|
||||
Mark1: TSynEditMark absolute Item1;
|
||||
Mark2: TSynEditMark absolute Item2;
|
||||
begin
|
||||
Result := 0;
|
||||
if Mark1 = Mark2 then Exit;
|
||||
|
||||
if Mark1.IsBookmark then
|
||||
Result := 1
|
||||
else
|
||||
if Mark2.IsBookmark then
|
||||
Result := -1
|
||||
else
|
||||
if Mark1.Priority < Mark2.Priority then
|
||||
Result := 1
|
||||
else
|
||||
if Mark1.Priority > Mark2.Priority then
|
||||
Result := -1;
|
||||
end;
|
||||
|
||||
procedure TSynGutterMarks.Paint(Canvas : TCanvas; AClip : TRect; FirstLine, LastLine : integer);
|
||||
var
|
||||
i: integer;
|
||||
bHasOtherMarks: boolean;
|
||||
aGutterOffs: PIntArray;
|
||||
dc: HDC;
|
||||
LineHeight: Integer;
|
||||
|
Loading…
Reference in New Issue
Block a user