This file is indexed.

/usr/lib/lazarus/0.9.30.4/ide/sourcemarks.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
{
/***************************************************************************
                             SourceMarks.pas
                             ---------------

 ***************************************************************************/

 ***************************************************************************
 *                                                                         *
 *   This source 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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This code 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.                              *
 *                                                                         *
 *   A copy of the GNU General Public License is available on the World    *
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 *   obtain it by writing to the Free Software Foundation,                 *
 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 *                                                                         *
 ***************************************************************************

  Author: Mattias Gaertner
  
  Abstract:
    All source editor marks, except the bookmarks, are managed by the
    SourceEditorMarks. It extends the TSynEditMark and combines all marks of
    all editors.
}
unit SourceMarks;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Graphics, Controls, MenuIntf, LCLProc,
  AVL_Tree, SrcEditorIntf, SynEdit, SynEditMarks, EditorOptions,
  SynEditMarkupGutterMark;
  
type

  TSourceEditorBase = class;

  { TSourceEditorSharedValuesBase }

  TSourceEditorSharedValuesBase = class
  protected
    function GetSharedEditorsBase(Index: Integer): TSourceEditorBase; virtual abstract;
    function SharedEditorCount: Integer; virtual; abstract;
  end;

  { TSourceEditorBase }

  TSourceEditorBase = class(TSourceEditorInterface)
  protected
    function GetSharedValues: TSourceEditorSharedValuesBase; virtual; abstract;
  end;

  { *** }

  TSourceMarks = class;
  TSourceMark = class;

  TGetSourceMarkHintEvent =
    procedure(SenderMark: TSourceMark; var Hint: string) of object;
  TCreateSourceMarkPopupMenuEvent =
    procedure(SenderMark: TSourceMark;
              const AddMenuItem: TAddMenuItemProc) of object;
  TGetFilenameEvent = function(ASourceEditor: TObject): string of object;

  TSourceMarkHandler = (
    smhPositionChanged,
    smhBeforeFree,
    smhGetHint,
    smhCreatePopupMenu
    );

  TMarksAction = (maAdded, maRemoved, maChanged);
  TMarksActionEvent = procedure(AMark: TSourceMark; Action: TMarksAction) of object;


  { TSourceMark }
  
  TSourceMark = class(TSynEditMarkupMark)
  private
    FData: TObject;
    FSourceMarks: TSourceMarks;
    FSourceEditorID: TSourceEditorSharedValuesBase;
    FHandlers: array[TSourceMarkHandler] of TMethodList;
    function  GetSourceEditor: TSourceEditorBase;
    procedure SetSourceMarks(const AValue: TSourceMarks);
    procedure Changed;
  private
    FIsBreakPoint: boolean;
    FLineColorAttrib: TAdditionalHilightAttribute;
    FLineColorBackGround: TColor;
    FLineColorForeGround: TColor;
  protected
    procedure DoChange(AChanges: TSynEditMarkChangeReasons); override;
    procedure AddHandler(HandlerType: TSourceMarkHandler;
                         const Handler: TMethod);
    procedure DoPositionChanged; virtual;
    procedure DoLineUpdate; virtual;

    procedure SetData(const AValue: TObject); virtual;
    procedure SetIsBreakPoint(const AValue: boolean); virtual;
    procedure SetLineColorAttrib(const AValue: TAdditionalHilightAttribute); virtual;
    procedure SetLineColorBackGround(const AValue: TColor); virtual;
    procedure SetLineColorForeGround(const AValue: TColor); virtual;

    procedure SetColumn(const Value: Integer); override;
    procedure SetLine(const Value: Integer); override;
  public
    constructor Create(TheOwner: TSourceEditorBase; TheData: TObject);
    destructor Destroy; override;
    function Compare(OtherMark: TSourceMark): integer;
    function CompareEditorAndLine(ASrcEditID: TObject;
                                  ALine: integer): integer;
    function GetFilename: string;
    function GetHint: string; virtual;
    procedure CreatePopupMenuItems(const AddMenuItemProc: TAddMenuItemProc);
  public    // handlers
    procedure RemoveAllHandlersForObject(HandlerObject: TObject);
    procedure AddPositionChangedHandler(OnPositionChanged: TNotifyEvent);
    procedure RemovePositionChangedHandler(OnPositionChanged: TNotifyEvent);
    procedure AddBeforeFreeHandler(OnBeforeFree: TNotifyEvent);
    procedure RemoveBeforeFreeHandler(OnBeforeFree: TNotifyEvent);
    procedure AddGetHintHandler(OnGetHint: TGetSourceMarkHintEvent);
    procedure RemoveGetHintHandler(OnGetHint: TGetSourceMarkHintEvent);
    procedure AddCreatePopupMenuHandler(
                            OnCreatePopupMenu: TCreateSourceMarkPopupMenuEvent);
    procedure RemoveCreatePopupMenuHandler(
                            OnCreatePopupMenu: TCreateSourceMarkPopupMenuEvent);
  public
    // properties
    property Data: TObject read FData write SetData;
    property SourceMarks: TSourceMarks read FSourceMarks write SetSourceMarks;
    property SourceEditor: TSourceEditorBase read GetSourceEditor;
    property SourceEditorID: TSourceEditorSharedValuesBase read FSourceEditorID;
  public
    property LineColorAttrib: TAdditionalHilightAttribute read FLineColorAttrib
                                                       write SetLineColorAttrib;
    property LineColorForeGround: TColor read FLineColorForeGround
                                         write SetLineColorForeGround;
    property LineColorBackGround: TColor read FLineColorBackGround
                                         write SetLineColorBackGround;
  public
    property IsBreakPoint: boolean read FIsBreakPoint write SetIsBreakPoint;
  end;
  
  TSourceMarkClass = class of TSourceMark;
  PSourceMark = ^TSourceMark;
  
  
  { TSourceMarks }
  
  TSourceMarks = class(TComponent)
  private
    fActiveBreakPointImg: Integer;
    FCurrentLineBreakPointImg: Integer;
    FCurrentLineImg: Integer;
    FCurrentLineDisabledBreakPointImg: Integer;
    FSourceLineImg: Integer;
    FImgList: TImageList;
    fInactiveBreakPointImg: Integer;
    fInvalidBreakPointImg: Integer;
    fInvalidDisabledBreakPointImg: Integer;
    fItems: TList;// list of TSourceMark
    fMultiBreakPointImg: Integer;
    FOnGetFilename: TGetFilenameEvent;
    FOnAction: TMarksActionEvent;
    fSortedItems: TAVLTree;// tree of TSourceMark
    fUnknownBreakPointImg: Integer;
    fUnknownDisabledBreakPointImg: Integer;
    function GetItems(Index: integer): TSourceMark;
    procedure CreateImageList;
  protected
    function FindFirstMarkNode(ASrcEditID: TObject; ALine: integer): TAVLTreeNode;
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    function Count: integer;
    function Add(AMark: TSourceMark): integer;
    function Add(ASrcEdit: TSourceEditorBase; ALine: integer): TSourceMark;
    function AddCustomMark(TheOwner: TSourceEditorBase; Data: TObject;
                           MarkClass: TSourceMarkClass): TSourceMark;
    function AddImage(const ResName: string): integer;
    function GetFilename(AMark: TSourceMark): string;
    procedure Clear;
    procedure Delete(Index: integer);
    procedure Remove(AMark: TSourceMark);
    procedure DeleteAllForEditor(ASrcEdit: TSourceEditorBase);
    procedure DeleteAllForEditorID(ASrcEditID: TSourceEditorSharedValuesBase);
    function FindFirstMark(ASrcEdit: TSourceEditorBase;
                           ALine: integer): TSourceMark;
    function FindBreakPointMark(ASrcEdit: TSourceEditorBase;
                                ALine: integer): TSourceMark;
    procedure GetMarksForLine(ASrcEdit: TSourceEditorBase; ALine: integer;
                              var Marks: PSourceMark; var MarkCount: integer);
  public
    property ImgList: TImageList read FImgList write FImgList;
    property Items[Index: integer]: TSourceMark read GetItems; default;
    property OnGetFilename: TGetFilenameEvent read FOnGetFilename
                                              write FOnGetFilename;
    property OnAction: TMarksActionEvent read FOnAction write FOnAction;
  public
    // icon index
    property ActiveBreakPointImg: Integer read fActiveBreakPointImg;
    property InactiveBreakPointImg: Integer read fInactiveBreakPointImg;
    property InvalidBreakPointImg: Integer read fInvalidBreakPointImg;
    property InvalidDisabledBreakPointImg: Integer read fInvalidDisabledBreakPointImg;
    property MultiBreakPointImg: Integer read fMultiBreakPointImg;
    property UnknownBreakPointImg: Integer read fUnknownBreakPointImg;
    property UnknownDisabledBreakPointImg: Integer read fUnknownDisabledBreakPointImg;
    property CurrentLineImg: Integer read FCurrentLineImg;
    property CurrentLineBreakPointImg: Integer read FCurrentLineBreakPointImg;
    property CurrentLineDisabledBreakPointImg: Integer read FCurrentLineDisabledBreakPointImg;
    property SourceLineImg: Integer read FSourceLineImg;
  end;
  
