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