SourceEditor/Marks: Improved breakpoint line adjustment, on edit

git-svn-id: trunk@24532 -
This commit is contained in:
martin 2010-04-09 02:38:14 +00:00
parent 9a6460190f
commit f5773ee782
2 changed files with 60 additions and 33 deletions

View File

@ -149,6 +149,7 @@ type
TSourceEditorSharedValues = class TSourceEditorSharedValues = class
private private
FExecutionMark: TSourceMark;
FSharedEditorList: TFPList; // list of TSourceEditor sharing one TSynEdit FSharedEditorList: TFPList; // list of TSourceEditor sharing one TSynEdit
FExecutionLine: integer; FExecutionLine: integer;
FModified: boolean; FModified: boolean;
@ -166,7 +167,9 @@ type
property OtherSharedEditors[Caller: TSourceEditor; Index: Integer]: TSourceEditor property OtherSharedEditors[Caller: TSourceEditor; Index: Integer]: TSourceEditor
read GetOtherSharedEditors; read GetOtherSharedEditors;
property Modified: Boolean read FModified write SetModified; property Modified: Boolean read FModified write SetModified;
procedure CreateExecutionMark;
property ExecutionLine: Integer read FExecutionLine write FExecutionLine; property ExecutionLine: Integer read FExecutionLine write FExecutionLine;
property ExecutionMark: TSourceMark read FExecutionMark write FExecutionMark;
public public
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
@ -197,7 +200,6 @@ type
FSyntaxHighlighterType: TLazSyntaxHighlighter; FSyntaxHighlighterType: TLazSyntaxHighlighter;
FErrorLine: integer; FErrorLine: integer;
FErrorColumn: integer; FErrorColumn: integer;
FExecutionMark: TSourceMark;
FLineInfoNotification: TIDELineInfoNotification; FLineInfoNotification: TIDELineInfoNotification;
FOnEditorChange: TNotifyEvent; FOnEditorChange: TNotifyEvent;
@ -1977,16 +1979,27 @@ begin
Result := FSharedEditorList.Count - 1; Result := FSharedEditorList.Count - 1;
end; end;
procedure TSourceEditorSharedValues.CreateExecutionMark;
begin
FExecutionMark := TSourceMark.Create(SharedEditors[0], nil);
SourceEditorMarks.Add(FExecutionMark);
FExecutionMark.LineColorAttrib := ahaExecutionPoint;
FExecutionMark.Priority := 1;
end;
constructor TSourceEditorSharedValues.Create; constructor TSourceEditorSharedValues.Create;
begin begin
FSharedEditorList := TFPList.Create; FSharedEditorList := TFPList.Create;
BookmarkEventLock := 0; BookmarkEventLock := 0;
FExecutionLine:=-1; FExecutionLine:=-1;
FExecutionMark := nil;
end; end;
destructor TSourceEditorSharedValues.Destroy; destructor TSourceEditorSharedValues.Destroy;
begin begin
FreeAndNil(FSharedEditorList); FreeAndNil(FSharedEditorList);
// no need to care about ExecutionMark, it was removed in EditorClose
// via: SourceEditorMarks.DeleteAllForEditor(Self);
inherited Destroy; inherited Destroy;
end; end;
@ -2015,7 +2028,6 @@ Begin
FSyntaxHighlighterType:=lshNone; FSyntaxHighlighterType:=lshNone;
FErrorLine:=-1; FErrorLine:=-1;
FErrorColumn:=-1; FErrorColumn:=-1;
FExecutionMark := nil;
FHasExecutionMarks := False; FHasExecutionMarks := False;
FMarksRequested := False; FMarksRequested := False;
FSyncroLockCount := 0; FSyncroLockCount := 0;
@ -3337,39 +3349,38 @@ end;
procedure TSourceEditor.UpdateExecutionSourceMark; procedure TSourceEditor.UpdateExecutionSourceMark;
var var
BreakPoint: TIDEBreakPoint; BreakPoint: TIDEBreakPoint;
ExecutionMark: TSourceMark;
begin begin
if (FExecutionMark = nil) then ExecutionMark := FSharedValues.ExecutionMark;
begin if ExecutionMark = nil then exit;
FExecutionMark := TSourceMark.Create(Self, nil);
SourceEditorMarks.Add(FExecutionMark);
FExecutionMark.LineColorAttrib := ahaExecutionPoint;
FExecutionMark.Priority := 1;
end;
if FExecutionMark.Visible then if ExecutionMark.Visible then
FEditor.InvalidateLine(FExecutionMark.Line);
FExecutionMark.Visible := ExecutionLine <> -1;
if FExecutionMark.Visible then
begin begin
FExecutionMark.Line := ExecutionLine;
FEditor.InvalidateLine(FExecutionMark.Line);
if SourceEditorMarks.FindBreakPointMark(Self, ExecutionLine) <> nil then if SourceEditorMarks.FindBreakPointMark(Self, ExecutionLine) <> nil then
begin begin
BreakPoint := DebugBoss.BreakPoints.Find(Self.FileName, ExecutionLine); BreakPoint := DebugBoss.BreakPoints.Find(Self.FileName, ExecutionLine);
if (BreakPoint <> nil) and (not BreakPoint.Enabled) then if (BreakPoint <> nil) and (not BreakPoint.Enabled) then
FExecutionMark.ImageIndex := SourceEditorMarks.CurrentLineDisabledBreakPointImg ExecutionMark.ImageIndex := SourceEditorMarks.CurrentLineDisabledBreakPointImg
else else
FExecutionMark.ImageIndex := SourceEditorMarks.CurrentLineBreakPointImg; ExecutionMark.ImageIndex := SourceEditorMarks.CurrentLineBreakPointImg;
end end
else else
FExecutionMark.ImageIndex := SourceEditorMarks.CurrentLineImg; ExecutionMark.ImageIndex := SourceEditorMarks.CurrentLineImg;
end; end;
end; end;
procedure TSourceEditor.SetExecutionLine(NewLine: integer); procedure TSourceEditor.SetExecutionLine(NewLine: integer);
begin begin
if ExecutionLine=NewLine then exit; if ExecutionLine=NewLine then exit;
if (FSharedValues.ExecutionMark = nil) then begin
if NewLine = -1 then
exit;
FSharedValues.CreateExecutionMark;
end;
FSharedValues.ExecutionLine := NewLine; FSharedValues.ExecutionLine := NewLine;
FSharedValues.ExecutionMark.Visible := NewLine <> -1;
if NewLine <> -1 then
FSharedValues.ExecutionMark.Line := NewLine;
UpdateExecutionSourceMark; UpdateExecutionSourceMark;
end; end;
@ -8346,8 +8357,9 @@ begin
AMark.AddSourceEditor(Editor.FSharedValues.SharedEditors[i]); AMark.AddSourceEditor(Editor.FSharedValues.SharedEditors[i]);
end; end;
if AMark.IsBreakPoint and (Editor.FExecutionMark <> nil) and if ( AMark.IsBreakPoint and (Editor.FSharedValues.ExecutionMark <> nil) and
(AMark.Line = Editor.ExecutionLine) (AMark.Line = Editor.ExecutionLine)
) or (AMark = Editor.FSharedValues.ExecutionMark)
then then
Editor.UpdateExecutionSourceMark; Editor.UpdateExecutionSourceMark;
end; end;