var
  SourceEditorMarks: TSourceMarks;
  
implementation

type
  TEditorIDAndLine = record
    EditorID: TObject;
    Line: integer;
  end;
  PEditorAndLine = ^TEditorIDAndLine;

function CompareSourceMarks(Data1, Data2: Pointer): integer;
var
  Mark1: TSourceMark absolute Data1;
  Mark2: TSourceMark absolute Data2;
begin
  Result := Mark1.Compare(Mark2);
end;

function CompareEditorIDAndLineWithMark(Key, Data: Pointer): integer;
var
  EditorAndLine: PEditorAndLine absolute Key;
  AMark: TSourceMark absolute Data;
begin
  Result := -AMark.CompareEditorAndLine(EditorAndLine^.EditorID, EditorAndLine^.Line);
end;

{ TSourceMark }

procedure TSourceMark.SetSourceMarks(const AValue: TSourceMarks);
begin
  if FSourceMarks=AValue then exit;
  if FSourceMarks<>nil then
    FSourceMarks.Remove(Self);
  FSourceMarks := AValue;
  if AValue<>nil then
    AValue.Add(Self);
end;

function TSourceMark.GetSourceEditor: TSourceEditorBase;
begin
  if (FSourceEditorID <> nil) and (FSourceEditorID.SharedEditorCount > 0) then
    Result := FSourceEditorID.GetSharedEditorsBase(0)
  else
    Result := nil;
