ShellBrowser Delphi Components Documentation
ContentsIndexHome
PreviousUpNext
JamFilePreview.TJamFilePreview.OnLoadPreview

Occurs before the preview handler is loaded for the given file

Syntax
Pascal
property OnLoadPreview: TJamFilePreviewLoadPreviewEvent;

Use this event to control the PreviewHandler that is used to show the given file and to determine if a thumbnail of the file is acceptable. See TJamFilePreviewLoadPreviewEventArgs for details

type
  TAnimatedImagePreviewHandler = class(TInterfacedObject, ICustomPreviewHandler)
  private
    fImage: TSkAnimatedImage;
  strict protected
    procedure Resize;
    procedure Unload;
    function Load(sender: TJamFilePreview; const pPath: string): Boolean;
  end;

{ TAnimatedImagePreviewHandler }

function TAnimatedImagePreviewHandler.Load(sender: TJamFilePreview;
  const pPath: string): Boolean;
begin
  fImage := TSkAnimatedImage.Create(sender);
  fImage.Parent := sender;
  fImage.Align := alClient;
  fImage.LoadFromFile(pPath);
  exit(true);
end;

procedure TAnimatedImagePreviewHandler.Resize;
begin
//alClient
end;

procedure TAnimatedImagePreviewHandler.Unload;
begin
  fImage.Visible := false;
  fImage.Parent := nil;
  FreeAndNil(fImage);
end;

procedure TMainForm.JamFilePreview1LoadPreview(Sender: TObject; eventArgs: TJamFilePreviewLoadPreviewEventArgs);
begin
  // This example shows how to use the HTML preview handler for files with the extensions CSM:
  if LowerCase(ExtractFileExt(eventArgs.Path)) = '.csm' then
      eventArgs.PreviewHandlerGuid := StringToGUID('{F8B8412B-DEA3-4130-B36C-5E8BE73106AC}');

  // The following example checks the PreviewHandler that will be used, and forces the loading and unloading of such previews
  // to the GUI thread. Doing so can be a workaround for rare cases where an external previewhandler has problems when
  // being executed to a non-gui thread.

  if (eventArgs.PreviewHandlerGuid = TShellPreviewHandlerGuids.Excel) then
    eventArgs.ForceGUIThread := true;

  // The following lines of code will force the loading of thumbnails for pdf files instead of using a preview handler.
  if LowerCase(ExtractFileExt(eventArgs.Path)) = '.pdf' then
    eventArgs.LoadThumbnail := true;

  // disable the Previewhandler for .eml and .jer files, since it displays a message to download the file.
  if (UpperCase(ExtractFileExt(eventArgs.Path)) = '.EML') or
      (UpperCase(ExtractFileExt(eventArgs.Path)) = '.JER')
  then
    eventArgs.PreviewHandlerGuid := TGuid.Empty;

  //the following uses a custom preview handler to view animated images with extension .WEBP. It uses a TSkAnimatedImage to show the file.
  if (Uppercase(ExtractFileExt(eventArgs.Path)) = '.WEBP') then begin
    eventArgs.CustomPreviewHandler := TAnimatedImagePreviewHandler.Create();
end;