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