end;

procedure TSourceMark.Changed;
begin
  if Assigned(FSourceMarks) and Assigned(FSourceMarks.OnAction) then
    FSourceMarks.OnAction(Self, maChanged);
end;

procedure TSourceMark.DoChange(AChanges: TSynEditMarkChangeReasons);
begin
  inherited DoChange(AChanges);
  if AChanges * [smcrLine, smcrColumn] <> [] then
    DoPositionChanged;
  Changed;
end;

procedure TSourceMark.SetLineColorBackGround(const AValue: TColor);
begin
  if FLineColorBackGround=AValue then exit;
  FLineColorBackGround:=AValue;
  DoLineUpdate;
  Changed;
end;

procedure TSourceMark.SetLineColorForeGround(const AValue: TColor);
begin
  if FLineColorForeGround=AValue then exit;
  FLineColorForeGround:=AValue;
  DoLineUpdate;
  Changed;
end;

procedure TSourceMark.SetLineColorAttrib(
  const AValue: TAdditionalHilightAttribute);
begin
  if FLineColorAttrib=AValue then exit;
  FLineColorAttrib:=AValue;
  DoLineUpdate;
  Changed;
end;

procedure TSourceMark.SetIsBreakPoint(const AValue: boolean);
begin
  if FIsBreakPoint=AValue then exit;
  FIsBreakPoint:=AValue;
  DoLineUpdate;
  Changed;
