1 | unit UCore;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, XMLConf, LazFileUtils, ActnList, Controls, UVCS, UProject,
|
---|
9 | ULastOpenedList, Forms, Dialogs, Menus, Contnrs, UBackend;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TCore }
|
---|
14 |
|
---|
15 | TCore = class(TDataModule)
|
---|
16 | AAbout: TAction;
|
---|
17 | ACommandUpdate: TAction;
|
---|
18 | ACommandCleanup: TAction;
|
---|
19 | ACommandCommit: TAction;
|
---|
20 | ACommandStatus: TAction;
|
---|
21 | AProjectGroupSaveAs: TAction;
|
---|
22 | AProjectGroupSave: TAction;
|
---|
23 | AProjectGroupClose: TAction;
|
---|
24 | AProjectGroupOpen: TAction;
|
---|
25 | AProjectGroupNew: TAction;
|
---|
26 | AViewTest: TAction;
|
---|
27 | AProjectCheckout: TAction;
|
---|
28 | AProjectClose: TAction;
|
---|
29 | ActionList1: TActionList;
|
---|
30 | AHelp: TAction;
|
---|
31 | AProjectOpen: TAction;
|
---|
32 | AQuit: TAction;
|
---|
33 | ASettings: TAction;
|
---|
34 | AViewFavorites: TAction;
|
---|
35 | ImageList1: TImageList;
|
---|
36 | LastOpenedListProject: TLastOpenedList;
|
---|
37 | LastOpenedListNewDir: TLastOpenedList;
|
---|
38 | LastOpenedListProjectGroup: TLastOpenedList;
|
---|
39 | LastOpenedListRepoURL: TLastOpenedList;
|
---|
40 | OpenDialog1: TOpenDialog;
|
---|
41 | SaveDialog1: TSaveDialog;
|
---|
42 | XMLConfig1: TXMLConfig;
|
---|
43 | procedure ACommandCheckoutExecute(Sender: TObject);
|
---|
44 | procedure ACommandCleanupExecute(Sender: TObject);
|
---|
45 | procedure ACommandCommitExecute(Sender: TObject);
|
---|
46 | procedure ACommandUpdateExecute(Sender: TObject);
|
---|
47 | procedure AProjectCheckoutExecute(Sender: TObject);
|
---|
48 | procedure AProjectCloseExecute(Sender: TObject);
|
---|
49 | procedure AProjectGroupCloseExecute(Sender: TObject);
|
---|
50 | procedure AProjectGroupNewExecute(Sender: TObject);
|
---|
51 | procedure AProjectGroupOpenExecute(Sender: TObject);
|
---|
52 | procedure AProjectGroupSaveAsExecute(Sender: TObject);
|
---|
53 | procedure AProjectGroupSaveExecute(Sender: TObject);
|
---|
54 | procedure AProjectOpenExecute(Sender: TObject);
|
---|
55 | procedure AQuitExecute(Sender: TObject);
|
---|
56 | procedure ASettingsExecute(Sender: TObject);
|
---|
57 | procedure AViewTestExecute(Sender: TObject);
|
---|
58 | procedure DataModuleCreate(Sender: TObject);
|
---|
59 | procedure DataModuleDestroy(Sender: TObject);
|
---|
60 | procedure LastOpenedListProjectChange(Sender: TObject);
|
---|
61 | procedure LastOpenedListProjectGroupChange(Sender: TObject);
|
---|
62 | private
|
---|
63 | procedure UpdateInterface;
|
---|
64 | procedure RegisterBackends;
|
---|
65 | procedure RegisterBackend(Backend: TBackend);
|
---|
66 | function DetectBackend(Directory: string): TBackend;
|
---|
67 | public
|
---|
68 | Backends: TObjectList; // TList<TBackend>
|
---|
69 | Project: TProject;
|
---|
70 | ProjectGroup: TProjectGroup;
|
---|
71 | UserName: string;
|
---|
72 | Email: string;
|
---|
73 | procedure LoadConfig;
|
---|
74 | procedure SaveConfig;
|
---|
75 | procedure Init;
|
---|
76 | procedure Done;
|
---|
77 | procedure ProjectOpen(Directory: string);
|
---|
78 | procedure ProjectGroupOpen(FileName: string);
|
---|
79 | end;
|
---|
80 |
|
---|
81 | var
|
---|
82 | Core: TCore;
|
---|
83 |
|
---|
84 | implementation
|
---|
85 |
|
---|
86 | {$R *.lfm}
|
---|
87 |
|
---|
88 | uses
|
---|
89 | UFormMain, UFormBrowse, UFormSettings, UFormCommit, UFormCheckout,
|
---|
90 | USubversion, UBazaar, UCVS, UGit, UFormTest, UFormProjectGroup;
|
---|
91 |
|
---|
92 | { TCore }
|
---|
93 |
|
---|
94 | procedure TCore.AQuitExecute(Sender: TObject);
|
---|
95 | begin
|
---|
96 | Application.Terminate;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | procedure TCore.ASettingsExecute(Sender: TObject);
|
---|
100 | begin
|
---|
101 | FormSettings.Load(XMLConfig1);
|
---|
102 | if FormSettings.ShowModal = mrOk then begin
|
---|
103 | FormSettings.Save(XMLConfig1);
|
---|
104 | end;
|
---|
105 | end;
|
---|
106 |
|
---|
107 | procedure TCore.AViewTestExecute(Sender: TObject);
|
---|
108 | begin
|
---|
109 | FormTest.Show;
|
---|
110 | end;
|
---|
111 |
|
---|
112 | procedure TCore.DataModuleCreate(Sender: TObject);
|
---|
113 | begin
|
---|
114 | Backends := TObjectList.Create;
|
---|
115 | Project := nil;
|
---|
116 | end;
|
---|
117 |
|
---|
118 | procedure TCore.DataModuleDestroy(Sender: TObject);
|
---|
119 | begin
|
---|
120 | FreeAndNil(Project);
|
---|
121 | FreeAndNil(Backends);
|
---|
122 | end;
|
---|
123 |
|
---|
124 | procedure TCore.LastOpenedListProjectChange(Sender: TObject);
|
---|
125 | begin
|
---|
126 | LastOpenedListProject.LoadToMenuItem(FormMain.MenuItemOpenRecent, FormMain.OpenRecentExecute);
|
---|
127 | end;
|
---|
128 |
|
---|
129 | procedure TCore.LastOpenedListProjectGroupChange(Sender: TObject);
|
---|
130 | begin
|
---|
131 | LastOpenedListProjectGroup.LoadToMenuItem(FormMain.MenuItemRecentProjectGroup, FormMain.ProjectGroupOpenRecentExecute);
|
---|
132 | end;
|
---|
133 |
|
---|
134 | procedure TCore.UpdateInterface;
|
---|
135 | begin
|
---|
136 | AProjectClose.Enabled := Assigned(Project);
|
---|
137 | AProjectGroupClose.Enabled := Assigned(ProjectGroup);
|
---|
138 | AProjectGroupSave.Enabled := Assigned(ProjectGroup);
|
---|
139 | AProjectGroupSaveAs.Enabled := Assigned(ProjectGroup);
|
---|
140 | FormMain.UpdateInterface;
|
---|
141 | end;
|
---|
142 |
|
---|
143 | procedure TCore.RegisterBackends;
|
---|
144 | begin
|
---|
145 | RegisterBackend(TBackendSubversion.Create);
|
---|
146 | RegisterBackend(TBackendBazaar.Create);
|
---|
147 | RegisterBackend(TBackendCVS.Create);
|
---|
148 | RegisterBackend(TBackendGit.Create);
|
---|
149 | end;
|
---|
150 |
|
---|
151 | procedure TCore.RegisterBackend(Backend: TBackend);
|
---|
152 | begin
|
---|
153 | Backends.Add(Backend);
|
---|
154 | end;
|
---|
155 |
|
---|
156 | function TCore.DetectBackend(Directory: string): TBackend;
|
---|
157 | var
|
---|
158 | I: Integer;
|
---|
159 | begin
|
---|
160 | I := 0;
|
---|
161 | while (I < Backends.Count) and (not TBackend(Backends[I]).IsWorkingCopy(Directory)) do Inc(I);
|
---|
162 | if I < Backends.Count then Result := TBackend(Backends[I])
|
---|
163 | else Result := nil;
|
---|
164 | end;
|
---|
165 |
|
---|
166 | procedure TCore.LoadConfig;
|
---|
167 | begin
|
---|
168 | LastOpenedListProject.LoadFromXMLConfig(XMLConfig1, 'LastOpenedProjects');
|
---|
169 | LastOpenedListRepoURL.LoadFromXMLConfig(XMLConfig1, 'LastOpenedRepoURL');
|
---|
170 | LastOpenedListNewDir.LoadFromXMLConfig(XMLConfig1, 'LastOpenedNewDir');
|
---|
171 | LastOpenedListProjectGroup.LoadFromXMLConfig(XMLConfig1, 'LastOpenedListProjectGroup');
|
---|
172 | UserName := XMLConfig1.GetValue('UserName', '');
|
---|
173 | Email := XMLConfig1.GetValue('Email', '');
|
---|
174 | end;
|
---|
175 |
|
---|
176 | procedure TCore.SaveConfig;
|
---|
177 | begin
|
---|
178 | LastOpenedListProject.SaveToXMLConfig(XMLConfig1, 'LastOpenedProjects');
|
---|
179 | LastOpenedListRepoURL.SaveToXMLConfig(XMLConfig1, 'LastOpenedRepoURL');
|
---|
180 | LastOpenedListNewDir.SaveToXMLConfig(XMLConfig1, 'LastOpenedNewDir');
|
---|
181 | LastOpenedListProjectGroup.SaveToXMLConfig(XMLConfig1, 'LastOpenedListProjectGroup');
|
---|
182 | XMLConfig1.SetValue('UserName', UserName);
|
---|
183 | XMLConfig1.SetValue('Email', Email);
|
---|
184 | XmlConfig1.Flush;
|
---|
185 | end;
|
---|
186 |
|
---|
187 | procedure TCore.Init;
|
---|
188 | begin
|
---|
189 | RegisterBackends;
|
---|
190 | XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml';
|
---|
191 | ForceDirectoriesUTF8(ExtractFileDir(XMLConfig1.Filename));
|
---|
192 | LoadConfig;
|
---|
193 | if (LastOpenedListProject.Items.Count > 0) and DirectoryExistsUTF8(LastOpenedListProject.Items[0]) then
|
---|
194 | ProjectOpen(LastOpenedListProject.Items[0]);
|
---|
195 | end;
|
---|
196 |
|
---|
197 | procedure TCore.Done;
|
---|
198 | begin
|
---|
199 | SaveConfig;
|
---|
200 | end;
|
---|
201 |
|
---|
202 | procedure TCore.ProjectOpen(Directory: string);
|
---|
203 | begin
|
---|
204 | AProjectClose.Execute;
|
---|
205 | Project := TProject.Create;
|
---|
206 | Project.Backend := DetectBackend(Directory);
|
---|
207 | Project.WorkingCopy.UserName := Core.UserName;
|
---|
208 | Project.WorkingCopy.Email := Core.Email;
|
---|
209 | if Assigned(Project.Backend) then begin
|
---|
210 | Project.Directory := Directory;
|
---|
211 | UpdateInterface;
|
---|
212 | FormBrowse.Directory := Project.Directory;
|
---|
213 | FormBrowse.ReloadList;
|
---|
214 | LastOpenedListProject.AddItem(Project.Directory);
|
---|
215 | end else ShowMessage('Directory ''' + Directory + ''' not recognized as working copy of any of supported VCS systems');
|
---|
216 | end;
|
---|
217 |
|
---|
218 | procedure TCore.ProjectGroupOpen(FileName: string);
|
---|
219 | begin
|
---|
220 | AProjectGroupClose.Execute;
|
---|
221 | ProjectGroup := TProjectGroup.Create;
|
---|
222 | ProjectGroup.FileName := FileName;
|
---|
223 | UpdateInterface;
|
---|
224 | FormProjectGroup.ReloadTree;
|
---|
225 | LastOpenedListProjectGroup.AddItem(FileName);
|
---|
226 | end;
|
---|
227 |
|
---|
228 | procedure TCore.AProjectOpenExecute(Sender: TObject);
|
---|
229 | var
|
---|
230 | Dir: string;
|
---|
231 | OldDir: string;
|
---|
232 | begin
|
---|
233 | if Assigned(Project) then OldDir := Project.Directory
|
---|
234 | else OldDir := '';
|
---|
235 | if SelectDirectory('Open project', OldDir, Dir) then begin
|
---|
236 | ProjectOpen(Dir);
|
---|
237 | end;
|
---|
238 | end;
|
---|
239 |
|
---|
240 | procedure TCore.AProjectCloseExecute(Sender: TObject);
|
---|
241 | begin
|
---|
242 | FreeAndNil(Project);
|
---|
243 | FormBrowse.Directory := '';
|
---|
244 | FormBrowse.ReloadList;
|
---|
245 | UpdateInterface;
|
---|
246 | end;
|
---|
247 |
|
---|
248 | procedure TCore.AProjectGroupCloseExecute(Sender: TObject);
|
---|
249 | begin
|
---|
250 | FreeAndNil(ProjectGroup);
|
---|
251 | UpdateInterface;
|
---|
252 | FormProjectGroup.ReloadTree;
|
---|
253 | end;
|
---|
254 |
|
---|
255 | procedure TCore.AProjectGroupNewExecute(Sender: TObject);
|
---|
256 | begin
|
---|
257 | AProjectClose.Execute;
|
---|
258 | ProjectGroup := TProjectGroup.Create;
|
---|
259 | ProjectGroup.FileName := 'New project group.vcgrp';
|
---|
260 | UpdateInterface;
|
---|
261 | FormProjectGroup.ReloadTree;
|
---|
262 | end;
|
---|
263 |
|
---|
264 | procedure TCore.AProjectGroupOpenExecute(Sender: TObject);
|
---|
265 | begin
|
---|
266 | if LastOpenedListProjectGroup.Items.Count > 0 then
|
---|
267 | OpenDialog1.FileName := LastOpenedListProjectGroup.Items[0];
|
---|
268 | if OpenDialog1.Execute then begin
|
---|
269 | AProjectClose.Execute;
|
---|
270 | ProjectGroupOpen(OpenDialog1.FileName);
|
---|
271 | end;
|
---|
272 | end;
|
---|
273 |
|
---|
274 | procedure TCore.AProjectGroupSaveAsExecute(Sender: TObject);
|
---|
275 | begin
|
---|
276 | SaveDialog1.FileName := ProjectGroup.FileName;
|
---|
277 | if SaveDialog1.Execute then begin
|
---|
278 | ProjectGroup.SaveToFile(SaveDialog1.FileName);
|
---|
279 | UpdateInterface;
|
---|
280 | end;
|
---|
281 | end;
|
---|
282 |
|
---|
283 | procedure TCore.AProjectGroupSaveExecute(Sender: TObject);
|
---|
284 | begin
|
---|
285 | if FileExistsUTF8(ProjectGroup.FileName) then ProjectGroup.SaveToFile(ProjectGroup.FileName)
|
---|
286 | else AProjectGroupSaveAs.Execute;
|
---|
287 | end;
|
---|
288 |
|
---|
289 | procedure TCore.ACommandUpdateExecute(Sender: TObject);
|
---|
290 | begin
|
---|
291 | Project.WorkingCopy.Update;
|
---|
292 | end;
|
---|
293 |
|
---|
294 | procedure TCore.AProjectCheckoutExecute(Sender: TObject);
|
---|
295 | var
|
---|
296 | TempProject: TProject;
|
---|
297 | begin
|
---|
298 | if LastOpenedListRepoURL.Items.Count > 0 then
|
---|
299 | FormCheckout.EditURL.Text := LastOpenedListRepoURL.Items[0];
|
---|
300 | if LastOpenedListNewDir.Items.Count > 0 then
|
---|
301 | FormCheckout.EditDir.Text := LastOpenedListNewDir.Items[0];
|
---|
302 | if FormCheckout.ShowModal = mrOk then begin
|
---|
303 | LastOpenedListRepoURL.AddItem(FormCheckout.EditURL.Text);
|
---|
304 | LastOpenedListNewDir.AddItem(FormCheckout.EditDir.Text);
|
---|
305 | TempProject := TProject.Create;
|
---|
306 | try
|
---|
307 | TempProject.Backend := TBackend(FormCheckout.ComboBox1.Items.Objects[FormCheckout.ComboBox1.ItemIndex]);
|
---|
308 | TempProject.Directory := FormCheckout.EditDir.Text;
|
---|
309 | TempProject.RepositoryURL := FormCheckout.EditURL.Text;
|
---|
310 | TempProject.WorkingCopy.Checkout;
|
---|
311 | finally
|
---|
312 | TempProject.Free;
|
---|
313 | end;
|
---|
314 | ProjectOpen(FormCheckout.EditDir.Text);
|
---|
315 | end;
|
---|
316 | end;
|
---|
317 |
|
---|
318 | procedure TCore.ACommandCleanupExecute(Sender: TObject);
|
---|
319 | begin
|
---|
320 | Project.WorkingCopy.Cleanup;
|
---|
321 | end;
|
---|
322 |
|
---|
323 | procedure TCore.ACommandCheckoutExecute(Sender: TObject);
|
---|
324 | begin
|
---|
325 |
|
---|
326 | end;
|
---|
327 |
|
---|
328 | procedure TCore.ACommandCommitExecute(Sender: TObject);
|
---|
329 | begin
|
---|
330 | if FormCommit.ShowModal = mrOk then begin
|
---|
331 | Project.WorkingCopy.Commit(FormCommit.MemoMessage.Lines);
|
---|
332 | end;
|
---|
333 | end;
|
---|
334 |
|
---|
335 | end.
|
---|
336 |
|
---|