# ToolbarItem
Class
## About
`ToolbarItem` describes one visual and interactive toolbar entry. It can represent a button, toggle, menu, or spacer. The same class is used by the main toolbar and node popover toolbars.
## Enumerations
| Name | Value | Description |
| --- | :---: | --- |
| Kinds | Button = 0 <br > Toggle = 1 <br > Menu = 2 <br > Spacer = 3 <br > FlexibleSpace = 4 | (None) |
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| Constructor | identifier As String <br> caption As String <br> kind As Kinds = Kinds.Button | (None) | Creates a new toolbar item instance initialized from the supplied values. |
| ResetCustomization | (None) | (None) | Lets the editor manage Tooltip, Visible, Width, IconWidth, and IconHeight again after the application changed them, as it does for a built-in item that was never changed. |
| SetAdaptiveIcon | svg As String | (None) | Sets the icon from SVG source whose currentColor is drawn black in light mode and white in dark mode, redrawn when the appearance changes. An empty string removes the icon. Assigning Icon replaces it. |
## Properties
| Name | Type | Default Value | Description |
| --- | :---: | :---: | --- |
| Attributes | ContextEnabled | Boolean | (None) |
| Caption | String | (None) | Gets or sets the user-visible caption text. |
| Enabled | Boolean | True | Gets or sets whether this toolbar item can be activated. |
| Icon | Picture | (None) | Gets or sets the picture drawn for this toolbar item. |
| IconHeight | Double | (None) | Gets or sets the requested toolbar icon height. |
| IconWidth | Double | (None) | Gets or sets the requested toolbar icon width. |
| Identifier | String | (None) | Gets or sets the stable identifier used to locate this object. |
| Kind | Kinds | (None) | Gets or sets the toolbar item's interaction kind. |
| Menu | DesktopMenuItem | (None) | Gets or sets the native menu displayed by this toolbar item. |
| Owner | Editor | (None) | Gets or sets the editor that owns this toolbar object. |
| Picker | GraffitiProEditor.Picker | (None) | Gets or sets the picker opened by this item. When it is set, pressing the item opens the picker instead of Menu, and the chosen value arrives as the Tag of the selected DesktopMenuItem. |
| RecordsUndo | Boolean | True | Gets or sets whether activating this toolbar item records an undo state. |
| Toggled | Boolean | (None) | Gets or sets whether this toggle toolbar item is active. |
| Tooltip | String | (None) | Gets or sets the native tooltip displayed for this toolbar item. |
| Visible | Boolean | (None) | Gets or sets whether this toolbar item is visible. |
| Width | Double | (None) | Gets or sets the toolbar item's requested width. |
## Notes
Item properties remain editable after the item has been added to a toolbar section.
### Custom Actions
An item owned by a node is normally handled by that node. An application-defined item that is not associated with a node raises `Editor.ToolbarItemPressed`, passing both the item and any selected native menu item.
`RecordsUndo` should be `True` only when the action mutates editor content. Set it to `False` for commands such as previewing, printing, or opening an external application window.
### Kinds and Behavior
Buttons perform one action. Toggles display `Toggled` state. Menus use a native `DesktopMenuItem` hierarchy and display a disclosure indicator. A main-toolbar menu item whose `Menu` is `Nil` still displays the indicator, but pressing it raises `ToolbarItemPressed` with a `Nil` selection, so the application can open its own popup, such as `Editor.ShowInsertionChooser`. An item whose `Picker` is set opens that picker instead of `Menu`, in the main toolbar and in node popover toolbars, and receives the chosen value as the `Tag` of the selected `DesktopMenuItem`; give it the Menu kind to show the disclosure indicator. Spacers contribute separation rather than an action and use their configurable width. A `FlexibleSpace` item, used by the contextual toolbar, takes an equal share of the width left over in its row, pushing the items after it to the trailing edge.
Set `Icon` to a `Picture` containing the complete icon. The editor only scales that picture into the standard icon bounds; node subclasses are responsible for constructing their own icons. `Tooltip` supplies the native control tooltip.
For an icon that follows the system appearance, call `SetAdaptiveIcon` with SVG source instead. Its `currentColor` is drawn black in light mode and white in dark mode, and the picture is redrawn when the appearance changes. The built-in toolbar icons are drawn this way, from the 24-point Tabler Icons set. Assigning `Icon` afterwards replaces the SVG icon.
```xojo
Var saveItem As New GraffitiProEditor.ToolbarItem("save", "Save")
saveItem.Tooltip = "Save the Document"
saveItem.SetAdaptiveIcon("")
saveItem.RecordsUndo = False
```
## Examples
Application actions are handled through the editor's `ToolbarItemPressed` event.
### Application Action
```xojo
Var previewItem As New GraffitiProEditor.ToolbarItem("preview", "Preview")
previewItem.Icon = previewIcon
previewItem.Tooltip = "Preview HTML"
previewItem.RecordsUndo = False
Editor.Toolbar.Section(GraffitiProEditor.ToolbarSection.Types.Nodes).Add(previewItem)
```
Handle the editor's `ToolbarItemPressed` event and compare `item.Identifier` with `"preview"`.
```xojo
Sub ToolbarItemPressed(item As GraffitiProEditor.ToolbarItem, selectedItem As DesktopMenuItem)
#Pragma Unused selectedItem
If item.Identifier <> "preview" Then Return
Var preview As New HTMLPreviewWindow(Editor.ToHTML(True))
preview.Show
End Sub
```