end;

procedure TSourceMark.DoPositionChanged;
var
  i: Integer;
begin
  i:=FHandlers[smhPositionChanged].Count;
  while FHandlers[smhPositionChanged].NextDownIndex(i) do
    TNotifyEvent(FHandlers[smhPositionChanged][i])(Self);
end;

procedure TSourceMark.DoLineUpdate;
begin
  if (Line <= 0) or (not Visible) then Exit;
  DoChange([smcrChanged]);
end;

procedure TSourceMark.SetData(const AValue: TObject);
begin
  if FData=AValue then exit;
  FData:=AValue;
end;

procedure TSourceMark.AddHandler(HandlerType: TSourceMarkHandler;
  const Handler: TMethod);
begin
  if Handler.Code=nil then RaiseGDBException('TSourceMark.AddHandler');
  if FHandlers[HandlerType]=nil then
    FHandlers[HandlerType]:=TMethodList.Create;
  FHandlers[HandlerType].Add(Handler);
end;

procedure TSourceMark.SetColumn(const Value: Integer);
begin
  if Column=Value then exit;
  IncChangeLock;
  if FSourceMarks<>nil then
    FSourceMarks.fSortedItems.Remove(Self);
  inherited;
  if FSourceMarks<>nil then
    FSourceMarks.fSortedItems.Add(Self);
  DecChangeLock;
end;

procedure TSourceMark.SetLine(const Value: Integer);
begin
  if Line=Value then exit;
  IncChangeLock;
  if FSourceMarks<>nil then
    FSourceMarks.fSortedItems.Remove(Self);
  inherited;
  if FSourceMarks<>nil then
    FSourceMarks.fSortedItems.Add(Self);
  DecChangeLock;
end;

constructor TSourceMark.Create(TheOwner: TSourceEditorBase; TheData: TObject);
begin
  FSourceEditorID := TheOwner.GetSharedValues;
  inherited Create(TSynEdit(TheOwner.EditorControl));
  FData:=TheData;
  FLineColorAttrib:=ahaNone;
  FLineColorBackGround:=clNone;
  FLineColorForeGround:=clNone;
  TSynEdit(TheOwner.EditorControl).Marks.Add(Self);
end;

destructor TSourceMark.Destroy;
var
  HandlerType: TSourceMarkHandler;
  i: Integer;
begin
  // notify all who wants to know
  i:=FHandlers[smhBeforeFree].Count;
  while FHandlers[smhBeforeFree].NextDownIndex(i) do
    TNotifyEvent(FHandlers[smhBeforeFree][i])(Self);
  // remove from source marks
  SourceMarks := nil;
  FSourceEditorID := nil;

  // free handler lists
  for HandlerType:=Low(TSourceMarkHandler) to high(TSourceMarkHandler) do
    FreeThenNil(FHandlers[HandlerType]);
    
  inherited Destroy;
end;

function TSourceMark.Compare(OtherMark: TSourceMark): integer;
begin
  Result:=PtrInt(SourceEditorID)-PtrInt(OtherMark.SourceEditorID);
  if Result<>0 then exit;
  Result:=Line-OtherMark.Line;
  if Result<>0 then exit;
  Result:=Column-OtherMark.Column;
  if Result <> 0 then exit;
  Result:=Priority-OtherMark.Priority;
  if Result <> 0 then exit;
  Result := PtrInt(Self) - PtrInt(OtherMark);
end;

function TSourceMark.CompareEditorAndLine(ASrcEditID: TObject;
  ALine: integer): integer;
begin
  Result := PtrInt(SourceEditorID) - PtrInt(ASrcEditID);
  if Result <> 0 then Exit;
  Result := Line - ALine;
end;

function TSourceMark.GetFilename: string;
begin
  Result:='';
  if FSourceMarks=nil then exit;
  Result:=FSourceMarks.GetFilename(Self);
end;

function TSourceMark.GetHint: string;
var
  i: Integer;
begin
  Result:='';
  i:=FHandlers[smhGetHint].Count;
  while FHandlers[smhGetHint].NextDownIndex(i) do
    TGetSourceMarkHintEvent(FHandlers[smhGetHint][i])(Self,Result);
