source: trunk/Forms/UFormBrowse.pas

Last change on this file was 19, checked in by chronos, 7 years ago
  • Fixed: Build under Lazarus 1.8.0.
  • Modified: Updated Common package.
File size: 5.5 KB
Line 
1unit UFormBrowse;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 ExtCtrls, Menus, ActnList, UFindFile, UVCS, Contnrs, LazFileUtils;
10
11type
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
56var
57 FormBrowse: TFormBrowse;
58
59implementation
60
61uses
62 UCore, UFormLog;
63
64{$R *.lfm}
65
66{ TFormBrowse }
67
68procedure TFormBrowse.ListView1Data(Sender: TObject; Item: TListItem);
69begin
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;
80end;
81
82procedure TFormBrowse.ListView1DblClick(Sender: TObject);
83begin
84
85end;
86
87procedure TFormBrowse.ListView1SelectItem(Sender: TObject; Item: TListItem;
88 Selected: Boolean);
89begin
90 UpdateInterface;
91end;
92
93procedure TFormBrowse.ADeleteExecute(Sender: TObject);
94begin
95
96end;
97
98procedure TFormBrowse.ALogShowExecute(Sender: TObject);
99begin
100 FormLog.FileName := Directory + DirectorySeparator + ListView1.Selected.Caption;
101 FormLog.ShowModal;
102end;
103
104procedure TFormBrowse.AAddExecute(Sender: TObject);
105begin
106 Core.Project.WorkingCopy.Add(Directory + DirectorySeparator + ListView1.Selected.Caption);
107end;
108
109procedure TFormBrowse.AOpenExecute(Sender: TObject);
110begin
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;
122end;
123
124procedure TFormBrowse.ARenameExecute(Sender: TObject);
125var
126 NewName: string;
127begin
128 if InputQuery('Rename', 'Enter new name', NewName) then
129 Core.Project.WorkingCopy.Move(Directory + DirectorySeparator + ListView1.Selected.Caption, NewName);
130end;
131
132procedure TFormBrowse.FormCreate(Sender: TObject);
133begin
134 FileList := TObjectList.Create;
135end;
136
137procedure TFormBrowse.FormDestroy(Sender: TObject);
138begin
139 FileList.Free;
140end;
141
142procedure TFormBrowse.FormShow(Sender: TObject);
143begin
144 UpdateInterface;
145end;
146
147procedure TFormBrowse.ReloadList;
148var
149 FindFile: TFindFile;
150 FoundFileList: TStrings;
151 I: Integer;
152 FileStatusList: TFileStatusList;
153 NewFileItem: TFileStatus;
154 FS: TFileStatus;
155 RelativeName: string;
156begin
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;
197end;
198
199procedure TFormBrowse.UpdateInterface;
200begin
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);
207end;
208
209end.
210
Note: See TracBrowser for help on using the repository browser.