View File

@ -125,6 +125,7 @@ type
FSourceMarks: TSourceMarks; FSourceMarks: TSourceMarks;
FSourceEditorID: TObject; FSourceEditorID: TObject;
FSynMarks: TSourceSynMarkList; FSynMarks: TSourceSynMarkList;
FSynMarkLock: Integer;
FData: TObject; FData: TObject;
FHandlers: array[TSourceMarkHandler] of TMethodList; FHandlers: array[TSourceMarkHandler] of TMethodList;
FLine: integer; FLine: integer;
@ -146,7 +147,7 @@ type
procedure AddHandler(HandlerType: TSourceMarkHandler; procedure AddHandler(HandlerType: TSourceMarkHandler;
const Handler: TMethod); const Handler: TMethod);
procedure DoPositionChanged; virtual; procedure DoPositionChanged; virtual;
procedure DoLineUpdate; virtual; procedure DoLineUpdate(Force: Boolean = False); virtual;
function EditorUpdateRequired: Boolean; virtual; // called to check if we need to update the editor if a property is changed function EditorUpdateRequired: Boolean; virtual; // called to check if we need to update the editor if a property is changed
procedure SetColumn(const Value: Integer); //override; procedure SetColumn(const Value: Integer); //override;
procedure SetData(const AValue: TObject); virtual; procedure SetData(const AValue: TObject); virtual;
@ -461,7 +462,6 @@ var
i: Integer; i: Integer;
begin begin
for i := 0 to Count - 1 do for i := 0 to Count - 1 do
if Visible then
Items[i].GetEdit.InvalidateLine(ALine); Items[i].GetEdit.InvalidateLine(ALine);
end; end;
@ -542,6 +542,7 @@ procedure TSourceMark.SetPriority(const AValue: integer);
begin begin
if FPriority = AValue then exit; if FPriority = AValue then exit;
FPriority := AValue; FPriority := AValue;
if FSynMarkLock = 0 then
FSynMarks.Priority := AValue; FSynMarks.Priority := AValue;
end; end;
@ -570,11 +571,14 @@ end;
procedure TSourceMark.SynMarkChanged(Sender: TObject); procedure TSourceMark.SynMarkChanged(Sender: TObject);
begin begin
// Only read Value from Mark => Do not write back to Mark(s)
inc(FSynMarkLock);
Line := TSourceSynMark(Sender).Line; Line := TSourceSynMark(Sender).Line;
Column := TSourceSynMark(Sender).Column; Column := TSourceSynMark(Sender).Column;
Priority := TSourceSynMark(Sender).Priority; Priority := TSourceSynMark(Sender).Priority;
ImageIndex := TSourceSynMark(Sender).ImageIndex; ImageIndex := TSourceSynMark(Sender).ImageIndex;
Visible := TSourceSynMark(Sender).Visible; Visible := TSourceSynMark(Sender).Visible;
dec(FSynMarkLock);
end; end;
procedure TSourceMark.SetLineColorBackGround(const AValue: TColor); procedure TSourceMark.SetLineColorBackGround(const AValue: TColor);
@ -582,6 +586,7 @@ begin
if FLineColorBackGround=AValue then exit; if FLineColorBackGround=AValue then exit;
FLineColorBackGround:=AValue; FLineColorBackGround:=AValue;
DoLineUpdate; DoLineUpdate;
Changed;
end; end;
procedure TSourceMark.SetLineColorForeGround(const AValue: TColor); procedure TSourceMark.SetLineColorForeGround(const AValue: TColor);
@ -589,6 +594,7 @@ begin
if FLineColorForeGround=AValue then exit; if FLineColorForeGround=AValue then exit;
FLineColorForeGround:=AValue; FLineColorForeGround:=AValue;
DoLineUpdate; DoLineUpdate;
Changed;
end; end;
procedure TSourceMark.SetLineColorAttrib( procedure TSourceMark.SetLineColorAttrib(
@ -597,6 +603,7 @@ begin
if FLineColorAttrib=AValue then exit; if FLineColorAttrib=AValue then exit;
FLineColorAttrib:=AValue; FLineColorAttrib:=AValue;
DoLineUpdate; DoLineUpdate;
Changed;
end; end;
procedure TSourceMark.SetIsBreakPoint(const AValue: boolean); procedure TSourceMark.SetIsBreakPoint(const AValue: boolean);
@ -604,14 +611,17 @@ begin
if FIsBreakPoint=AValue then exit; if FIsBreakPoint=AValue then exit;
FIsBreakPoint:=AValue; FIsBreakPoint:=AValue;
DoLineUpdate; DoLineUpdate;
Changed;
end; end;
procedure TSourceMark.SetVisible(const AValue: boolean); procedure TSourceMark.SetVisible(const AValue: boolean);
begin begin
if Visible = AValue then Exit; if Visible = AValue then Exit;
FVisible := AValue; FVisible := AValue;
if FSynMarkLock = 0 then
FSynMarks.Visible := AValue; FSynMarks.Visible := AValue;
if EditorUpdateRequired then DoLineUpdate; if EditorUpdateRequired then DoLineUpdate(True);
Changed;
end; end;
procedure TSourceMark.DoPositionChanged; procedure TSourceMark.DoPositionChanged;
@ -623,11 +633,11 @@ begin
TNotifyEvent(FHandlers[smhPositionChanged][i])(Self); TNotifyEvent(FHandlers[smhPositionChanged][i])(Self);
end; end;
procedure TSourceMark.DoLineUpdate; procedure TSourceMark.DoLineUpdate(Force: Boolean = False);
begin begin
if Line <= 0 then Exit; if Line <= 0 then Exit;
if Visible or Force then
FSynMarks.InvalidateLine(Line); FSynMarks.InvalidateLine(Line);
Changed;
end; end;
procedure TSourceMark.SetData(const AValue: TObject); procedure TSourceMark.SetData(const AValue: TObject);
@ -657,6 +667,7 @@ begin
if Column=Value then exit; if Column=Value then exit;
if FSourceMarks<>nil then FSourceMarks.fSortedItems.Remove(Self); if FSourceMarks<>nil then FSourceMarks.fSortedItems.Remove(Self);
FColumn := Value; FColumn := Value;
if FSynMarkLock = 0 then
FSynMarks.Column := Value; FSynMarks.Column := Value;
if FSourceMarks<>nil then FSourceMarks.fSortedItems.Add(Self); if FSourceMarks<>nil then FSourceMarks.fSortedItems.Add(Self);
DoPositionChanged; DoPositionChanged;
@ -666,6 +677,7 @@ procedure TSourceMark.SetImage(const Value: Integer);
begin begin
if ImageIndex=Value then exit; if ImageIndex=Value then exit;
FImage := Value; FImage := Value;
if FSynMarkLock = 0 then
FSynMarks.ImageIndex := Value; FSynMarks.ImageIndex := Value;
Changed; Changed;
end; end;
@ -676,14 +688,17 @@ begin
if EditorUpdateRequired then DoLineUpdate; if EditorUpdateRequired then DoLineUpdate;
if FSourceMarks<>nil then FSourceMarks.fSortedItems.Remove(Self); if FSourceMarks<>nil then FSourceMarks.fSortedItems.Remove(Self);
FLine := Value; FLine := Value;
if FSynMarkLock = 0 then
FSynMarks.Line := Value; FSynMarks.Line := Value;
if FSourceMarks<>nil then FSourceMarks.fSortedItems.Add(Self); if FSourceMarks<>nil then FSourceMarks.fSortedItems.Add(Self);
DoPositionChanged; DoPositionChanged;
if EditorUpdateRequired then DoLineUpdate; if EditorUpdateRequired then DoLineUpdate;
Changed;
end; end;
constructor TSourceMark.Create(TheOwner: TSourceEditorInterface; TheData: TObject); constructor TSourceMark.Create(TheOwner: TSourceEditorInterface; TheData: TObject);
begin begin
FSynMarkLock := 0;
FSynMarks := TSourceSynMarkList.Create; FSynMarks := TSourceSynMarkList.Create;
FSynMarks.OnChange := @SynMarkChanged; FSynMarks.OnChange := @SynMarkChanged;
FSynMarks.Add(TSourceSynMark.Create(Self, TheOwner)); FSynMarks.Add(TSourceSynMark.Create(Self, TheOwner));