mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 22:19:12 +02:00
Diff tool: rename variables.
git-svn-id: trunk@46028 -
This commit is contained in:
parent
30cd69fe8f
commit
3aa148f840
@ -46,9 +46,9 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TDiffFile }
|
{ TAvailableDiffFile }
|
||||||
|
|
||||||
TDiffFile = class
|
TAvailableDiffFile = class
|
||||||
public
|
public
|
||||||
Name: string;
|
Name: string;
|
||||||
Editor: TSourceEditor;
|
Editor: TSourceEditor;
|
||||||
@ -57,19 +57,18 @@ type
|
|||||||
NewSelectionAvailable: boolean);
|
NewSelectionAvailable: boolean);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TAvailableDiffFiles }
|
||||||
|
|
||||||
{ TDiffFiles }
|
TAvailableDiffFiles = class(TList)
|
||||||
|
|
||||||
TDiffFiles = class(TList)
|
|
||||||
private
|
private
|
||||||
function GetItems(Index: integer): TDiffFile;
|
function GetItems(Index: integer): TAvailableDiffFile;
|
||||||
procedure SetItems(Index: integer; const AValue: TDiffFile);
|
procedure SetItems(Index: integer; const AValue: TAvailableDiffFile);
|
||||||
public
|
public
|
||||||
procedure Clear; override;
|
procedure Clear; override;
|
||||||
function Add(DiffFile: TDiffFile): integer;
|
function Add(DiffFile: TAvailableDiffFile): integer;
|
||||||
function IndexOfName(const Name: string): integer;
|
function IndexOfName(const Name: string): integer;
|
||||||
public
|
public
|
||||||
property Items[Index: integer]: TDiffFile read GetItems write SetItems; default;
|
property Items[Index: integer]: TAvailableDiffFile read GetItems write SetItems; default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -111,14 +110,14 @@ type
|
|||||||
fUpdating: Boolean;
|
fUpdating: Boolean;
|
||||||
fIdleConnected: boolean;
|
fIdleConnected: boolean;
|
||||||
fCancelled: boolean;
|
fCancelled: boolean;
|
||||||
|
fAvailableFiles: TAvailableDiffFiles;
|
||||||
|
fSelectedFile1: TAvailableDiffFile;
|
||||||
|
fSelectedFile2: TAvailableDiffFile;
|
||||||
procedure SetupComponents;
|
procedure SetupComponents;
|
||||||
procedure UpdateDiff;
|
procedure UpdateDiff;
|
||||||
procedure SetIdleConnected(const AValue: boolean);
|
procedure SetIdleConnected(const AValue: boolean);
|
||||||
procedure OnIdle(Sender: TObject; var Done: Boolean);
|
procedure OnIdle(Sender: TObject; var Done: Boolean);
|
||||||
public
|
public
|
||||||
Files: TDiffFiles;
|
|
||||||
Text1: TDiffFile;
|
|
||||||
Text2: TDiffFile;
|
|
||||||
constructor Create(TheOwner: TComponent); override;
|
constructor Create(TheOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure Init;
|
procedure Init;
|
||||||
@ -150,19 +149,19 @@ implementation
|
|||||||
function ShowDiffDialog(Text1Index: integer; out Diff: string): TModalResult;
|
function ShowDiffDialog(Text1Index: integer; out Diff: string): TModalResult;
|
||||||
var
|
var
|
||||||
DiffDlg: TDiffDlg;
|
DiffDlg: TDiffDlg;
|
||||||
Files: TDiffFiles;
|
Files: TAvailableDiffFiles;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
SrcEdit: TSourceEditor;
|
SrcEdit: TSourceEditor;
|
||||||
begin
|
begin
|
||||||
DiffDlg := TDiffDlg.Create(nil);
|
DiffDlg := TDiffDlg.Create(nil);
|
||||||
Files := TDiffFiles.Create;
|
Files := TAvailableDiffFiles.Create;
|
||||||
try
|
try
|
||||||
// Get available files
|
// Get available files
|
||||||
for i:=0 to SourceEditorManager.SourceEditorCount - 1 do begin
|
for i:=0 to SourceEditorManager.SourceEditorCount - 1 do begin
|
||||||
SrcEdit := SourceEditorManager.SourceEditors[i]; // FindSourceEditorWithPageIndex(i);
|
SrcEdit := SourceEditorManager.SourceEditors[i]; // FindSourceEditorWithPageIndex(i);
|
||||||
Files.Add(TDiffFile.Create(SrcEdit.PageName, SrcEdit, SrcEdit.SelectionAvailable));
|
Files.Add(TAvailableDiffFile.Create(SrcEdit.PageName, SrcEdit, SrcEdit.SelectionAvailable));
|
||||||
end;
|
end;
|
||||||
DiffDlg.Files := Files;
|
DiffDlg.fAvailableFiles := Files;
|
||||||
DiffDlg.SetText1Index(Text1Index);
|
DiffDlg.SetText1Index(Text1Index);
|
||||||
DiffDlg.Init;
|
DiffDlg.Init;
|
||||||
Result := DiffDlg.ShowModal;
|
Result := DiffDlg.ShowModal;
|
||||||
@ -190,7 +189,7 @@ begin
|
|||||||
//only add new files
|
//only add new files
|
||||||
if Text1ComboBox.Items.IndexOf(dlgOpen.FileName) = -1 then
|
if Text1ComboBox.Items.IndexOf(dlgOpen.FileName) = -1 then
|
||||||
begin
|
begin
|
||||||
Files.Add(TDiffFile.Create(dlgOpen.FileName,nil,False));
|
fAvailableFiles.Add(TAvailableDiffFile.Create(dlgOpen.FileName,nil,False));
|
||||||
Text1ComboBox.Items.Add(dlgOpen.FileName);
|
Text1ComboBox.Items.Add(dlgOpen.FileName);
|
||||||
Text2ComboBox.Items.Add(dlgOpen.FileName);
|
Text2ComboBox.Items.Add(dlgOpen.FileName);
|
||||||
end;
|
end;
|
||||||
@ -304,33 +303,33 @@ begin
|
|||||||
if fUpdating then Exit;
|
if fUpdating then Exit;
|
||||||
fUpdating := True;
|
fUpdating := True;
|
||||||
DiffSynEdit.Lines.Text := '';
|
DiffSynEdit.Lines.Text := '';
|
||||||
if (Text1 <> nil) and (Text2 <> nil) then begin
|
if (fSelectedFile1 <> nil) and (fSelectedFile2 <> nil) then begin
|
||||||
if Text1.Editor = nil then
|
if fSelectedFile1.Editor = nil then
|
||||||
begin
|
begin
|
||||||
dat := TStringListUTF8.Create;
|
dat := TStringListUTF8.Create;
|
||||||
dat.LoadFromFile(Text1.Name);
|
dat.LoadFromFile(fSelectedFile1.Name);
|
||||||
Text1Src := dat.Text;
|
Text1Src := dat.Text;
|
||||||
dat.Free;
|
dat.Free;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
if (Text1.SelectionAvailable and Text1OnlySelectionCheckBox.Checked) then
|
if (fSelectedFile1.SelectionAvailable and Text1OnlySelectionCheckBox.Checked) then
|
||||||
Text1Src := Text1.Editor.EditorComponent.SelText
|
Text1Src := fSelectedFile1.Editor.EditorComponent.SelText
|
||||||
else
|
else
|
||||||
Text1Src := Text1.Editor.EditorComponent.Lines.Text;
|
Text1Src := fSelectedFile1.Editor.EditorComponent.Lines.Text;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Text2.Editor = nil then
|
if fSelectedFile2.Editor = nil then
|
||||||
begin
|
begin
|
||||||
dat := TStringListUTF8.Create;
|
dat := TStringListUTF8.Create;
|
||||||
dat.LoadFromFile(Text2.Name);
|
dat.LoadFromFile(fSelectedFile2.Name);
|
||||||
Text2Src := dat.Text;
|
Text2Src := dat.Text;
|
||||||
dat.Free;
|
dat.Free;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
if (Text2.SelectionAvailable and Text2OnlySelectionCheckBox.Checked) then
|
if (fSelectedFile2.SelectionAvailable and Text2OnlySelectionCheckBox.Checked) then
|
||||||
Text2Src := Text2.Editor.EditorComponent.SelText
|
Text2Src := fSelectedFile2.Editor.EditorComponent.SelText
|
||||||
else
|
else
|
||||||
Text2Src := Text2.Editor.EditorComponent.Lines.Text;
|
Text2Src := fSelectedFile2.Editor.EditorComponent.Lines.Text;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Text1GroupBox.Enabled := False;
|
Text1GroupBox.Enabled := False;
|
||||||
@ -379,9 +378,9 @@ begin
|
|||||||
// get recent Text 2
|
// get recent Text 2
|
||||||
LastText2Name:=InputHistories.DiffText2;
|
LastText2Name:=InputHistories.DiffText2;
|
||||||
if LastText2Name<>'' then
|
if LastText2Name<>'' then
|
||||||
i:=Files.IndexOfName(LastText2Name);
|
i:=fAvailableFiles.IndexOfName(LastText2Name);
|
||||||
if i<0 then i:=0;
|
if i<0 then i:=0;
|
||||||
if i=Files.IndexOf(Text2) then inc(i);
|
if i=fAvailableFiles.IndexOf(fSelectedFile2) then inc(i);
|
||||||
SetText2Index(i);
|
SetText2Index(i);
|
||||||
|
|
||||||
// set recent options
|
// set recent options
|
||||||
@ -398,57 +397,57 @@ begin
|
|||||||
// Text 1
|
// Text 1
|
||||||
Text1Combobox.Items.BeginUpdate;
|
Text1Combobox.Items.BeginUpdate;
|
||||||
Text1Combobox.Items.Clear;
|
Text1Combobox.Items.Clear;
|
||||||
for i:=0 to Files.Count-1 do
|
for i:=0 to fAvailableFiles.Count-1 do
|
||||||
Text1Combobox.Items.Add(Files[i].Name);
|
Text1Combobox.Items.Add(fAvailableFiles[i].Name);
|
||||||
Text1Combobox.Items.EndUpdate;
|
Text1Combobox.Items.EndUpdate;
|
||||||
|
|
||||||
// Text 2
|
// Text 2
|
||||||
Text2Combobox.Items.BeginUpdate;
|
Text2Combobox.Items.BeginUpdate;
|
||||||
Text2Combobox.Items.Clear;
|
Text2Combobox.Items.Clear;
|
||||||
for i:=0 to Files.Count-1 do
|
for i:=0 to fAvailableFiles.Count-1 do
|
||||||
Text2Combobox.Items.Add(Files[i].Name);
|
Text2Combobox.Items.Add(fAvailableFiles[i].Name);
|
||||||
Text2Combobox.Items.EndUpdate;
|
Text2Combobox.Items.EndUpdate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDiffDlg.SetText1Index(NewIndex: integer);
|
procedure TDiffDlg.SetText1Index(NewIndex: integer);
|
||||||
var
|
var
|
||||||
OldText1: TDiffFile;
|
OldText1: TAvailableDiffFile;
|
||||||
begin
|
begin
|
||||||
OldText1:=Text1;
|
OldText1:=fSelectedFile1;
|
||||||
if (NewIndex>=0) and (NewIndex<Files.Count) then begin
|
if (NewIndex>=0) and (NewIndex<fAvailableFiles.Count) then begin
|
||||||
Text1:=Files[NewIndex];
|
fSelectedFile1:=fAvailableFiles[NewIndex];
|
||||||
Text1Combobox.Text:=Text1.Name;
|
Text1Combobox.Text:=fSelectedFile1.Name;
|
||||||
Text1OnlySelectionCheckBox.Enabled:=Text1.SelectionAvailable;
|
Text1OnlySelectionCheckBox.Enabled:=fSelectedFile1.SelectionAvailable;
|
||||||
end else begin
|
end else begin
|
||||||
Text1:=nil;
|
fSelectedFile1:=nil;
|
||||||
Text1Combobox.Text:='';
|
Text1Combobox.Text:='';
|
||||||
Text1OnlySelectionCheckBox.Enabled:=false;
|
Text1OnlySelectionCheckBox.Enabled:=false;
|
||||||
end;
|
end;
|
||||||
if Text1<>OldText1 then UpdateDiff;
|
if fSelectedFile1<>OldText1 then UpdateDiff;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDiffDlg.SetText2Index(NewIndex: integer);
|
procedure TDiffDlg.SetText2Index(NewIndex: integer);
|
||||||
var
|
var
|
||||||
OldText2: TDiffFile;
|
OldText2: TAvailableDiffFile;
|
||||||
begin
|
begin
|
||||||
OldText2:=Text2;
|
OldText2:=fSelectedFile2;
|
||||||
if (NewIndex>=0) and (NewIndex<Files.Count) then begin
|
if (NewIndex>=0) and (NewIndex<fAvailableFiles.Count) then begin
|
||||||
Text2:=Files[NewIndex];
|
fSelectedFile2:=fAvailableFiles[NewIndex];
|
||||||
Text2Combobox.Text:=Text2.Name;
|
Text2Combobox.Text:=fSelectedFile2.Name;
|
||||||
Text2OnlySelectionCheckBox.Enabled:=Text2.SelectionAvailable;
|
Text2OnlySelectionCheckBox.Enabled:=fSelectedFile2.SelectionAvailable;
|
||||||
end else begin
|
end else begin
|
||||||
Text2:=nil;
|
fSelectedFile2:=nil;
|
||||||
Text2Combobox.Text:='';
|
Text2Combobox.Text:='';
|
||||||
Text2OnlySelectionCheckBox.Enabled:=false;
|
Text2OnlySelectionCheckBox.Enabled:=false;
|
||||||
end;
|
end;
|
||||||
if Text2<>OldText2 then UpdateDiff;
|
if fSelectedFile2<>OldText2 then UpdateDiff;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDiffDlg.SaveSettings;
|
procedure TDiffDlg.SaveSettings;
|
||||||
begin
|
begin
|
||||||
InputHistories.DiffFlags:=GetDiffOptions;
|
InputHistories.DiffFlags:=GetDiffOptions;
|
||||||
if Text2<>nil then begin
|
if fSelectedFile2<>nil then begin
|
||||||
InputHistories.DiffText2:=Text2.Name;
|
InputHistories.DiffText2:=fSelectedFile2.Name;
|
||||||
InputHistories.DiffText2OnlySelection:=Text2OnlySelectionCheckBox.Checked;
|
InputHistories.DiffText2OnlySelection:=Text2OnlySelectionCheckBox.Checked;
|
||||||
end else begin
|
end else begin
|
||||||
InputHistories.DiffText2:='';
|
InputHistories.DiffText2:='';
|
||||||
@ -487,9 +486,9 @@ begin
|
|||||||
Include(Result,tdfIgnoreTrailingSpaces);
|
Include(Result,tdfIgnoreTrailingSpaces);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TDiffFile }
|
{ TAvailableDiffFile }
|
||||||
|
|
||||||
constructor TDiffFile.Create(const NewName: string; NewEditor: TSourceEditor;
|
constructor TAvailableDiffFile.Create(const NewName: string; NewEditor: TSourceEditor;
|
||||||
NewSelectionAvailable: boolean);
|
NewSelectionAvailable: boolean);
|
||||||
begin
|
begin
|
||||||
Name:=NewName;
|
Name:=NewName;
|
||||||
@ -497,19 +496,19 @@ begin
|
|||||||
SelectionAvailable:=NewSelectionAvailable;
|
SelectionAvailable:=NewSelectionAvailable;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TDiffFiles }
|
{ TAvailableDiffFiles }
|
||||||
|
|
||||||
function TDiffFiles.GetItems(Index: integer): TDiffFile;
|
function TAvailableDiffFiles.GetItems(Index: integer): TAvailableDiffFile;
|
||||||
begin
|
begin
|
||||||
Result:=TDiffFile(inherited Items[Index]);
|
Result:=TAvailableDiffFile(inherited Items[Index]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDiffFiles.SetItems(Index: integer; const AValue: TDiffFile);
|
procedure TAvailableDiffFiles.SetItems(Index: integer; const AValue: TAvailableDiffFile);
|
||||||
begin
|
begin
|
||||||
inherited Items[Index]:=AValue;
|
inherited Items[Index]:=AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDiffFiles.Clear;
|
procedure TAvailableDiffFiles.Clear;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
@ -518,12 +517,12 @@ begin
|
|||||||
inherited Clear;
|
inherited Clear;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDiffFiles.Add(DiffFile: TDiffFile): integer;
|
function TAvailableDiffFiles.Add(DiffFile: TAvailableDiffFile): integer;
|
||||||
begin
|
begin
|
||||||
Result:=inherited Add(DiffFile);
|
Result:=inherited Add(DiffFile);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDiffFiles.IndexOfName(const Name: string): integer;
|
function TAvailableDiffFiles.IndexOfName(const Name: string): integer;
|
||||||
begin
|
begin
|
||||||
Result:=Count-1;
|
Result:=Count-1;
|
||||||
while (Result>=0) and (Items[Result].Name<>Name) do dec(Result);
|
while (Result>=0) and (Items[Result].Name<>Name) do dec(Result);
|
||||||
|
Loading…
Reference in New Issue
Block a user