end;

procedure TSourceMark.CreatePopupMenuItems(
  const AddMenuItemProc: TAddMenuItemProc);
var
  i: Integer;
begin
  i:=FHandlers[smhCreatePopupMenu].Count;
  while FHandlers[smhCreatePopupMenu].NextDownIndex(i) do
    TCreateSourceMarkPopupMenuEvent(FHandlers[smhCreatePopupMenu][i])
      (Self,AddMenuItemProc);
end;

procedure TSourceMark.RemoveAllHandlersForObject(HandlerObject: TObject);
var
  HandlerType: TSourceMarkHandler;
begin
  for HandlerType:=Low(TSourceMarkHandler) to High(TSourceMarkHandler) do
    if FHandlers[HandlerType]<>nil then
      FHandlers[HandlerType].RemoveAllMethodsOfObject(HandlerObject);
end;

procedure TSourceMark.AddPositionChangedHandler(OnPositionChanged: TNotifyEvent
  );
begin
  AddHandler(smhPositionChanged,TMethod(OnPositionChanged));
end;

procedure TSourceMark.RemovePositionChangedHandler(
  OnPositionChanged: TNotifyEvent);
begin
  FHandlers[smhPositionChanged].Remove(TMethod(OnPositionChanged));
end;

procedure TSourceMark.AddBeforeFreeHandler(OnBeforeFree: TNotifyEvent);
begin
  AddHandler(smhBeforeFree,TMethod(OnBeforeFree));
end;

procedure TSourceMark.RemoveBeforeFreeHandler(OnBeforeFree: TNotifyEvent);
begin
  FHandlers[smhBeforeFree].Remove(TMethod(OnBeforeFree));
end;

procedure TSourceMark.AddGetHintHandler(OnGetHint: TGetSourceMarkHintEvent);
begin
  AddHandler(smhGetHint,TMethod(OnGetHint));
end;

procedure TSourceMark.RemoveGetHintHandler(OnGetHint: TGetSourceMarkHintEvent);
begin
  FHandlers[smhGetHint].Remove(TMethod(OnGetHint));
end;

procedure TSourceMark.AddCreatePopupMenuHandler(
  OnCreatePopupMenu: TCreateSourceMarkPopupMenuEvent);
begin
  AddHandler(smhCreatePopupMenu,TMethod(OnCreatePopupMenu));
end;

procedure TSourceMark.RemoveCreatePopupMenuHandler(
  OnCreatePopupMenu: TCreateSourceMarkPopupMenuEvent);
begin
  FHandlers[smhCreatePopupMenu].Remove(TMethod(OnCreatePopupMenu));
end;

{ TSourceMarks }

function TSourceMarks.GetItems(Index: integer): TSourceMark;
begin
  Result:=TSourceMark(FItems[Index]);
end;

procedure TSourceMarks.CreateImageList;
var
  i: Integer;
begin
  // create default mark icons
  ImgList:=TImageList.Create(Self);
  ImgList.Width:=11;
  ImgList.Height:=11;

  // synedit expects the first 10 icons for the bookmarks
  for i := 0 to 9 do
    AddImage('bookmark'+IntToStr(i));

  // load active breakpoint image
  fActiveBreakPointImg:=AddImage('ActiveBreakPoint');
  // load disabled breakpoint image
  fInactiveBreakPointImg:=AddImage('InactiveBreakPoint');
  // load invalid breakpoint image
  fInvalidBreakPointImg:=AddImage('InvalidBreakPoint');
  // load invalid disabled breakpoint image
  fInvalidDisabledBreakPointImg := AddImage('InvalidDisabledBreakPoint');
  // load unknown breakpoint image
  fUnknownBreakPointImg:=AddImage('UnknownBreakPoint');
  // load unknown disabled breakpoint image
  fUnknownDisabledBreakPointImg := AddImage('UnknownDisabledBreakPoint');
  // load multi mixed breakpoint image
  fMultiBreakPointImg:=AddImage('MultiBreakPoint');
  // load current line image
  FCurrentLineImg:=AddImage('debugger_current_line');
  // load current line + breakpoint image
  FCurrentLineBreakPointImg:=AddImage('debugger_current_line_breakpoint');
  // load current line + disabled breakpoint image
  FCurrentLineDisabledBreakPointImg := AddImage('debugger_current_line_disabled_breakpoint');
  // load source line
  FSourceLineImg:=AddImage('debugger_source_line');
