mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 21:38:00 +02:00
IDE: Remove LCL dependency from unit DiffPatch.
git-svn-id: trunk@57121 -
This commit is contained in:
parent
1cefe1d894
commit
78bc310072
@ -142,6 +142,7 @@ type
|
||||
procedure UpdateDiff;
|
||||
procedure SetIdleConnected(const AValue: boolean);
|
||||
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
|
||||
procedure UpdateProgress(aPosition: Integer);
|
||||
public
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -379,6 +380,12 @@ begin
|
||||
IdleConnected:=True;
|
||||
end;
|
||||
|
||||
procedure TDiffDlg.UpdateProgress(aPosition: Integer);
|
||||
begin
|
||||
ProgressBar1.Position := aPosition;
|
||||
Application.ProcessMessages;
|
||||
end;
|
||||
|
||||
procedure TDiffDlg.SetIdleConnected(const AValue: boolean);
|
||||
begin
|
||||
if fIdleConnected=AValue then exit;
|
||||
@ -407,9 +414,11 @@ begin
|
||||
OpenInEditorButton.Enabled := False;
|
||||
//CancelScanningButton.Enabled := True;
|
||||
|
||||
DiffOutput:=TDiffOutput.Create(Text1Src, Text2Src, GetDiffOptions, ProgressBar1);
|
||||
DiffOutput := TDiffOutput.Create(Text1Src, Text2Src, GetDiffOptions);
|
||||
try
|
||||
DiffSynEdit.Lines.Text:=DiffOutput.CreateTextDiff;
|
||||
ProgressBar1.Max := DiffOutput.GetProgressMax;
|
||||
DiffOutput.OnProgressPos := @UpdateProgress;
|
||||
DiffSynEdit.Lines.Text := DiffOutput.CreateTextDiff;
|
||||
finally
|
||||
DiffOutput.Free;
|
||||
end;
|
||||
|
@ -37,7 +37,7 @@ unit DiffPatch;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LCLProc, Forms, ComCtrls;
|
||||
Classes, SysUtils, LazLogger;
|
||||
|
||||
type
|
||||
TTextDiffFlag = (
|
||||
@ -97,14 +97,16 @@ type
|
||||
procedure GetNextLineExtends(var LineExtends: TLineExtends);
|
||||
end;
|
||||
|
||||
TProgressEvent = procedure(aPosition: Integer) of object;
|
||||
|
||||
{ TDiffOutput }
|
||||
|
||||
TDiffOutput = class
|
||||
private
|
||||
fText1, fText2: string;
|
||||
fOutputType: TTextDiffOutputType;
|
||||
fOnProgressPos: TProgressEvent;
|
||||
fFlags: TTextDiffFlags;
|
||||
fProgressBar: TProgressBar;
|
||||
fDiffStream: TStream;
|
||||
fPart1, fPart2: TDiffPart;
|
||||
procedure FindNextEqualLine(const Start1, Start2: TLineExtends;
|
||||
@ -120,12 +122,13 @@ type
|
||||
procedure AddDiff(const Start1, End1, Start2, End2: TLineExtends);
|
||||
procedure UpdateProgressBar(const Line: TLineExtends);
|
||||
public
|
||||
constructor Create(const aText1, aText2: string;
|
||||
aFlags: TTextDiffFlags; aProgressBar: TProgressBar);
|
||||
constructor Create(const aText1, aText2: string; aFlags: TTextDiffFlags);
|
||||
destructor Destroy; override;
|
||||
function GetProgressMax: Integer;
|
||||
function CreateTextDiff: string;
|
||||
public
|
||||
property OutputType: TTextDiffOutputType read fOutputType write fOutputType;
|
||||
property OnProgressPos: TProgressEvent read fOnProgressPos write fOnProgressPos;
|
||||
end;
|
||||
|
||||
|
||||
@ -171,12 +174,11 @@ end;
|
||||
function GotoNextLine(var LineExtends: TLineExtends): boolean;
|
||||
begin
|
||||
with LineExtends do begin
|
||||
if LineStart<NextLineStart then begin
|
||||
Result:=LineStart<NextLineStart;
|
||||
if Result then begin
|
||||
inc(LineNumber);
|
||||
LineStart:=NextLineStart;
|
||||
Result:=true;
|
||||
end else
|
||||
Result:=false;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -670,7 +672,7 @@ begin
|
||||
until false;
|
||||
except
|
||||
on E: Exception do begin
|
||||
DebugLn('CreateTextDiff ',E.Message);
|
||||
DebugLogger.DebugLn('CreateTextDiff ',E.Message);
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
@ -711,10 +713,8 @@ end;
|
||||
|
||||
procedure TDiffOutput.UpdateProgressBar(const Line: TLineExtends);
|
||||
begin
|
||||
if Assigned(fProgressBar) then begin
|
||||
fProgressBar.Position := Line.LineStart;
|
||||
Application.ProcessMessages;
|
||||
end;
|
||||
if Assigned(OnProgressPos) then
|
||||
OnProgressPos(Line.LineStart);
|
||||
end;
|
||||
|
||||
procedure TDiffOutput.FinishOldContextBlock;
|
||||
@ -858,21 +858,16 @@ begin
|
||||
fPart2.Write2(Start2,End2,Part1HasChangedLines,'+');
|
||||
end;
|
||||
|
||||
constructor TDiffOutput.Create(const aText1, aText2: string;
|
||||
aFlags: TTextDiffFlags; aProgressBar: TProgressBar);
|
||||
var
|
||||
i: Integer;
|
||||
function TDiffOutput.GetProgressMax: Integer;
|
||||
begin
|
||||
Result := Length(fText1); // + Length(fText2);
|
||||
end;
|
||||
|
||||
constructor TDiffOutput.Create(const aText1, aText2: string; aFlags: TTextDiffFlags);
|
||||
begin
|
||||
fText1:=aText1;
|
||||
fText2:=aText2;
|
||||
fFlags:=aFlags;
|
||||
fProgressBar:=aProgressBar;
|
||||
if Assigned(fProgressBar) then begin
|
||||
i := Length(aText1); // + Length(aText2);
|
||||
fProgressBar.Max := i;
|
||||
fProgressBar.Step := i;
|
||||
fProgressBar.Position := 0;
|
||||
end;
|
||||
fOutputType:=tdoContext; // Default OutputType, can be changed later
|
||||
fDiffStream:=TMemoryStream.Create;
|
||||
fPart1:=TDiffPart.Create(Self, fText1);
|
||||
@ -881,8 +876,8 @@ end;
|
||||
|
||||
destructor TDiffOutput.Destroy;
|
||||
begin
|
||||
if Assigned(fProgressBar) then
|
||||
fProgressBar.Position := 0;
|
||||
if Assigned(OnProgressPos) then
|
||||
OnProgressPos(0);
|
||||
fPart2.Free;
|
||||
fPart1.Free;
|
||||
fDiffStream.Free;
|
||||
|
@ -338,7 +338,7 @@ begin
|
||||
fs.Read(Result^.TxtOnDisk[1],length(Result^.TxtOnDisk));
|
||||
fs.Free;
|
||||
|
||||
DiffOutput:=TDiffOutput.Create(Source,Result^.TxtOnDisk, [], nil);
|
||||
DiffOutput:=TDiffOutput.Create(Source,Result^.TxtOnDisk, []);
|
||||
try
|
||||
Result^.Diff+=DiffOutput.CreateTextDiff;
|
||||
finally
|
||||
|
Loading…
Reference in New Issue
Block a user