YOUSEFUL / DELPHI / COMPONENTS

TAtlasNavigation

List box whose items are actions: selecting an item executes its action.

Visual control Palette: Atlas Unit Atlas.Layout · Inherits TListBox · Product Atlas VCL

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

MemberKindWhat it does
CreateconstructorCreates an empty navigation list with ItemHeight = 32.
DestroydestructorFrees the action list; the actions themselves are not freed.
AddActionmethodAppends an item with the action's caption.
RefreshActionsmethodCalls 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.

pascal
Navigation.AddAction(Action);

RefreshActions method

procedure RefreshActions;

Calls Update on every action and copies its current caption into the matching item.

pascal
Action.Caption := 'Inbox (3)';
Navigation.RefreshActions;

Examples

Navigation list from actions

Parents the list first, then adds one item per action.

pascal
uses System.Classes, Vcl.Controls, Vcl.ActnList, Atlas.Layout;

function AddNavigation(Owner: TComponent; Parent: TWinControl; const Actions: array of TAction): TAtlasNavigation;
var
  Action: TAction;
begin
  Result := TAtlasNavigation.Create(Owner);
  Result.Parent := Parent; // before AddAction: the list box needs a window
  Result.Align := alClient;
  for Action in Actions do
    Result.AddAction(Action);
end;

Show a count in an item

Items copy the action caption only when asked.

pascal
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;

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