> ## Documentation Index
> Fetch the complete documentation index at: https://klyx.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Toolbar

> Add custom toolbar actions to Klyx

Extensions can add actions to Klyx's toolbar. Each action has an ID, label, icon, category, priority, and click handler.

## ToolbarRegistry

Register toolbar actions during `onLoad()`.

### Register an action

```kotlin theme={null}
toolbar.register(
    this,
    ToolbarAction(
        id = "myext.action",
        label = "My Action",
        icon = ToolbarIcon.Resource("myaction.png"),
        category = ToolbarCategory("My Plugin"),
        priority = 100,
        onClick = { /* handle action */ }
    )
)
```

### Unregister an action

```kotlin theme={null}
toolbar.unregister("myext.action")
```

### List all actions

```kotlin theme={null}
val allActions: List<ToolbarAction> = toolbar.actions()
```

## ToolbarAction fields

| Field      | Type              | Description                 |
| ---------- | ----------------- | --------------------------- |
| `id`       | `String`          | Unique action identifier    |
| `label`    | `String`          | Display text                |
| `icon`     | `ToolbarIcon?`    | Optional icon               |
| `category` | `ToolbarCategory` | Grouping category           |
| `priority` | `Int`             | Sort order (higher = first) |
| `onClick`  | `() -> Unit`      | Click handler               |

## ToolbarIcon

| Option                                 | Description                                              |
| -------------------------------------- | -------------------------------------------------------- |
| `ToolbarIcon.Resource(path)`           | Icon bundled inside the plugin. Example: `icons/git.svg` |
| `ToolbarIcon.File(file)`               | Load from a custom file                                  |
| `ToolbarIcon.Painter(painter)`         | Compose Painter instance                                 |
| `ToolbarIcon.ImageVector(imageVector)` | Compose ImageVector                                      |

## ToolbarCategory

Pre-defined categories in the companion object:

| Category                      | Description             |
| ----------------------------- | ----------------------- |
| `ToolbarCategory.CurrentFile` | Current file operations |
| `ToolbarCategory.Workspace`   | Workspace operations    |
| `ToolbarCategory.Run`         | Run/execute actions     |
| `ToolbarCategory.Tools`       | Tool actions            |
| `ToolbarCategory.Plugins`     | Plugin actions          |

Custom categories are also supported:

```kotlin theme={null}
ToolbarCategory("My Plugin")
```
