-
Notifications
You must be signed in to change notification settings - Fork 13
/
ProjectVersionCompare.pas
183 lines (161 loc) · 5.55 KB
/
ProjectVersionCompare.pas
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
/// File Versioning comparison form
// - this unit is part of SynProject, under GPL 3.0 license; version 1.7
unit ProjectVersionCompare;
(*
This file is part of SynProject.
Synopse SynProject. Copyright (C) 2008-2023 Arnaud Bouchez
Synopse Informatique - https://synopse.info
SynProject 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 3 of the License, or (at
your option) any later version.
SynProject 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 Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
along with SynProject. If not, see <http://www.gnu.org/licenses/>.
*)
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Menus, ComCtrls, ExtCtrls, SynMemoEx, ProjectCommons,
ProjectVersioning,
ProjectEditor, ProjectFrameViewer, ProjectFormViewTwo;
type
TProjectVersionCompareForm = class(TForm)
PanelLeft: TPanel;
PanelRight: TPanel;
ListFilesCommit: TListView;
procedure FormResize(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ListFilesCommitSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
private
procedure SynchronizeOnScroll(Sender: TObject);
public
Backup,
Versions: TVersions;
Editor: TFrameEditor;
EditorText: string;
Title,
FileName: string;
FileNameIndex: integer; // in Backup.FileNames[]
View1,
View2: TFrameViewer;
procedure OnEditorBtnHistoryClick(Sender: TObject);
procedure Init(aVersions: TVersions; aEditor: TFrameEditor; const aFileName: string);
procedure CompareUsing(const aTitle: string; Back: TVersions);
end;
var
ProjectVersionCompareForm: TProjectVersionCompareForm;
implementation
uses
ProjectVersionMain;
{$R *.dfm}
{ TProjectVersionCompareForm }
procedure TProjectVersionCompareForm.CompareUsing(const aTitle: string; Back: TVersions);
var i: integer;
begin
Backup := Back;
FileNameIndex := Back.FileNames.FindIndex(FileName);
if FileNameIndex<0 then exit;
Title := StringReplaceAll(aTitle,'&','');
Caption := ' '+Title;
WindowState := wsMaximized;
View1.Free;
View1 := TFrameViewer.Create(self,Back,nil,false);
View1.FileName := FileName;
View1.Parent := PanelLeft;
View1.Align := alClient;
View1.Name := 'View1';
View1.Diff := true;
View1.MemoEx.OnScroll := SynchronizeOnScroll;
// right = current Editor content
View2.Free;
View2 := TFrameViewer.Create(self,Back,nil,false);
View2.FileName := FileName;
View2.Parent := PanelRight;
View2.Align := alClient;
View2.Name := 'View2';
View2.Diff := true;
View2.MemoEx.OnScroll := SynchronizeOnScroll;
MainForm.PagesLeft.CommitInit(ListFilesCommit);
for i := Back.Count-1 downto 0 do
with Back.Values[i] do
if FileName=FileNameIndex then
MainForm.PagesLeft.CommitAdd(Back,Commit,true,ListFilesCommit);
MainForm.PagesLeft.CommitEnd(ListFilesCommit);
ListFilesCommit.OnResize := nil; // FormResize;
ShowModal;
end;
procedure TProjectVersionCompareForm.OnEditorBtnHistoryClick(Sender: TObject);
// just a TMenuItem with Tag = BakcupDir #
var Menu: TMenuItem absolute Sender;
b, path, FN: string;
Back: TVersions;
begin
if not Sender.InheritsFrom(TMenuItem) then exit;
if Menu.Tag=-1 then // Tag=-1 -> commits = Version
Back := Versions else begin
b := Versions.Params['BackupDir'+IntToStr(Menu.Tag)];
// BackupDir0=Local backup,012345,D:\-=- Backup -=-\Synopse\
FN := Versions.GetBackupFileName(b,path);
if not FileExists(FN) then exit;
Back := TVersions.Create(FN);
end;
try
EditorText := Editor.Memo.Lines.Text;
CompareUsing('Compare with '+Menu.Caption, Back);
finally
if Back<>Versions then
Back.Free;
end;
end;
procedure TProjectVersionCompareForm.FormResize(Sender: TObject);
var W: integer;
begin
W := (ClientWidth-ListFilesCommit.Width)div 2;
PanelLeft.Width := W;
PanelRight.Width := W;
end;
procedure TProjectVersionCompareForm.SynchronizeOnScroll(Sender: TObject);
var M: TMemoEx absolute Sender;
begin
if not (Sender.InheritsFrom(TMemoEx)) then exit;
if M=View1.MemoEx then
View2.MemoEx.SetLeftTop(0,M.TopRow) else
if M=View2.MemoEx then
View1.MemoEx.SetLeftTop(0,M.TopRow);
end;
procedure TProjectVersionCompareForm.Init(aVersions: TVersions;
aEditor: TFrameEditor; const aFileName: string);
begin
Versions := aVersions;
Editor := aEditor;
FileName := aFileName;
end;
procedure TProjectVersionCompareForm.FormShow(Sender: TObject);
begin
if ListFilesCommit.Items.Count>0 then
ListFilesCommit.ItemIndex := 0;
View2.MemoEx.SetFocus; // must be after having been shown
end;
procedure TProjectVersionCompareForm.ListFilesCommitSelectItem(
Sender: TObject; Item: TListItem; Selected: Boolean);
var List: TListView absolute Sender;
Diff: TDiffCalc;
begin
if csDestroying in ComponentState then exit;
if not Sender.InheritsFrom(TListView) or not Assigned(Backup) then exit;
if List.SelCount>1 then begin // maximum 1 selected item
Item.Selected := false;
exit;
end;
Diff.Execute(Backup.GetVersionData(FileNameIndex,integer(Item.Data)), EditorText,
View1.MemoEx, View2.MemoEx, false);
Caption := format(' %s - %s : %d add, %d mod, %d del',[
Title,FileName,Diff.linesAdd,Diff.linesMod,Diff.linesDel]);
View2.GotoNextModif;
end;
end.