[93] | 1 | unit Template;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
| 7 | Dialogs, ExtCtrls, StdCtrls, StrUtils,
|
---|
[97] | 8 | Data, TypeDefs, Menus, Buttons;
|
---|
[93] | 9 |
|
---|
| 10 | type
|
---|
| 11 | TNewFileSelectedEvent = procedure(FileInfo: TFileInfo) of object;
|
---|
| 12 | TNewConnectionEvent = procedure(Connection: Integer) of object;
|
---|
[97] | 13 | TCheckCloseableEvent = function: Boolean of object;
|
---|
[93] | 14 |
|
---|
| 15 | TForm_ToolTemplate = class(TForm)
|
---|
| 16 | panel_files: TPanel;
|
---|
| 17 | filelist: TListBox;
|
---|
| 18 | panel_extension: TPanel;
|
---|
| 19 | label_ext: TLabel;
|
---|
| 20 | combo_extension: TComboBox;
|
---|
| 21 | check_zerobyte: TCheckBox;
|
---|
| 22 | edit_filtername: TEdit;
|
---|
| 23 | check_filtername: TCheckBox;
|
---|
| 24 | Splitter1: TSplitter;
|
---|
| 25 | content: TPanel;
|
---|
| 26 | filepopup: TPopupMenu;
|
---|
| 27 | popup_import: TMenuItem;
|
---|
| 28 | popup_export: TMenuItem;
|
---|
| 29 | popup_separator: TMenuItem;
|
---|
| 30 | importd: TOpenDialog;
|
---|
| 31 | exportd: TSaveDialog;
|
---|
| 32 | btn_sort_id_asc: TSpeedButton;
|
---|
| 33 | btn_sort_id_desc: TSpeedButton;
|
---|
| 34 | btn_sort_name_asc: TSpeedButton;
|
---|
| 35 | btn_sort_name_desc: TSpeedButton;
|
---|
| 36 | btn_sort_ext_asc: TSpeedButton;
|
---|
| 37 | btn_sort_ext_desc: TSpeedButton;
|
---|
| 38 | Label1: TLabel;
|
---|
| 39 | Label2: TLabel;
|
---|
| 40 | Label3: TLabel;
|
---|
| 41 | combo_connection: TComboBox;
|
---|
| 42 | Bevel1: TBevel;
|
---|
| 43 | procedure RecreateExtList;
|
---|
[97] | 44 | procedure UpdateConList;
|
---|
[93] | 45 | procedure LoadFileNames;
|
---|
[97] | 46 | procedure SelectFileName(ConnectionID: Integer; FileName: String);
|
---|
| 47 | procedure SelectFileID(ConnectionID, FileID: Integer);
|
---|
| 48 | procedure SelectConnection(ConnectionID: Integer);
|
---|
[93] | 49 | procedure check_filternameClick(Sender: TObject);
|
---|
| 50 | procedure check_zerobyteClick(Sender: TObject);
|
---|
| 51 | procedure combo_extensionClick(Sender: TObject);
|
---|
| 52 | procedure listClick(Sender: TObject);
|
---|
| 53 | procedure listMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
| 54 | Shift: TShiftState; X, Y: Integer);
|
---|
| 55 |
|
---|
| 56 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 57 | procedure popup_importClick(Sender: TObject);
|
---|
| 58 | procedure popup_exportClick(Sender: TObject);
|
---|
| 59 | procedure popup_opentool(Sender: TObject);
|
---|
| 60 | procedure filepopupPopup(Sender: TObject);
|
---|
| 61 | procedure btn_sortClick(Sender: TObject);
|
---|
| 62 | procedure FormActivate(Sender: TObject);
|
---|
| 63 | procedure combo_connectionChange(Sender: TObject);
|
---|
| 64 | private
|
---|
| 65 | FSortBy: TSortType;
|
---|
| 66 | FOnNewFileSelected: TNewFileSelectedEvent;
|
---|
| 67 | FOnNewConnection: TNewConnectionEvent;
|
---|
[97] | 68 | FOnCheckCloseable: TCheckCloseableEvent;
|
---|
[93] | 69 | FAllowedExts: String;
|
---|
| 70 | FAllowMultiSelect: Boolean;
|
---|
| 71 | FSelectedFile: TFileInfo;
|
---|
[97] | 72 | FConnectionID: Integer;
|
---|
[93] | 73 | procedure SetAllowedExts(exts: String);
|
---|
| 74 | procedure SetMultiSelect(allow: Boolean);
|
---|
[97] | 75 | function GetToolCloseable: Boolean;
|
---|
[93] | 76 | public
|
---|
| 77 | constructor Create(AOwner: TComponent); override;
|
---|
| 78 | procedure SetFileFilters(pattern, extension: String; zerobytes: Boolean);
|
---|
| 79 | published
|
---|
| 80 | property OnNewFileSelected: TNewFileSelectedEvent read FOnNewFileSelected write FOnNewFileSelected;
|
---|
| 81 | property OnNewConnection: TNewConnectionEvent read FOnNewConnection write FOnNewConnection;
|
---|
[97] | 82 | property OnCheckCloseable: TCheckCloseableEvent read FOnCheckCloseable write FOnCheckCloseable;
|
---|
[93] | 83 | property AllowedExts: String read FAllowedExts write SetAllowedExts;
|
---|
| 84 | property AllowMultiSelect: Boolean read FAllowMultiSelect write SetMultiSelect;
|
---|
| 85 | property SelectedFile: TFileInfo read FSelectedFile;
|
---|
[97] | 86 | property ConnectionID: Integer read FConnectionID;
|
---|
| 87 | property Closeable: Boolean read GetToolCloseable;
|
---|
[93] | 88 | end;
|
---|
| 89 |
|
---|
| 90 | var
|
---|
| 91 | ToolList: TToolList;
|
---|
| 92 | procedure AddToolListEntry(context, name, exts: String);
|
---|
| 93 |
|
---|
| 94 | implementation
|
---|
| 95 | {$R *.dfm}
|
---|
[97] | 96 | uses Main, ConnectionManager, Exporters, Functions;
|
---|
[93] | 97 |
|
---|
| 98 |
|
---|
[97] | 99 | procedure TForm_ToolTemplate.UpdateConList;
|
---|
[93] | 100 | var
|
---|
| 101 | i: Integer;
|
---|
| 102 | fn, datatype, boxstring: String;
|
---|
| 103 | level: Integer;
|
---|
| 104 | begin
|
---|
| 105 | combo_connection.ItemIndex := -1;
|
---|
| 106 | combo_connection.Items.Clear;
|
---|
[97] | 107 | if ConManager.Count > 0 then
|
---|
[93] | 108 | begin
|
---|
[97] | 109 | for i := 0 to ConManager.Count - 1 do
|
---|
[93] | 110 | begin
|
---|
[97] | 111 | level := ConManager.ConnectionByIndex[i].LevelNumber;
|
---|
| 112 | fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
|
---|
| 113 | if ConManager.ConnectionByIndex[i].Backend = DB_ONI then
|
---|
[93] | 114 | datatype := 'ONI-.dat: '
|
---|
[97] | 115 | else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then
|
---|
[93] | 116 | datatype := 'OUP-DB: '
|
---|
| 117 | else
|
---|
| 118 | datatype := 'Unknown: ';
|
---|
| 119 | boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
|
---|
| 120 | combo_connection.Items.Add(boxstring);
|
---|
[97] | 121 | if ConManager.ConnectionByIndex[i].ConnectionID = FConnectionID then
|
---|
[93] | 122 | combo_connection.ItemIndex := combo_connection.Items.Count - 1;
|
---|
| 123 | end;
|
---|
| 124 | if combo_connection.ItemIndex = -1 then
|
---|
| 125 | begin
|
---|
| 126 | combo_connection.ItemIndex := 0;
|
---|
| 127 | combo_connectionChange(Self);
|
---|
| 128 | end;
|
---|
| 129 | end
|
---|
| 130 | else
|
---|
| 131 | begin
|
---|
[97] | 132 | FConnectionID := 0;
|
---|
[93] | 133 | filelist.Items.Clear;
|
---|
| 134 | combo_extension.Items.Clear;
|
---|
| 135 | combo_connectionChange(Self);
|
---|
[97] | 136 | FSelectedFile.ID := -1;
|
---|
[93] | 137 | if Assigned(FOnNewFileSelected) then
|
---|
| 138 | FOnNewFileSelected(FSelectedFile);
|
---|
| 139 | end;
|
---|
| 140 | end;
|
---|
| 141 |
|
---|
| 142 | procedure TForm_ToolTemplate.RecreateExtList;
|
---|
| 143 | var
|
---|
[97] | 144 | i: Integer;
|
---|
| 145 | exts: TStrings;
|
---|
[93] | 146 | begin
|
---|
| 147 | combo_extension.Items.Clear;
|
---|
[97] | 148 | if FConnectionID > -1 then
|
---|
[93] | 149 | begin
|
---|
| 150 | combo_extension.Items.Add('_All files_ (' +
|
---|
[97] | 151 | IntToStr(ConManager.Connection[FConnectionID].GetFileCount) + ')');
|
---|
| 152 | exts := ConManager.Connection[FConnectionID].GetExtensionsList(EF_ExtCount);
|
---|
| 153 | for i := 0 to exts.Count - 1 do
|
---|
[93] | 154 | if Length(FAllowedExts) > 0 then
|
---|
| 155 | begin
|
---|
[97] | 156 | if Pos(MidStr(exts.Strings[i],1,4), FAllowedExts) > 0 then
|
---|
| 157 | combo_extension.Items.Add(exts.Strings[i]);
|
---|
| 158 | end
|
---|
| 159 | else
|
---|
| 160 | combo_extension.Items.Add(exts.Strings[i]);
|
---|
[93] | 161 | combo_extension.ItemIndex := 0;
|
---|
| 162 | combo_extensionClick(Self);
|
---|
[97] | 163 | exts.Free;
|
---|
[93] | 164 | end;
|
---|
| 165 | end;
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 | procedure TForm_ToolTemplate.LoadFileNames;
|
---|
| 171 | var
|
---|
| 172 | Extension: String;
|
---|
| 173 | no_zero_bytes: Boolean;
|
---|
| 174 | pattern: String;
|
---|
[97] | 175 | files: TStrings;
|
---|
| 176 | i: Integer;
|
---|
[93] | 177 | begin
|
---|
[97] | 178 | if FConnectionID > -1 then
|
---|
[93] | 179 | begin
|
---|
| 180 | Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
|
---|
| 181 | no_zero_bytes := not check_zerobyte.Checked;
|
---|
| 182 | pattern := '';
|
---|
| 183 | if check_filtername.Checked then
|
---|
| 184 | pattern := edit_filtername.Text;
|
---|
| 185 | if Extension = '_All' then
|
---|
| 186 | if Length(FAllowedExts) > 0 then
|
---|
| 187 | Extension := FAllowedExts
|
---|
| 188 | else
|
---|
| 189 | Extension := '';
|
---|
| 190 |
|
---|
[97] | 191 | files := ConManager.Connection[FConnectionID].GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
|
---|
[93] | 192 |
|
---|
| 193 | filelist.Visible := False;
|
---|
| 194 | filelist.Items.Clear;
|
---|
[97] | 195 | if files.Count > 0 then
|
---|
| 196 | filelist.Items.AddStrings(files);
|
---|
[93] | 197 | filelist.Visible := True;
|
---|
| 198 | end;
|
---|
| 199 | end;
|
---|
| 200 |
|
---|
| 201 |
|
---|
| 202 | procedure TForm_ToolTemplate.popup_exportClick(Sender: TObject);
|
---|
| 203 | var
|
---|
| 204 | id: Integer;
|
---|
| 205 | ext: String;
|
---|
| 206 | begin
|
---|
[97] | 207 | id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
|
---|
[93] | 208 | ext := RightStr(filelist.Items.Strings[filelist.ItemIndex], 4);
|
---|
| 209 | exportd.Filter := 'Files of matching extension (*.' + ext + ')|*.' + ext + '|All files|*.*';
|
---|
| 210 | exportd.DefaultExt := ext;
|
---|
| 211 | if exportd.Execute then
|
---|
[97] | 212 | ExportDatFile(FConnectionID, id, exportd.FileName);
|
---|
[93] | 213 | end;
|
---|
| 214 |
|
---|
| 215 | procedure TForm_ToolTemplate.popup_importClick(Sender: TObject);
|
---|
| 216 | var
|
---|
| 217 | id: Integer;
|
---|
| 218 | finfo: TFileInfo;
|
---|
| 219 | fs: TFileStream;
|
---|
| 220 | begin
|
---|
[101] | 221 | if CR_EditDat in ConManager.Connection[FConnectionID].ChangeRights then
|
---|
| 222 | begin
|
---|
| 223 | id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
|
---|
| 224 | finfo := ConManager.Connection[FConnectionID].GetFileInfo(id);
|
---|
[93] | 225 |
|
---|
[101] | 226 | importd.Filter := 'Files of matching extension (*.' + finfo.Extension + ')|*.' +
|
---|
| 227 | finfo.Extension + '|All files|*.*';
|
---|
| 228 | if importd.Execute then
|
---|
| 229 | begin
|
---|
| 230 | fs := TFileStream.Create(importd.FileName, fmOpenRead);
|
---|
| 231 | if fs.Size <> finfo.Size then
|
---|
| 232 | begin
|
---|
| 233 | if not (CR_ResizeDat in ConManager.Connection[FConnectionID].ChangeRights) then
|
---|
| 234 | begin
|
---|
| 235 | ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) +
|
---|
| 236 | ', file has to have same size as file in .dat with this backend.' + CrLf +
|
---|
| 237 | 'Size of file in .dat: ' + FormatFileSize(finfo.Size) + CrLf +
|
---|
| 238 | 'Size of chosen file: ' + FormatFileSize(fs.Size));
|
---|
| 239 | Exit;
|
---|
| 240 | end else begin
|
---|
| 241 | if MessageBox(Self.Handle,
|
---|
| 242 | PChar('File has different size from the file in the .dat.' + CrLf +
|
---|
| 243 | 'Size of file in .dat: ' + FormatFileSize(finfo.Size) + CrLf +
|
---|
| 244 | 'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf +
|
---|
| 245 | 'Replace anyway?'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then
|
---|
| 246 | begin
|
---|
| 247 | Exit;
|
---|
| 248 | end;
|
---|
| 249 | end;
|
---|
| 250 | end;
|
---|
[97] | 251 | ConManager.Connection[FConnectionID].UpdateDatFile(id, fs);
|
---|
[93] | 252 | Self.listClick(Self);
|
---|
[101] | 253 | fs.Free;
|
---|
[93] | 254 | end;
|
---|
[101] | 255 | end else begin
|
---|
| 256 | ShowMessage('Editing .dat-contents not allowed with this backend.');
|
---|
[93] | 257 | end;
|
---|
| 258 | end;
|
---|
| 259 |
|
---|
| 260 | procedure TForm_ToolTemplate.popup_opentool(Sender: TObject);
|
---|
| 261 | var
|
---|
| 262 | sender_name, context: String;
|
---|
| 263 | id: Integer;
|
---|
| 264 | begin
|
---|
| 265 | sender_name := TComponent(Sender).Name;
|
---|
[97] | 266 | id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
|
---|
[93] | 267 | context := MidStr(sender_name, Pos('_', sender_name) + 1, Length(sender_name) - Pos('_', sender_name));
|
---|
[97] | 268 | Form_Main.open_child(context, FConnectionID, id);
|
---|
[93] | 269 | end;
|
---|
| 270 |
|
---|
| 271 | procedure TForm_ToolTemplate.combo_connectionChange(Sender: TObject);
|
---|
| 272 | var
|
---|
| 273 | name: String;
|
---|
| 274 | nstart, nend: Integer;
|
---|
| 275 | i: Integer;
|
---|
| 276 | begin
|
---|
| 277 | if combo_connection.ItemIndex >= 0 then
|
---|
[97] | 278 | FConnectionID := combo_connection.ItemIndex
|
---|
| 279 | else
|
---|
| 280 | FConnectionID := -1;
|
---|
| 281 | RecreateExtList;
|
---|
| 282 | if Assigned(FOnNewConnection) then
|
---|
| 283 | FOnNewConnection(FConnectionID);
|
---|
[93] | 284 | end;
|
---|
| 285 |
|
---|
| 286 | procedure TForm_ToolTemplate.combo_extensionClick(Sender: TObject);
|
---|
| 287 | begin
|
---|
| 288 | LoadFileNames;
|
---|
| 289 | end;
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 | constructor TForm_ToolTemplate.Create(AOwner: TComponent);
|
---|
| 293 | var
|
---|
| 294 | i: Integer;
|
---|
| 295 | item: TMenuItem;
|
---|
| 296 | begin
|
---|
| 297 | inherited;
|
---|
[97] | 298 | Self.Width := 260;
|
---|
| 299 | Self.Height := 300;
|
---|
| 300 | FAllowedExts := '';
|
---|
| 301 | FAllowMultiSelect := False;
|
---|
| 302 | FOnNewFileSelected := nil;
|
---|
| 303 | FOnNewConnection := nil;
|
---|
| 304 | FOnCheckCloseable := nil;
|
---|
| 305 | FConnectionID := -1;
|
---|
| 306 | FSelectedFile.ID := -1;
|
---|
| 307 | UpdateConList;
|
---|
[93] | 308 | if Length(ToolList) > 0 then
|
---|
| 309 | begin
|
---|
| 310 | for i := 0 to High(ToolList) do
|
---|
| 311 | begin
|
---|
| 312 | item := TMenuItem.Create(filepopup);
|
---|
| 313 | item.Name := 'popup_' + ToolList[i].context;
|
---|
| 314 | item.Caption := 'Open with ' + ToolList[i].name;
|
---|
| 315 | item.OnClick := Self.popup_opentool;
|
---|
| 316 | filepopup.Items.Insert(i, item);
|
---|
| 317 | end;
|
---|
| 318 | end;
|
---|
| 319 | end;
|
---|
| 320 |
|
---|
| 321 | procedure TForm_ToolTemplate.filepopupPopup(Sender: TObject);
|
---|
| 322 | var
|
---|
| 323 | ext: String;
|
---|
| 324 | i: Integer;
|
---|
| 325 | begin
|
---|
| 326 | ext := RightStr(filelist.Items.Strings[filelist.ItemIndex], 4);
|
---|
| 327 | for i := 0 to High(ToolList) do
|
---|
| 328 | begin
|
---|
| 329 | filepopup.Items.Items[i].Enabled := True;
|
---|
| 330 | if Length(ToolList[i].exts) > 0 then
|
---|
| 331 | if Pos(ext, ToolList[i].exts) = 0 then
|
---|
| 332 | filepopup.Items.Items[i].Enabled := False;
|
---|
| 333 | end;
|
---|
| 334 | end;
|
---|
| 335 |
|
---|
| 336 | procedure TForm_ToolTemplate.check_zerobyteClick(Sender: TObject);
|
---|
| 337 | begin
|
---|
| 338 | LoadFileNames;
|
---|
| 339 | end;
|
---|
| 340 |
|
---|
| 341 | procedure TForm_ToolTemplate.btn_sortClick(Sender: TObject);
|
---|
| 342 | begin
|
---|
| 343 | if btn_sort_id_asc.Down then
|
---|
[97] | 344 | FSortBy := ST_IDAsc
|
---|
[93] | 345 | else if btn_sort_id_desc.Down then
|
---|
[97] | 346 | FSortBy := ST_IDDesc
|
---|
[93] | 347 | else if btn_sort_name_asc.Down then
|
---|
[97] | 348 | FSortBy := ST_NameAsc
|
---|
[93] | 349 | else if btn_sort_name_desc.Down then
|
---|
[97] | 350 | FSortBy := ST_NameDesc
|
---|
[93] | 351 | else if btn_sort_ext_asc.Down then
|
---|
[97] | 352 | FSortBy := ST_ExtAsc
|
---|
[93] | 353 | else if btn_sort_ext_desc.Down then
|
---|
[97] | 354 | FSortBy := ST_ExtDesc;
|
---|
[93] | 355 | LoadFileNames;
|
---|
| 356 | end;
|
---|
| 357 |
|
---|
| 358 | procedure TForm_ToolTemplate.check_filternameClick(Sender: TObject);
|
---|
| 359 | begin
|
---|
| 360 | edit_filtername.Enabled := not check_filtername.Checked;
|
---|
| 361 | LoadFileNames;
|
---|
| 362 | end;
|
---|
| 363 |
|
---|
| 364 | procedure TForm_ToolTemplate.listClick(Sender: TObject);
|
---|
| 365 | var
|
---|
| 366 | fileid: Integer;
|
---|
| 367 | begin
|
---|
| 368 | if filelist.ItemIndex > -1 then
|
---|
| 369 | begin
|
---|
[97] | 370 | fileid := ConManager.Connection[FConnectionID].ExtractFileIDOfName(
|
---|
[93] | 371 | filelist.Items.Strings[filelist.ItemIndex]);
|
---|
[97] | 372 | FSelectedFile := ConManager.Connection[FConnectionID].GetFileInfo(fileid);
|
---|
[93] | 373 | if Assigned(FOnNewFileSelected) then
|
---|
| 374 | FOnNewFileSelected(FSelectedFile);
|
---|
| 375 | end;
|
---|
| 376 | end;
|
---|
| 377 |
|
---|
| 378 | procedure TForm_ToolTemplate.listMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
| 379 | Shift: TShiftState; X, Y: Integer);
|
---|
| 380 | var
|
---|
| 381 | pt: TPoint;
|
---|
| 382 | begin
|
---|
| 383 | pt.X := x;
|
---|
| 384 | pt.Y := y;
|
---|
| 385 | // filelist.ItemIndex := filelist.ItemAtPos(pt, true);
|
---|
| 386 | // Self.listClick(Self);
|
---|
| 387 | end;
|
---|
| 388 |
|
---|
| 389 |
|
---|
| 390 |
|
---|
[97] | 391 | procedure TForm_ToolTemplate.SelectConnection(ConnectionID: Integer);
|
---|
| 392 | begin
|
---|
| 393 | if FConnectionID <> ConnectionID then
|
---|
| 394 | begin
|
---|
| 395 | combo_connection.ItemIndex := ConManager.ConnectionIndexByID[ConnectionID];
|
---|
| 396 | combo_connectionChange(Self);
|
---|
| 397 | end;
|
---|
| 398 | end;
|
---|
| 399 |
|
---|
| 400 | procedure TForm_ToolTemplate.SelectFileID(ConnectionID, FileID: Integer);
|
---|
[93] | 401 | var
|
---|
| 402 | i: Integer;
|
---|
| 403 | begin
|
---|
[97] | 404 | if FConnectionID <> ConnectionID then
|
---|
| 405 | SelectConnection(ConnectionID);
|
---|
[93] | 406 |
|
---|
| 407 | filelist.ItemIndex := -1;
|
---|
| 408 | if filelist.Items.Count > 0 then
|
---|
| 409 | for i := 0 to filelist.Items.Count - 1 do
|
---|
[97] | 410 | if ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[i]) = FileID then
|
---|
[93] | 411 | begin
|
---|
| 412 | filelist.ItemIndex := i;
|
---|
| 413 | Break;
|
---|
| 414 | end;
|
---|
| 415 | Self.listClick(Self);
|
---|
| 416 | end;
|
---|
| 417 |
|
---|
[97] | 418 | procedure TForm_ToolTemplate.SelectFileName(ConnectionID: Integer; filename: String);
|
---|
[93] | 419 | var
|
---|
| 420 | i: Integer;
|
---|
| 421 | begin
|
---|
[97] | 422 | if FConnectionID <> ConnectionID then
|
---|
| 423 | SelectConnection(ConnectionID);
|
---|
[93] | 424 |
|
---|
| 425 | filelist.ItemIndex := -1;
|
---|
| 426 | if filelist.Items.Count > 0 then
|
---|
| 427 | for i := 0 to filelist.Items.Count - 1 do
|
---|
| 428 | if filelist.Items.Strings[i] = filename then
|
---|
| 429 | filelist.ItemIndex := i;
|
---|
| 430 | Self.listClick(Self);
|
---|
| 431 | end;
|
---|
| 432 |
|
---|
| 433 | procedure TForm_ToolTemplate.SetAllowedExts(exts: String);
|
---|
| 434 | begin
|
---|
| 435 | FAllowedExts := exts;
|
---|
| 436 | RecreateExtList;
|
---|
| 437 | end;
|
---|
| 438 |
|
---|
| 439 | procedure TForm_ToolTemplate.SetFileFilters(pattern, extension: String;
|
---|
| 440 | zerobytes: Boolean);
|
---|
| 441 | var
|
---|
| 442 | i: Integer;
|
---|
| 443 | begin
|
---|
| 444 | if Length(pattern) > 0 then
|
---|
| 445 | Self.edit_filtername.Text := pattern;
|
---|
| 446 | Self.check_filtername.Checked := Length(pattern) > 0;
|
---|
| 447 | if Length(extension) > 0 then
|
---|
| 448 | begin
|
---|
| 449 | for i := 0 to Self.combo_extension.Items.Count - 1 do
|
---|
| 450 | if Pos(extension, Self.combo_extension.Items.Strings[i]) > 0 then
|
---|
| 451 | Break;
|
---|
| 452 | if i < Self.combo_extension.Items.Count then
|
---|
| 453 | Self.combo_extension.ItemIndex := i
|
---|
| 454 | else
|
---|
| 455 | Self.combo_extension.ItemIndex := -1;
|
---|
| 456 | end;
|
---|
| 457 | Self.check_zerobyte.Checked := zerobytes;
|
---|
| 458 | Self.LoadFileNames;
|
---|
| 459 | end;
|
---|
| 460 |
|
---|
| 461 | procedure TForm_ToolTemplate.SetMultiSelect(allow: Boolean);
|
---|
| 462 | begin
|
---|
| 463 | FAllowMultiSelect := allow;
|
---|
| 464 | filelist.MultiSelect := allow;
|
---|
| 465 | end;
|
---|
| 466 |
|
---|
| 467 |
|
---|
[97] | 468 | function TForm_ToolTemplate.GetToolCloseable: Boolean;
|
---|
[93] | 469 | begin
|
---|
[97] | 470 | if Assigned(FOnCheckCloseable) then
|
---|
| 471 | Result := FOnCheckCloseable
|
---|
| 472 | else
|
---|
| 473 | Result := True;
|
---|
[93] | 474 | end;
|
---|
| 475 |
|
---|
| 476 | procedure TForm_ToolTemplate.FormActivate(Sender: TObject);
|
---|
| 477 | begin
|
---|
| 478 | if edit_filtername.CanFocus then
|
---|
| 479 | edit_filtername.SetFocus
|
---|
| 480 | else
|
---|
| 481 | if content.CanFocus then
|
---|
| 482 | content.SetFocus;
|
---|
| 483 | end;
|
---|
| 484 |
|
---|
| 485 | procedure TForm_ToolTemplate.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 486 | begin
|
---|
| 487 | Action := caFree;
|
---|
| 488 | end;
|
---|
| 489 |
|
---|
| 490 |
|
---|
| 491 | procedure AddToolListEntryExt(context, ext: String);
|
---|
| 492 | var
|
---|
| 493 | i: Integer;
|
---|
| 494 | begin
|
---|
| 495 | for i := 0 to High(ToolList) do
|
---|
| 496 | if ToolList[i].context = context then
|
---|
| 497 | begin
|
---|
| 498 | if Pos(ext, ToolList[i].exts) = 0 then
|
---|
| 499 | begin
|
---|
| 500 | if Length(ToolList[i].exts) = 0 then
|
---|
| 501 | ToolList[i].exts := ext
|
---|
| 502 | else
|
---|
| 503 | ToolList[i].exts := ToolList[i].exts + ',' + ext;
|
---|
| 504 | end;
|
---|
| 505 | Exit;
|
---|
| 506 | end;
|
---|
| 507 | end;
|
---|
| 508 |
|
---|
| 509 | procedure AddToolListEntry(context, name, exts: String);
|
---|
| 510 | var
|
---|
| 511 | i: Integer;
|
---|
| 512 | begin
|
---|
| 513 | if Length(ToolList) > 0 then
|
---|
| 514 | begin
|
---|
| 515 | for i := 0 to High(ToolList) do
|
---|
| 516 | if ToolList[i].context = context then
|
---|
| 517 | begin
|
---|
| 518 | if (Length(ToolList[i].name) = 0) and (Length(name) > 0) then
|
---|
| 519 | ToolList[i].name := name;
|
---|
| 520 | if Length(exts) > 0 then
|
---|
| 521 | AddToolListEntryExt(context, exts);
|
---|
| 522 | Exit;
|
---|
| 523 | end;
|
---|
| 524 | end;
|
---|
| 525 | SetLength(ToolList, Length(ToolList) + 1);
|
---|
| 526 | for i := High(ToolList) downto 1 do
|
---|
| 527 | if ToolList[i - 1].name > name then
|
---|
| 528 | ToolList[i] := ToolList[i - 1]
|
---|
| 529 | else
|
---|
| 530 | Break;
|
---|
| 531 | ToolList[i].context := context;
|
---|
| 532 | ToolList[i].name := name;
|
---|
| 533 | ToolList[i].exts := exts;
|
---|
| 534 | end;
|
---|
| 535 |
|
---|
| 536 | end.
|
---|