Action toolbars
The clipboard, insert and file I/O toolbars expose document actions rather than
formatting. Like the formatting bars they bind through Control and carry an
Options set, but their events are the focus: clipboard actions usually run
against the editor automatically, while insert and file I/O actions typically
need your application to supply the image, link target, or file name.
Clipboard toolbar
TTMSFNCClipboardToolBar.Options is a set of TTMSFNCClipboardToolBarOption
values (etoCut, etoCopy, etoPaste, etoUndo, etoRedo). The matching
OnCut, OnCopy, OnPaste, OnUndo and OnRedo events fire after the action
runs against the connected editor.
// A clipboard toolbar: cut, copy, paste, undo and redo. Limit the visible
// buttons with Options and react with the per-action events.
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCClipboardToolBar1.Control := TMSFNCRichEditor1;
TMSFNCClipboardToolBar1.Options := [etoCut, etoCopy, etoPaste, etoUndo, etoRedo];
end;
procedure TForm1.TMSFNCClipboardToolBar1Paste(Sender: TObject);
begin
StatusBar1.Panels.Items[0].Text := 'Pasted from clipboard';
end;
Insert toolbar
TTMSFNCInsertToolBar.Options is a set of TTMSFNCInsertToolBarOption values
(ftiImage, ftiHyperlink). Handle OnInsertBitmap and OnInsertHyperlink to
present your own file or link dialog, since the toolbar cannot know the source.
// An insert toolbar: image and hyperlink buttons. These actions typically need
// the application to supply the file name or URL, so handle their events.
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCInsertToolBar1.Control := TMSFNCRichEditor1;
TMSFNCInsertToolBar1.Options := [ftiImage, ftiHyperlink];
end;
procedure TForm1.TMSFNCInsertToolBar1InsertHyperlink(Sender: TObject);
begin
// Show your own dialog and insert the link into the bound editor.
ShowMessage('Insert hyperlink');
end;
procedure TForm1.TMSFNCInsertToolBar1InsertBitmap(Sender: TObject);
begin
ShowMessage('Insert image');
end;
File I/O toolbar
TTMSFNCFileIOToolBar.Options is a set of TTMSFNCFileIOToolBarOption values
(itoOpenFile, itoSaveFile). Handle OnOpenFile and OnSaveFile to choose a
path or run your own open/save flow.
// A file I/O toolbar: open and save buttons for the bound editor's document.
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCFileIOToolBar1.Control := TMSFNCRichEditor1;
TMSFNCFileIOToolBar1.Options := [itoOpenFile, itoSaveFile];
end;
procedure TForm1.TMSFNCFileIOToolBar1OpenFile(Sender: TObject);
begin
StatusBar1.Panels.Items[0].Text := 'Document opened';
end;
procedure TForm1.TMSFNCFileIOToolBar1SaveFile(Sender: TObject);
begin
StatusBar1.Panels.Items[0].Text := 'Document saved';
end;
Combining the action toolbars
Putting it together — clipboard, insert and file I/O bars on one editor, each
with its own Options, forming a complete action strip:
// Clipboard, insert and file I/O toolbars sharing a single editor. Each keeps
// its own Options so the three bars together form a complete action strip.
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCClipboardToolBar1.Control := TMSFNCRichEditor1;
TMSFNCInsertToolBar1.Control := TMSFNCRichEditor1;
TMSFNCFileIOToolBar1.Control := TMSFNCRichEditor1;
TMSFNCClipboardToolBar1.Options := [etoCut, etoCopy, etoPaste, etoUndo, etoRedo];
TMSFNCInsertToolBar1.Options := [ftiImage, ftiHyperlink];
TMSFNCFileIOToolBar1.Options := [itoOpenFile, itoSaveFile];
end;
procedure TForm1.TMSFNCInsertToolBar1InsertHyperlink(Sender: TObject);
begin
ShowMessage('Insert hyperlink');
end;
procedure TForm1.TMSFNCFileIOToolBar1SaveFile(Sender: TObject);
begin
StatusBar1.Panels.Items[0].Text := 'Saved';
end;
Common mistakes
- Expecting insert/file actions to work without an event handler. The toolbar
raises
OnInsertBitmap/OnOpenFileetc.; your code supplies the data. - Leaving undo/redo enabled on a control that does not support them. Trim the
clipboard
Optionsto the actions the bound editor actually offers.