1 | unit _TemplateFileList;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
7 | Dialogs, _TemplateFile, StdCtrls, ExtCtrls, Menus, Buttons,
|
---|
8 | ComCtrls, TypeDefs, VirtualTrees;
|
---|
9 |
|
---|
10 | type
|
---|
11 | TForm_TemplateFileList = class(TForm_TemplateFile)
|
---|
12 | panel_files: TPanel;
|
---|
13 | splitter_content: TSplitter;
|
---|
14 | panel_content: TPanel;
|
---|
15 | filepopup: TPopupMenu;
|
---|
16 | popup_separator2: TMenuItem;
|
---|
17 | popup_linkshere: TMenuItem;
|
---|
18 | popup_separator: TMenuItem;
|
---|
19 | popup_import: TMenuItem;
|
---|
20 | popup_export: TMenuItem;
|
---|
21 | importd: TOpenDialog;
|
---|
22 | exportd: TSaveDialog;
|
---|
23 | FilePages: TPageControl;
|
---|
24 | tab_files: TTabSheet;
|
---|
25 | panel_extension: TPanel;
|
---|
26 | label_sort2: TLabel;
|
---|
27 | label_sort1: TLabel;
|
---|
28 | label_extension: TLabel;
|
---|
29 | btn_sort_id_asc: TSpeedButton;
|
---|
30 | btn_sort_id_desc: TSpeedButton;
|
---|
31 | btn_sort_name_asc: TSpeedButton;
|
---|
32 | btn_sort_name_desc: TSpeedButton;
|
---|
33 | btn_sort_ext_asc: TSpeedButton;
|
---|
34 | btn_sort_ext_desc: TSpeedButton;
|
---|
35 | combo_extension: TComboBox;
|
---|
36 | check_zerobyte: TCheckBox;
|
---|
37 | edit_filtername: TEdit;
|
---|
38 | check_filtername: TCheckBox;
|
---|
39 | filelist: TListBox;
|
---|
40 | tab_meta: TTabSheet;
|
---|
41 | filelist_meta: TVirtualStringTree;
|
---|
42 | procedure NewCon(ID: Integer);
|
---|
43 |
|
---|
44 | procedure check_filternameClick(Sender: TObject);
|
---|
45 | procedure check_zerobyteClick(Sender: TObject);
|
---|
46 | procedure combo_extensionClick(Sender: TObject);
|
---|
47 | procedure btn_sortClick(Sender: TObject);
|
---|
48 | procedure listClick(Sender: TObject);
|
---|
49 | procedure listMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
50 | Shift: TShiftState; X, Y: Integer);
|
---|
51 |
|
---|
52 | procedure popup_importClick(Sender: TObject);
|
---|
53 | procedure popup_exportClick(Sender: TObject);
|
---|
54 | procedure popup_opentool(Sender: TObject);
|
---|
55 | procedure popup_linkshereClick(Sender: TObject);
|
---|
56 | procedure filepopupPopup(Sender: TObject);
|
---|
57 | private
|
---|
58 | FSortBy: TSortType;
|
---|
59 | FAllowedExts: String;
|
---|
60 | FAllowMultiSelect: Boolean;
|
---|
61 | procedure SetAllowedExts(exts: String);
|
---|
62 | procedure SetMultiSelect(allow: Boolean);
|
---|
63 | public
|
---|
64 | constructor Create(AOwner: TComponent); override;
|
---|
65 | procedure RecreateExtList;
|
---|
66 | procedure LoadFileNames;
|
---|
67 | procedure SetFileFilters(pattern, extension: String; zerobytes: Boolean);
|
---|
68 | property AllowedExts: String read FAllowedExts write SetAllowedExts;
|
---|
69 | property AllowMultiSelect: Boolean read FAllowMultiSelect write SetMultiSelect;
|
---|
70 | end;
|
---|
71 |
|
---|
72 | implementation
|
---|
73 | {$R *.dfm}
|
---|
74 | uses ConnectionManager, Exporters, Functions, StrUtils, WhatLinksHere, Main,
|
---|
75 | _BaseTemplate;
|
---|
76 |
|
---|
77 |
|
---|
78 | procedure TForm_TemplateFileList.RecreateExtList;
|
---|
79 | var
|
---|
80 | i: Integer;
|
---|
81 | exts: TStrings;
|
---|
82 | begin
|
---|
83 | combo_extension.Items.Clear;
|
---|
84 | if FConnectionID > -1 then
|
---|
85 | begin
|
---|
86 | combo_extension.Items.Add('_All files_ (' +
|
---|
87 | IntToStr(ConManager.Connection[FConnectionID].GetFileCount) + ')');
|
---|
88 | exts := nil;
|
---|
89 | exts := ConManager.Connection[FConnectionID].GetExtensionsList(EF_ExtCount);
|
---|
90 | for i := 0 to exts.Count - 1 do
|
---|
91 | if Length(FAllowedExts) > 0 then
|
---|
92 | begin
|
---|
93 | if Pos(MidStr(exts.Strings[i],1,4), FAllowedExts) > 0 then
|
---|
94 | combo_extension.Items.Add(exts.Strings[i]);
|
---|
95 | end
|
---|
96 | else
|
---|
97 | combo_extension.Items.Add(exts.Strings[i]);
|
---|
98 | combo_extension.ItemIndex := 0;
|
---|
99 | combo_extensionClick(Self);
|
---|
100 | exts.Free;
|
---|
101 | end;
|
---|
102 | end;
|
---|
103 |
|
---|
104 | procedure TForm_TemplateFileList.LoadFileNames;
|
---|
105 | var
|
---|
106 | Extension: String;
|
---|
107 | no_zero_bytes: Boolean;
|
---|
108 | pattern: String;
|
---|
109 | files: TStrings;
|
---|
110 | begin
|
---|
111 | if FConnectionID > -1 then
|
---|
112 | begin
|
---|
113 | Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
|
---|
114 | no_zero_bytes := not check_zerobyte.Checked;
|
---|
115 | pattern := '';
|
---|
116 | if check_filtername.Checked then
|
---|
117 | pattern := edit_filtername.Text;
|
---|
118 | if Extension = '_All' then
|
---|
119 | if Length(FAllowedExts) > 0 then
|
---|
120 | Extension := FAllowedExts
|
---|
121 | else
|
---|
122 | Extension := '';
|
---|
123 |
|
---|
124 | files := nil;
|
---|
125 | files := ConManager.Connection[FConnectionID].GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
|
---|
126 |
|
---|
127 | filelist.Visible := False;
|
---|
128 | filelist.Items.Clear;
|
---|
129 | if files.Count > 0 then
|
---|
130 | filelist.Items.AddStrings(files);
|
---|
131 | filelist.Visible := True;
|
---|
132 | end;
|
---|
133 | end;
|
---|
134 |
|
---|
135 |
|
---|
136 | procedure TForm_TemplateFileList.NewCon(ID: Integer);
|
---|
137 | begin
|
---|
138 | RecreateExtList;
|
---|
139 | end;
|
---|
140 |
|
---|
141 | procedure TForm_TemplateFileList.popup_exportClick(Sender: TObject);
|
---|
142 | var
|
---|
143 | id: Integer;
|
---|
144 | ext: String;
|
---|
145 | begin
|
---|
146 | id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
|
---|
147 | ext := RightStr(filelist.Items.Strings[filelist.ItemIndex], 4);
|
---|
148 | exportd.Filter := 'Files of matching extension (*.' + ext + ')|*.' + ext + '|All files|*.*';
|
---|
149 | exportd.DefaultExt := ext;
|
---|
150 | if exportd.Execute then
|
---|
151 | ExportDatFile(FConnectionID, id, exportd.FileName);
|
---|
152 | end;
|
---|
153 |
|
---|
154 | procedure TForm_TemplateFileList.popup_importClick(Sender: TObject);
|
---|
155 | var
|
---|
156 | id: Integer;
|
---|
157 | finfo: TFileInfo;
|
---|
158 | fs: TFileStream;
|
---|
159 | begin
|
---|
160 | if CR_EditDat in ConManager.Connection[FConnectionID].ChangeRights then
|
---|
161 | begin
|
---|
162 | id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
|
---|
163 | finfo := ConManager.Connection[FConnectionID].GetFileInfo(id);
|
---|
164 |
|
---|
165 | importd.Filter := 'Files of matching extension (*.' + finfo.Extension + ')|*.' +
|
---|
166 | finfo.Extension + '|All files|*.*';
|
---|
167 | if importd.Execute then
|
---|
168 | begin
|
---|
169 | fs := TFileStream.Create(importd.FileName, fmOpenRead);
|
---|
170 | if fs.Size <> finfo.Size then
|
---|
171 | begin
|
---|
172 | if not (CR_ResizeDat in ConManager.Connection[FConnectionID].ChangeRights) then
|
---|
173 | begin
|
---|
174 | ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) +
|
---|
175 | ', file has to have same size as file in .dat with this backend.' + CrLf +
|
---|
176 | 'Size of file in .dat: ' + FormatFileSize(finfo.Size) + CrLf +
|
---|
177 | 'Size of chosen file: ' + FormatFileSize(fs.Size));
|
---|
178 | Exit;
|
---|
179 | end else begin
|
---|
180 | if MessageBox(Self.Handle,
|
---|
181 | PChar('File has different size from the file in the .dat.' + CrLf +
|
---|
182 | 'Size of file in .dat: ' + FormatFileSize(finfo.Size) + CrLf +
|
---|
183 | 'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf +
|
---|
184 | 'Replace anyway?'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then
|
---|
185 | begin
|
---|
186 | Exit;
|
---|
187 | end;
|
---|
188 | end;
|
---|
189 | end;
|
---|
190 | ConManager.Connection[FConnectionID].UpdateDatFile(id, fs);
|
---|
191 | Self.listClick(Self);
|
---|
192 | fs.Free;
|
---|
193 | end;
|
---|
194 | end else begin
|
---|
195 | ShowMessage('Editing .dat-contents not allowed with this backend.');
|
---|
196 | end;
|
---|
197 | end;
|
---|
198 |
|
---|
199 |
|
---|
200 | procedure TForm_TemplateFileList.popup_linkshereClick(Sender: TObject);
|
---|
201 | begin
|
---|
202 | Form_WhatLinksHere.ConID := FConnectionID;
|
---|
203 | Form_WhatLinksHere.FileID := FSelectedFile.ID;
|
---|
204 | Form_WhatLinksHere.SenderForm := Self;
|
---|
205 | Form_WhatLinksHere.Show;
|
---|
206 | end;
|
---|
207 |
|
---|
208 | procedure TForm_TemplateFileList.popup_opentool(Sender: TObject);
|
---|
209 | var
|
---|
210 | sender_name, context: String;
|
---|
211 | id: Integer;
|
---|
212 | begin
|
---|
213 | sender_name := TComponent(Sender).Name;
|
---|
214 | id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
|
---|
215 | context := MidStr(sender_name, Pos('_', sender_name) + 1, Length(sender_name) - Pos('_', sender_name));
|
---|
216 | Form_Main.open_child(context, FConnectionID, id);
|
---|
217 | end;
|
---|
218 |
|
---|
219 | procedure TForm_TemplateFileList.filepopupPopup(Sender: TObject);
|
---|
220 | var
|
---|
221 | ext: String;
|
---|
222 | i: Integer;
|
---|
223 | begin
|
---|
224 | ext := RightStr(filelist.Items.Strings[filelist.ItemIndex], 4);
|
---|
225 | for i := 0 to High(ToolList) do
|
---|
226 | begin
|
---|
227 | filepopup.Items.Items[i].Enabled := True;
|
---|
228 | if Length(ToolList[i].exts) > 0 then
|
---|
229 | if Pos(ext, ToolList[i].exts) = 0 then
|
---|
230 | filepopup.Items.Items[i].Enabled := False;
|
---|
231 | end;
|
---|
232 | end;
|
---|
233 |
|
---|
234 |
|
---|
235 | procedure TForm_TemplateFileList.check_zerobyteClick(Sender: TObject);
|
---|
236 | begin
|
---|
237 | LoadFileNames;
|
---|
238 | end;
|
---|
239 |
|
---|
240 | procedure TForm_TemplateFileList.btn_sortClick(Sender: TObject);
|
---|
241 | begin
|
---|
242 | if btn_sort_id_asc.Down then
|
---|
243 | FSortBy := ST_IDAsc
|
---|
244 | else if btn_sort_id_desc.Down then
|
---|
245 | FSortBy := ST_IDDesc
|
---|
246 | else if btn_sort_name_asc.Down then
|
---|
247 | FSortBy := ST_NameAsc
|
---|
248 | else if btn_sort_name_desc.Down then
|
---|
249 | FSortBy := ST_NameDesc
|
---|
250 | else if btn_sort_ext_asc.Down then
|
---|
251 | FSortBy := ST_ExtAsc
|
---|
252 | else if btn_sort_ext_desc.Down then
|
---|
253 | FSortBy := ST_ExtDesc;
|
---|
254 | LoadFileNames;
|
---|
255 | end;
|
---|
256 |
|
---|
257 | procedure TForm_TemplateFileList.check_filternameClick(Sender: TObject);
|
---|
258 | begin
|
---|
259 | edit_filtername.Enabled := not check_filtername.Checked;
|
---|
260 | LoadFileNames;
|
---|
261 | end;
|
---|
262 |
|
---|
263 | procedure TForm_TemplateFileList.combo_extensionClick(Sender: TObject);
|
---|
264 | begin
|
---|
265 | LoadFileNames;
|
---|
266 | end;
|
---|
267 |
|
---|
268 | procedure TForm_TemplateFileList.listClick(Sender: TObject);
|
---|
269 | var
|
---|
270 | fileid: Integer;
|
---|
271 | begin
|
---|
272 | if filelist.ItemIndex > -1 then
|
---|
273 | begin
|
---|
274 | fileid := ConManager.Connection[FConnectionID].ExtractFileIDOfName(
|
---|
275 | filelist.Items.Strings[filelist.ItemIndex]);
|
---|
276 | FSelectedFile := ConManager.Connection[FConnectionID].GetFileInfo(fileid);
|
---|
277 | if Assigned(FOnNewFileSelected) then
|
---|
278 | FOnNewFileSelected(FSelectedFile);
|
---|
279 | end;
|
---|
280 | end;
|
---|
281 |
|
---|
282 | procedure TForm_TemplateFileList.listMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
283 | Shift: TShiftState; X, Y: Integer);
|
---|
284 | var
|
---|
285 | pt: TPoint;
|
---|
286 | begin
|
---|
287 | pt.X := x;
|
---|
288 | pt.Y := y;
|
---|
289 | if Shift = [ssRight] then
|
---|
290 | begin
|
---|
291 | filelist.ItemIndex := filelist.ItemAtPos(pt, true);
|
---|
292 | Self.listClick(Self);
|
---|
293 | end;
|
---|
294 | end;
|
---|
295 |
|
---|
296 |
|
---|
297 |
|
---|
298 | procedure TForm_TemplateFileList.SetAllowedExts(exts: String);
|
---|
299 | begin
|
---|
300 | FAllowedExts := exts;
|
---|
301 | RecreateExtList;
|
---|
302 | end;
|
---|
303 |
|
---|
304 | procedure TForm_TemplateFileList.SetFileFilters(pattern, extension: String;
|
---|
305 | zerobytes: Boolean);
|
---|
306 | var
|
---|
307 | i: Integer;
|
---|
308 | begin
|
---|
309 | if Length(pattern) > 0 then
|
---|
310 | Self.edit_filtername.Text := pattern;
|
---|
311 | Self.check_filtername.Checked := Length(pattern) > 0;
|
---|
312 | if Length(extension) > 0 then
|
---|
313 | begin
|
---|
314 | for i := 0 to Self.combo_extension.Items.Count - 1 do
|
---|
315 | if Pos(extension, Self.combo_extension.Items.Strings[i]) > 0 then
|
---|
316 | Break;
|
---|
317 | if i < Self.combo_extension.Items.Count then
|
---|
318 | Self.combo_extension.ItemIndex := i
|
---|
319 | else
|
---|
320 | Self.combo_extension.ItemIndex := -1;
|
---|
321 | end;
|
---|
322 | Self.check_zerobyte.Checked := zerobytes;
|
---|
323 | Self.LoadFileNames;
|
---|
324 | end;
|
---|
325 |
|
---|
326 | procedure TForm_TemplateFileList.SetMultiSelect(allow: Boolean);
|
---|
327 | begin
|
---|
328 | FAllowMultiSelect := allow;
|
---|
329 | filelist.MultiSelect := allow;
|
---|
330 | end;
|
---|
331 |
|
---|
332 |
|
---|
333 |
|
---|
334 | constructor TForm_TemplateFileList.Create(AOwner: TComponent);
|
---|
335 | var
|
---|
336 | i: Integer;
|
---|
337 | item: TMenuItem;
|
---|
338 | begin
|
---|
339 | inherited;
|
---|
340 | FAllowedExts := '';
|
---|
341 | FAllowMultiSelect := False;
|
---|
342 | FOnNewConnection := NewCon;
|
---|
343 | UpdateConList;
|
---|
344 | if Length(ToolList) > 0 then
|
---|
345 | begin
|
---|
346 | for i := 0 to High(ToolList) do
|
---|
347 | begin
|
---|
348 | item := TMenuItem.Create(filepopup);
|
---|
349 | item.Name := 'popup_' + ToolList[i].context;
|
---|
350 | item.Caption := 'Open with ' + ToolList[i].name;
|
---|
351 | item.OnClick := Self.popup_opentool;
|
---|
352 | filepopup.Items.Insert(i, item);
|
---|
353 | end;
|
---|
354 | end;
|
---|
355 | end;
|
---|
356 |
|
---|
357 |
|
---|
358 | end.
|
---|