YOUSEFUL / DELPHI / COMPONENTS
TAtlasNavigation
List box whose items are actions: selecting an item executes its action.
Description
TAtlasNavigation is a TListBox that keeps a list of actions parallel to its items. AddAction appends the action's caption; when the selection changes (mouse or arrow keys, because the list box raises Click on every selection change) the selected action is updated and, if enabled, executed. Setting ItemIndex from code selects an item without executing it. An action that is destroyed is removed with its item.
Items do not follow the actions on their own: call RefreshActions after changing captions. A disabled action's item looks the same as the others but does nothing. Do not add, delete or sort Items directly (Sorted included), or items and actions no longer match. The constructor sets ItemHeight to 32, which takes effect only with an owner-draw Style such as lbOwnerDrawFixed. Parent the control before adding actions. Not implemented: icons, groups and collapsible sections.
Members
| Member | Kind | What it does |
|---|---|---|
Create | constructor | Creates an empty navigation list with ItemHeight = 32. |
Destroy | destructor | Frees the action list; the actions themselves are not freed. |
AddAction | method | Appends an item with the action's caption. |
RefreshActions | method | Calls Update on every action and copies its current caption into the matching item. |
Constructors
Create constructor
constructor Create(AOwner: TComponent); override;Creates an empty navigation list with ItemHeight = 32.
Destructors
Destroy destructor
destructor Destroy; override;Frees the action list; the actions themselves are not freed.
Methods
AddAction method
procedure AddAction(Action: TCustomAction);Appends an item with the action's caption. Raises EAtlasLayoutError when Action is nil. The list box needs a window, so set Parent first; otherwise the VCL raises EInvalidOperation (has no parent window). The same action may be added more than once.
Navigation.AddAction(Action);RefreshActions method
procedure RefreshActions;Calls Update on every action and copies its current caption into the matching item.
Action.Caption := 'Inbox (3)';
Navigation.RefreshActions;Examples
Show a count in an item
Items copy the action caption only when asked.
uses System.SysUtils, Vcl.ActnList, Atlas.Layout;
procedure ShowUnread(Navigation: TAtlasNavigation; InboxAction: TAction; Unread: Integer);
begin
if Unread > 0 then
InboxAction.Caption := 'Inbox (' + IntToStr(Unread) + ')'
else
InboxAction.Caption := 'Inbox';
Navigation.RefreshActions;
end;
Related
TAtlasCommandBar · TAtlasTileBoard · TAtlasWorkspace
Also in Atlas VCL
TAtlasTable · TAtlasGrid · TAtlasValueEdit · TAtlasTree · TAtlasWorkbook · TAtlasSheetGrid · TAtlasPivot · TAtlasInspector · TAtlasRichEdit · TAtlasSpellChecker · TAtlasChart · TAtlasGauge · TAtlasThemer · TAtlasWizard · TAtlasWorkspace · TAtlasCommandBar · TAtlasActionTile · TAtlasTileBoard · TAtlasMap · TAtlasGraph · TAtlasDiagram · TAtlasPrintDocument · TAtlasSchedule · TAtlasScheduler · TAtlasTaskPlan · TAtlasGantt · TAtlasPdfDocument · TAtlasPdfViewer