SynEdit: begin refactor SynEdit.Marks (use tree for storage).

git-svn-id: trunk@27764 -
This commit is contained in:
martin 2010-10-19 21:48:29 +00:00
parent 58ea9148ea
commit 7e8ea9c121
2 changed files with 23 additions and 18 deletions

View File

@ -7402,11 +7402,11 @@ var
ASrcEdit: TSourceEditor;
ASynEdit: TSynEdit;
EditCaret: TPoint;
LineMarks: TSynEditMarks;
AMark: TSourceMark;
i: integer;
HintStr: String;
CurHint: String;
MLine: TSynEditMarkLine;
begin
// hide other hints
//debugln('TSourceNotebook.ShowSynEditHint A');
@ -7422,17 +7422,25 @@ begin
if EditPos.X<ASynEdit.Gutter.Width then begin
// hint for a gutter item
if EditorOpts.ShowGutterHints then begin
ASynEdit.Marks.GetMarksForLine(EditCaret.Y,LineMarks);
HintStr:='';
for i:=Low(TSynEditMarks) to High(TSynEditMarks) do begin
if not (LineMarks[i] is TSourceSynMark) then continue;
AMark := TSourceSynMark(LineMarks[i]).SourceMark;
if AMark = nil then continue;
CurHint:=AMark.GetHint;
if CurHint='' then continue;
if HintStr<>'' then HintStr:=HintStr+LineEnding;
HintStr:=HintStr+CurHint;
MLine := ASynEdit.Marks.Line[EditCaret.Y];
if MLine <> nil then begin
if ASynEdit.BookMarkOptions.DrawBookmarksFirst then
MLine.Sort(smsoBookmarkFirst, smsoColumn)
else
MLine.Sort(smsoBookMarkLast, smsoColumn);
for i := 0 to MLine.Count - 1 do begin
if not (MLine[i] is TSourceSynMark) then continue;
AMark := TSourceSynMark(MLine[i]).SourceMark;
if AMark = nil then continue;
CurHint:=AMark.GetHint;
if CurHint='' then continue;
if HintStr<>'' then HintStr:=HintStr+LineEnding;
HintStr:=HintStr+CurHint;
end;
end;
if HintStr<>'' then
ActivateHint(MousePos,'',HintStr);
end;

View File

@ -63,7 +63,7 @@ type
public
constructor Create(AOwner: TSourceMark; AEditor: TSourceEditorInterface);
destructor Destroy; override;
function GetEdit: TSynEdit; override;
function GetEdit: TSynEdit;
property SourceMark: TSourceMark read FSourceMark write FSourceMark;
end;
@ -88,7 +88,7 @@ type
function Add(Item: TSourceSynMark): Integer;
property Items[Index: Integer]: TSourceSynMark read GetSM write PutSM; default;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
procedure InvalidateLine(ALine: Integer);
procedure DoChange(AChanges: TSynEditMarkChangeReasons);
procedure DeleteWithSourceEditor(ASrcEditor: TSourceEditorInterface);
function IndexOfSourceEditor(AEditor: TSourceEditorInterface): Integer;
procedure IncChangeLock;
@ -460,12 +460,12 @@ begin
Result := inherited Add(Item);
end;
procedure TSourceSynMarkList.InvalidateLine(ALine: Integer);
procedure TSourceSynMarkList.DoChange(AChanges: TSynEditMarkChangeReasons);
var
i: Integer;
begin
for i := 0 to Count - 1 do
Items[i].GetEdit.InvalidateLine(ALine);
Items[i].DoChange(AChanges);
end;
procedure TSourceSynMarkList.DeleteWithSourceEditor(
@ -609,7 +609,6 @@ begin
FVisible := AValue;
if FSynMarkLock = 0 then
FSynMarks.Visible := AValue;
if EditorUpdateRequired then DoLineUpdate(True);
Changed;
end;
@ -626,7 +625,7 @@ procedure TSourceMark.DoLineUpdate(Force: Boolean = False);
begin
if Line <= 0 then Exit;
if Visible or Force then
FSynMarks.InvalidateLine(Line);
FSynMarks.DoChange([smcrChanged]);
end;
procedure TSourceMark.SetData(const AValue: TObject);
@ -674,14 +673,12 @@ end;
procedure TSourceMark.SetLine(const Value: Integer);
begin
if Line=Value then exit;
if EditorUpdateRequired then DoLineUpdate;
if FSourceMarks<>nil then FSourceMarks.fSortedItems.Remove(Self);
FLine := Value;
if FSynMarkLock = 0 then
FSynMarks.Line := Value;
if FSourceMarks<>nil then FSourceMarks.fSortedItems.Add(Self);
DoPositionChanged;
if EditorUpdateRequired then DoLineUpdate;
Changed;
end;