end;

function TSourceMarks.FindFirstMarkNode(ASrcEditID: TObject; ALine: integer
  ): TAVLTreeNode;
var
  LeftNode: TAVLTreeNode;
  EditorIDAndLine: TEditorIDAndLine;
begin
  EditorIDAndLine.EditorID := ASrcEditID;
  EditorIDAndLine.Line := ALine;
  Result := fSortedItems.FindKey(@EditorIDAndLine, @CompareEditorIDAndLineWithMark);
  while Result <> nil do
  begin
    LeftNode := fSortedItems.FindPrecessor(Result);
    if (LeftNode = nil) or
       (CompareEditorIDAndLineWithMark(@EditorIDAndLine, LeftNode.Data) <> 0) then break;
    Result := LeftNode;
  end;
end;

constructor TSourceMarks.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  fItems:=TList.Create;
  fSortedItems:=TAVLTree.Create(@CompareSourceMarks);
  CreateImageList;
end;

destructor TSourceMarks.Destroy;
begin
  Clear;
  FreeThenNil(FItems);
  FreeThenNil(fSortedItems);
  inherited Destroy;
end;

function TSourceMarks.Count: integer;
begin
  Result:=fItems.Count;
end;

procedure TSourceMarks.Clear;
begin
  while fItems.Count>0 do Delete(fItems.Count-1);
end;

function TSourceMarks.Add(AMark: TSourceMark): integer;
begin
  if AMark=nil then exit(-1);
  AMark.FSourceMarks:=Self;
  Result:=fItems.Add(AMark);
  fSortedItems.Add(AMark);
  if Assigned(FOnAction) then
    FOnAction(AMark, maAdded);
end;

function TSourceMarks.Add(ASrcEdit: TSourceEditorBase; ALine: integer): TSourceMark;
begin
  Result:=TSourceMark.Create(ASrcEdit, nil);
  Result.Line := ALine;
  Add(Result);
end;

function TSourceMarks.AddCustomMark(TheOwner: TSourceEditorBase; Data: TObject;
  MarkClass: TSourceMarkClass): TSourceMark;
begin
  if MarkClass=nil then MarkClass:=TSourceMark;
  Result:=MarkClass.Create(TheOwner,Data);
  Add(Result);
end;

procedure TSourceMarks.Delete(Index: integer);
var
  AMark: TSourceMark;
begin
  AMark:=Items[Index];
  AMark.fSourceMarks:=nil;
  fItems.Delete(Index);
  fSortedItems.Remove(AMark);
  if Assigned(FOnAction) then
    FOnAction(AMark, maRemoved);
  AMark.Free;
end;

procedure TSourceMarks.Remove(AMark: TSourceMark);
var
  i: Integer;
begin
  if (AMark=nil) or (AMark.SourceMarks<>Self) then exit;
  i:=fItems.IndexOf(AMark);
  if i<0 then exit;
  fItems.Delete(i);
  fSortedItems.Remove(AMark);
  AMark.fSourceMarks:=nil;
  if Assigned(FOnAction) then
    FOnAction(AMark, maRemoved);
end;

procedure TSourceMarks.DeleteAllForEditor(ASrcEdit: TSourceEditorBase);
begin
  DeleteAllForEditorID(ASrcEdit.GetSharedValues);
end;

procedure TSourceMarks.DeleteAllForEditorID(ASrcEditID: TSourceEditorSharedValuesBase);
var
  i: Integer;
begin
  if ASrcEditID = nil then
    exit;
  i:=fItems.Count-1;
  while i>=0 do begin
    if Items[i].SourceEditorID = ASrcEditID then
      Delete(i);
    dec(i);
  end;
