# Host class
{: .no_toc }

The root API the IDE passes to every addin. The DLL receives a **Host** as the argument to its [`tbCreateCompilerAddin`](/tB/Packages/tbIDE/index.md#building-and-loading-an-addin) factory; the addin retains that reference for its lifetime and reaches every other capability through it --- the currently-loaded [**CurrentProject**](#currentproject), the [**ActiveEditors**](#activeeditors), the [**Toolbars**](#toolbars) for adding buttons, the [**Menus**](#menus) for adding commands, the [**Designers**](#designers) for adding an editor for a kind of file, the [**ProjectExplorer**](#projectexplorer), the [**ToolWindows**](#toolwindows) for adding HTML-rendered panels, the [**DebugConsole**](#debugconsole) for log output, the virtual [**FileSystem**](#filesystem), the [**KeyboardShortcuts**](#keyboardshortcuts) registry, the [**Themes**](#themes) state, plus the dialog helpers [**ShowMessageBox**](#showmessagebox) / [**ShowNotification**](#shownotification).

Typically held via `WithEvents` so the addin can subscribe to lifecycle events:

```tb check_build
Private WithEvents Host As Host

Public Sub New(ByVal Host As Host)
    Set Me.Host = Host
End Sub

Private Sub Host_OnProjectLoaded()
    With Host.Toolbars(0)
        .AddSplitter
        Set MyButton = .AddButton("MyButton", "My Action")
    End With
End Sub
```

Almost every meaningful addin builds its toolbar buttons and tool windows inside the [**OnProjectLoaded**](#onprojectloaded) handler --- that is the first moment the IDE is fully ready to accept extensibility commands.

* TOC
{:toc}

## Properties

### ActiveEditors
{: .no_toc }

The collection of editors currently open in the IDE. `Host.ActiveEditors(0)` returns the active one --- at present the IDE exposes exactly one active editor at a time and `Host.ActiveEditors.Count` is **1** when an editor is open, **0** when none is. **As** [**Editors**](/tB/Packages/tbIDE/Editors.md). Read-only.

### CompilerVersion
{: .no_toc }

The full compiler-version string of the running IDE, such as `"0.15.1045"`. **String**, read-only. Its third number is the number of the BETA, so an addin can refuse an IDE that is too old for it; see [**UnsupportedHostAddin**](/tB/Packages/tbIDE/UnsupportedHostAddin.md).

### CurrentProject
{: .no_toc }

The currently-loaded project. Provides project name and path, lifecycle methods (Save / Close / Build / Clean), the project's [**RootFolder**](/tB/Packages/tbIDE/Project.md#rootfolder) into the virtual file system, expression evaluation against the running project context, and persistent meta-data storage inside the `.twinproj` file. **As** [**Project**](/tB/Packages/tbIDE/Project.md). Read-only.

### DebugConsole
{: .no_toc }

The IDE's DEBUG CONSOLE pane. Print, clear, or set focus. **As** [**DebugConsole**](/tB/Packages/tbIDE/DebugConsole.md). Read-only.

### Designers
{: .no_toc }

The registry of designers: editors that an addin supplies for a kind of file, shown in a tab of their own. Call [**Designers.Register**](/tB/Packages/tbIDE/Designers.md#register) to add one. **As** [**Designers**](/tB/Packages/tbIDE/Designers.md). Read-only.

### FileSystem
{: .no_toc }

The IDE's virtual file system --- the abstraction that lets the addin traverse and read source files without touching the on-disk paths. **As** [**FileSystem**](/tB/Packages/tbIDE/FileSystem.md). Read-only.

### IDEProcessID
{: .no_toc }

The OS process ID of the running IDE process. **Long**, read-only. Useful for inter-process scenarios --- e.g. an external helper EXE that needs to know which IDE invoked it.

### IDEWindowHandle
{: .no_toc }

The Win32 `HWND` of the IDE's main window. **LongPtr**, read-only. Pass to Win32 APIs that need a window owner, or use as the parent handle when displaying owned modal dialogs from the addin.

### KeyboardShortcuts
{: .no_toc }

The keyboard-shortcut registry. Call [**KeyboardShortcuts.Add**](/tB/Packages/tbIDE/KeyboardShortcuts.md#add) to bind a key combination to a callback. **As** [**KeyboardShortcuts**](/tB/Packages/tbIDE/KeyboardShortcuts.md). Read-only.

### Menus
{: .no_toc }

The IDE's menus, for adding commands to them or a menu of the addin's own. **As** [**Menus**](/tB/Packages/tbIDE/Menus.md). Read-only.

### ProjectExplorer
{: .no_toc }

The **Project Explorer** panel: the item selected in it, and a new file made through it. **As** [**ProjectExplorer**](/tB/Packages/tbIDE/ProjectExplorer.md). Read-only.

### Themes
{: .no_toc }

The IDE's theme state. Exposes the active theme name and group; pair with the [**OnChangedTheme**](#onchangedtheme) event to react to user theme changes. **As** [**Themes**](/tB/Packages/tbIDE/Themes.md). Read-only.

### Toolbars
{: .no_toc }

The collection of IDE toolbars. Currently a one-element collection --- `Host.Toolbars(0)` is the only available toolbar. **As** [**Toolbars**](/tB/Packages/tbIDE/Toolbars.md). Read-only.

### ToolWindows
{: .no_toc }

Factory for HTML-rendered tool windows. Call [**ToolWindows.Add**](/tB/Packages/tbIDE/ToolWindows.md#add) to create one. **As** [**ToolWindows**](/tB/Packages/tbIDE/ToolWindows.md). Read-only.

## Methods

### ShowMessageBox
{: .no_toc }

Displays a modal IDE-styled dialog with a customisable button strip. Returns the zero-based index of the pressed button, or `-1` if the dialog was closed without picking one.

Syntax: *host*.**ShowMessageBox**( *Prompt*, *Buttons*, *Title* ) **As Long**

*Prompt*
: *required* The message to display. **String**.

*Buttons*
: *required* A **String** of button captions separated by `|`. E.g. `"OK"` for a single OK button, `"Yes|No|Cancel"` for three buttons.

*Title*
: *required* The dialog's title-bar text. **String**.

```tb check_build
Select Case Host.ShowMessageBox("Save changes before closing?", _
                                 "Save|Discard|Cancel", "Confirm")
    Case 0: ' Save
    Case 1: ' Discard
    Case 2, -1: ' Cancel or closed
End Select
```

### ShowNotification
{: .no_toc }

Displays a non-modal, discreet notification pop-up in the IDE --- a toast-style transient message that does not require the user to react.

Syntax: *host*.**ShowNotification** *Prompt*

*Prompt*
: *required* The notification text. **String**.

[**ShowMessageBox**](#showmessagebox) is for when the user has to answer something; **ShowNotification** is for "the user should know but doesn't have to react".

## Events

The **Host** CoClass exposes three events. The last two, [**OnChangedActiveEditor**](#onchangedactiveeditor) and [**OnChangedTheme**](#onchangedtheme), were each added in a later revision of the events interface, and are tagged with the compile-time [`[AllowUnpopulatedVtableEntry]`](/tB/Core/Attributes.md#allowunpopulatedvtableentry) attribute, so that an addin that implements only the first revision's members still satisfies the current one.

### OnProjectLoaded
{: .no_toc }

Fires once the IDE has finished loading the project and is ready to accept extensibility commands. The canonical place to set up toolbar buttons, open tool windows that should be visible by default, register keyboard shortcuts, and log the start-up state to the [**DebugConsole**](/tB/Packages/tbIDE/DebugConsole.md).

Syntax: *host*_**OnProjectLoaded**()

```tb check_build
Private Sub Host_OnProjectLoaded()
    With Host.Toolbars(0)
        .AddSplitter
        Set MyButton = .AddButton("MyButton", "My Action")
    End With
End Sub
```

### OnChangedActiveEditor
{: .no_toc }

Fires when the user switches the focused editor. The event is the right hook for refreshing any addin UI that depends on the current editor (e.g. a context-aware tool window).

Syntax: *host*_**OnChangedActiveEditor**(*EditorIdx* **As Long**, *Editor* **As** [**Editor**](/tB/Packages/tbIDE/Editor.md))

*EditorIdx*
: The zero-based index of the newly active editor in the [**ActiveEditors**](#activeeditors) collection.

*Editor*
: The newly active editor object. Castable to [**CodeEditor**](/tB/Packages/tbIDE/CodeEditor.md) for code panes --- see [Editor castability](/tB/Packages/tbIDE/Editor.md#castability).

### OnChangedTheme
{: .no_toc }

Fires when the user changes the IDE theme. Pair with [**Themes.ActiveThemeName**](/tB/Packages/tbIDE/Themes.md#activethemename) / [**Themes.ActiveThemeNameGroup**](/tB/Packages/tbIDE/Themes.md#activethemenamegroup) to refresh any colour-sensitive elements the addin draws inside its tool windows.

Syntax: *host*_**OnChangedTheme**(*ThemeName* **As String**)

*ThemeName*
: The new theme's name --- same value the user now sees in [**Themes.ActiveThemeName**](/tB/Packages/tbIDE/Themes.md#activethemename) (e.g. `"Classic"`, `"Dark"`, `"Light"`).

## DebuggerEvaluateOptions
{: #debuggerevaluateoptions }

A flags enum declared inline on the **Host** interface; consumed by [**Project.Evaluate**](/tB/Packages/tbIDE/Project.md#evaluate) (and any future debugger-evaluation API). Currently a single-value placeholder --- additional flags may appear in later IDE versions.

| Constant | Value | Description |
|----------|-------|-------------|
| **NONE**{: #DebuggerEvaluateOptions_NONE } | 0 | No special evaluation options. |
