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