end;

function TSourceMarks.FindFirstMark(ASrcEdit: TSourceEditorBase; ALine: integer): TSourceMark;
var
  AVLNode: TAVLTreeNode;
  SrcEditorID: TSourceEditorSharedValuesBase;
begin
  Result := nil;
  SrcEditorID := ASrcEdit.GetSharedValues;
  if SrcEditorID = nil then
    exit;
  AVLNode:=FindFirstMarkNode(SrcEditorID, ALine);
  if AVLNode<>nil then
    Result:=TSourceMark(AVLNode.Data);
end;

function TSourceMarks.FindBreakPointMark(ASrcEdit: TSourceEditorBase;
  ALine: integer): TSourceMark;
var
  AVLNode: TAVLTreeNode;
  EditorIDAndLine: TEditorIDAndLine;
  CurMark: TSourceMark;
  SrcEditorID: TSourceEditorSharedValuesBase;
begin
  Result := nil;
  SrcEditorID := ASrcEdit.GetSharedValues;
  if SrcEditorID = nil then
    exit;

  EditorIDAndLine.EditorID := SrcEditorID;
  EditorIDAndLine.Line := ALine;
  AVLNode := FindFirstMarkNode(EditorIDAndLine.EditorID, ALine);
  while (AVLNode <> nil) do
  begin
    CurMark := TSourceMark(AVLNode.Data);
    if CompareEditorIDAndLineWithMark(@EditorIDAndLine, CurMark) <> 0 then break;
    if CurMark.IsBreakPoint then
    begin
      Result := CurMark;
      Exit;
    end;
    AVLNode := fSortedItems.FindSuccessor(AVLNode);
  end;
end;

procedure TSourceMarks.GetMarksForLine(ASrcEdit: TSourceEditorBase;
  ALine: integer; var Marks: PSourceMark; var MarkCount: integer);
var
  i, Capacity: integer;
  AVLNode: TAVLTreeNode;
  EditorIDAndLine: TEditorIDAndLine;
  CurMark: TSourceMark;
  HasChange: Boolean;
  SrcEditorID: TSourceEditorSharedValuesBase;
begin
  SrcEditorID := ASrcEdit.GetSharedValues;
  if SrcEditorID = nil then
    exit;

  Capacity := 0;
  MarkCount := 0;
  Marks := nil;
  EditorIDAndLine.EditorID := SrcEditorID;
  EditorIDAndLine.Line := ALine;
  AVLNode := FindFirstMarkNode(EditorIDAndLine.EditorID, ALine);
  while (AVLNode <> nil) do
  begin
    CurMark := TSourceMark(AVLNode.Data);
    if CompareEditorIDAndLineWithMark(@EditorIDAndLine, CurMark) <> 0 then break;
    if Capacity <= MarkCount then
    begin
      inc(Capacity, Capacity + 4);
      ReAllocMem(Marks, Capacity * SizeOf(Pointer));
    end;
    Marks[MarkCount] := CurMark;
    inc(MarkCount);
    AVLNode := fSortedItems.FindSuccessor(AVLNode);
  end;
  HasChange := MarkCount > 1;
  // easy popup sort by priority
  while HasChange do
  begin
    HasChange := False;
    for i := 0 to MarkCount - 2 do
      if Marks[i].Priority < Marks[i+1].Priority then
      begin
        CurMark := Marks[i];
        Marks[i] := Marks[i+1];
        Marks[i+1] := CurMark;
        HasChange := True;
      end;
  end;
end;

function TSourceMarks.AddImage(const ResName: string): integer;
begin
  Result := ImgList.AddLazarusResource(Resname);
end;

function TSourceMarks.GetFilename(AMark: TSourceMark): string;
begin
  Result:='';
  if (AMark=nil) or (not Assigned(OnGetFilename)) then exit;
  if AMark.SourceEditor=nil then exit;
  Result:=OnGetFilename(AMark.SourceEditor);
end;

initialization
  SourceEditorMarks:=nil;

end.