Question
“How do I add a custom button to the preview toolbar?”
Solution
Create a Preview Plugin that overrides the CreateToolbarItems routine. Use the Toolbar.AddButton routine to add a new button to the toolbar before the default buttons are created. Take a look at the TppPreview.CreateToolbarItems routine located in the ppPreview.pas file for examples of how the existing buttons are created.
Download: AddButtonToPreview.zip
Sample Delphi code:
uses
ppPreview,
ppTBX,
ppToolResources,
Dialogs;
type
TmyPreview = class(TppPreview)
private
FNewButton: TppTBXItem;
protected
procedure CreateToolbarItems; override;
public
procedure ehFilebutton_Click(Sender: TObject);
property NewButton: TppTBXItem read FFileButton;
end;
implementation
{------------------------------------------------------------------------------}
{ TmyPreview.CreateToolbarItems}
procedure TmyPreview.CreateToolbarItems;
begin
Toolbar.BeginUpdate;
FNewButton := Toolbar.AddButton();
//FNewButton.Images := //Add image list here
FNewButton.ImageIndex := ToolImageList.AddTool('PPNEW'); //Index of image in ImageList
FNewButton.OnClick := ehFilebutton_Click;
Toolbar.EndUpdate;
inherited;
end;
procedure TmyPreview.ehFilebutton_Click(Sender: TObject);
begin
ShowMessage('New Button');
end;
{******************************************************************************
*
** I N I T I A L I Z A T I O N / F I N A L I Z A T I O N
*
{******************************************************************************}
initialization
TppPreviewPlugIn.Register(TmyPreview);
finalization
TppPreviewPlugIn.UnRegister(TmyPreview);
end.