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