1 | unit UFormBrowse;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
9 | ExtCtrls, Menus, ActnList, UFindFile, UVCS, Contnrs, LazFileUtils;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormBrowse }
|
---|
14 |
|
---|
15 | TFormBrowse = class(TForm)
|
---|
16 | AAdd: TAction;
|
---|
17 | ALogShow: TAction;
|
---|
18 | AOpen: TAction;
|
---|
19 | AProperties: TAction;
|
---|
20 | AUpdate: TAction;
|
---|
21 | ARename: TAction;
|
---|
22 | ADelete: TAction;
|
---|
23 | ActionList1: TActionList;
|
---|
24 | ListView1: TListView;
|
---|
25 | MainMenu1: TMainMenu;
|
---|
26 | MenuItem1: TMenuItem;
|
---|
27 | MenuItem2: TMenuItem;
|
---|
28 | MenuItem3: TMenuItem;
|
---|
29 | MenuItem4: TMenuItem;
|
---|
30 | MenuItem5: TMenuItem;
|
---|
31 | MenuItem6: TMenuItem;
|
---|
32 | MenuItem7: TMenuItem;
|
---|
33 | PopupMenu1: TPopupMenu;
|
---|
34 | Splitter1: TSplitter;
|
---|
35 | TreeView1: TTreeView;
|
---|
36 | procedure AAddExecute(Sender: TObject);
|
---|
37 | procedure ADeleteExecute(Sender: TObject);
|
---|
38 | procedure ALogShowExecute(Sender: TObject);
|
---|
39 | procedure AOpenExecute(Sender: TObject);
|
---|
40 | procedure ARenameExecute(Sender: TObject);
|
---|
41 | procedure FormCreate(Sender: TObject);
|
---|
42 | procedure FormDestroy(Sender: TObject);
|
---|
43 | procedure FormShow(Sender: TObject);
|
---|
44 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
45 | procedure ListView1DblClick(Sender: TObject);
|
---|
46 | procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
47 | Selected: Boolean);
|
---|
48 | private
|
---|
49 | FileList: TObjectList;
|
---|
50 | public
|
---|
51 | Directory: string;
|
---|
52 | procedure ReloadList;
|
---|
53 | procedure UpdateInterface;
|
---|
54 | end;
|
---|
55 |
|
---|
56 | var
|
---|
57 | FormBrowse: TFormBrowse;
|
---|
58 |
|
---|
59 | implementation
|
---|
60 |
|
---|
61 | uses
|
---|
62 | UCore, UFormLog;
|
---|
63 |
|
---|
64 | {$R *.lfm}
|
---|
65 |
|
---|
66 | { TFormBrowse }
|
---|
67 |
|
---|
68 | procedure TFormBrowse.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
69 | begin
|
---|
70 | if (Item.Index >= 0) and (Item.Index < FileList.Count) then
|
---|
71 | with TFileStatus(FileList[Item.Index]) do begin
|
---|
72 | Item.Caption := ExtractFileName(FileName);
|
---|
73 | if State <> fssNonVersioned then begin
|
---|
74 | Item.SubItems.Add(Version);
|
---|
75 | Item.SubItems.Add(DateToStr(Time));
|
---|
76 | Item.SubItems.Add(Author);
|
---|
77 | Item.SubItems.Add(FileStatusStateText[State]);
|
---|
78 | end;
|
---|
79 | end;
|
---|
80 | end;
|
---|
81 |
|
---|
82 | procedure TFormBrowse.ListView1DblClick(Sender: TObject);
|
---|
83 | begin
|
---|
84 |
|
---|
85 | end;
|
---|
86 |
|
---|
87 | procedure TFormBrowse.ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
88 | Selected: Boolean);
|
---|
89 | begin
|
---|
90 | UpdateInterface;
|
---|
91 | end;
|
---|
92 |
|
---|
93 | procedure TFormBrowse.ADeleteExecute(Sender: TObject);
|
---|
94 | begin
|
---|
95 |
|
---|
96 | end;
|
---|
97 |
|
---|
98 | procedure TFormBrowse.ALogShowExecute(Sender: TObject);
|
---|
99 | begin
|
---|
100 | FormLog.FileName := Directory + DirectorySeparator + ListView1.Selected.Caption;
|
---|
101 | FormLog.ShowModal;
|
---|
102 | end;
|
---|
103 |
|
---|
104 | procedure TFormBrowse.AAddExecute(Sender: TObject);
|
---|
105 | begin
|
---|
106 | Core.Project.WorkingCopy.Add(Directory + DirectorySeparator + ListView1.Selected.Caption);
|
---|
107 | end;
|
---|
108 |
|
---|
109 | procedure TFormBrowse.AOpenExecute(Sender: TObject);
|
---|
110 | begin
|
---|
111 | if Assigned(ListView1.Selected) then
|
---|
112 | with ListView1.Selected do begin
|
---|
113 | if Caption = '..' then begin
|
---|
114 | Directory := ExtractFileDir(Directory);
|
---|
115 | ReloadList;
|
---|
116 | end else
|
---|
117 | if DirectoryExistsUTF8(Directory + DirectorySeparator + Caption) then begin
|
---|
118 | Directory := Directory + DirectorySeparator + ListView1.Selected.Caption;
|
---|
119 | ReloadList;
|
---|
120 | end;
|
---|
121 | end;
|
---|
122 | end;
|
---|
123 |
|
---|
124 | procedure TFormBrowse.ARenameExecute(Sender: TObject);
|
---|
125 | var
|
---|
126 | NewName: string;
|
---|
127 | begin
|
---|
128 | if InputQuery('Rename', 'Enter new name', NewName) then
|
---|
129 | Core.Project.WorkingCopy.Move(Directory + DirectorySeparator + ListView1.Selected.Caption, NewName);
|
---|
130 | end;
|
---|
131 |
|
---|
132 | procedure TFormBrowse.FormCreate(Sender: TObject);
|
---|
133 | begin
|
---|
134 | FileList := TObjectList.Create;
|
---|
135 | end;
|
---|
136 |
|
---|
137 | procedure TFormBrowse.FormDestroy(Sender: TObject);
|
---|
138 | begin
|
---|
139 | FileList.Free;
|
---|
140 | end;
|
---|
141 |
|
---|
142 | procedure TFormBrowse.FormShow(Sender: TObject);
|
---|
143 | begin
|
---|
144 | UpdateInterface;
|
---|
145 | end;
|
---|
146 |
|
---|
147 | procedure TFormBrowse.ReloadList;
|
---|
148 | var
|
---|
149 | FindFile: TFindFile;
|
---|
150 | FoundFileList: TStrings;
|
---|
151 | I: Integer;
|
---|
152 | FileStatusList: TFileStatusList;
|
---|
153 | NewFileItem: TFileStatus;
|
---|
154 | FS: TFileStatus;
|
---|
155 | RelativeName: string;
|
---|
156 | begin
|
---|
157 | FileList.Clear;
|
---|
158 | if Assigned(Core.Project) then begin
|
---|
159 | FileStatusList := TFileStatusList.Create;
|
---|
160 | try
|
---|
161 | Core.Project.WorkingCopy.GetStatus(Directory, FileStatusList);
|
---|
162 |
|
---|
163 | if DirectoryExistsUTF8(Directory) then begin
|
---|
164 | FindFile := TFindFile.Create(nil);
|
---|
165 | try
|
---|
166 | FindFile.Path := Directory;
|
---|
167 | FindFile.FileMask := AllFilesMask;
|
---|
168 | FindFile.InSubFolders := False;
|
---|
169 | FoundFileList := FindFile.SearchForFiles;
|
---|
170 | //FoundFileList.Sort;
|
---|
171 | for I := 0 to FoundFileList.Count - 1 do begin
|
---|
172 | NewFileItem := TFileStatus.Create;
|
---|
173 | NewFileItem.FileName := FoundFileList[I];
|
---|
174 | RelativeName := NewFileItem.FileName;
|
---|
175 | if Copy(RelativeName, 1, Length(Core.Project.WorkingCopy.Path)) = Core.Project.WorkingCopy.Path then
|
---|
176 | Delete(RelativeName, 1, Length(Core.Project.WorkingCopy.Path));
|
---|
177 | if Copy(RelativeName, 1, 1) = DirectorySeparator then
|
---|
178 | Delete(RelativeName, 1, Length(DirectorySeparator));
|
---|
179 | FS := FileStatusList.SearchByName(RelativeName);
|
---|
180 | if Assigned(FS) then begin
|
---|
181 | NewFileItem.Assign(FS);
|
---|
182 | end;
|
---|
183 | FileList.Add(NewFileItem);
|
---|
184 | end;
|
---|
185 | for I := FileList.Count - 1 downto 0 do
|
---|
186 | if ExtractFileName(TFileStatus(FileList[I]).FileName) = '.' then FileList.Delete(I);
|
---|
187 | ListView1.Items.Count := FileList.Count;
|
---|
188 | finally
|
---|
189 | FindFile.Free;
|
---|
190 | end;
|
---|
191 | end else ListView1.Items.Count := 0;
|
---|
192 | finally
|
---|
193 | FileStatusList.Free;
|
---|
194 | end;
|
---|
195 | end;
|
---|
196 | ListView1.Refresh;
|
---|
197 | end;
|
---|
198 |
|
---|
199 | procedure TFormBrowse.UpdateInterface;
|
---|
200 | begin
|
---|
201 | AAdd.Enabled := Assigned(ListView1.Selected);
|
---|
202 | ADelete.Enabled := Assigned(ListView1.Selected);
|
---|
203 | ARename.Enabled := Assigned(ListView1.Selected);
|
---|
204 | AProperties.Enabled := Assigned(ListView1.Selected);
|
---|
205 | AOpen.Enabled := Assigned(ListView1.Selected);
|
---|
206 | ALogShow.Enabled := Assigned(ListView1.Selected);
|
---|
207 | end;
|
---|
208 |
|
---|
209 | end.
|
---|
210 |
|
---|