DesignerHost class
One tab of a designer, as the IDE gives it to the designer in Designer.OnAttached. Through it the designer draws the tab’s page, names the tab, fills the TOOLBOX, and gives the IDE the file’s new bytes.
Private Site As DesignerHost
Private Sub Designer_OnAttached(ByVal DesignerHost As DesignerHost)
Set Site = DesignerHost
Site.ApplyCss "#title { padding: 6px; background: var(--themeAddinPanelBackColor, #2b2e40); }"
Site.RootDomElement.ChildDomElements.Add("title", "div").Properties.innerText = Site.GetURI
End Sub
The page of the tab is HTML, as a ToolWindow’s is, and the same HtmlElement members build it, the custom-widget tags such as the datasheet included.
Properties
Caption
The text of the tab. String. The IDE names the tab after the file; set Caption to name it otherwise.
Syntax: host.Caption [ = value ]
IconData
The icon of the tab, as the text of an SVG picture that starts with <svg. Variant.
Syntax: host.IconData [ = value ]
RootDomElement
The element that holds the tab’s page. As HtmlElement, read-only. The default member. The page is a shadow root of its own: the IDE’s style sheets do not reach it, and ApplyCss styles it.
Toolbox
The designer’s tools in the IDE’s TOOLBOX. As DesignerToolbox, read-only.
Tooltip
The text shown when the pointer rests on the tab. String.
Syntax: host.Tooltip [ = value ]
Methods
ApplyCss
Adds a style sheet to the tab’s page.
Syntax: host.ApplyCss styles
- styles
- required The CSS. String. The theme’s colours for addins are there as variables, and follow a change of the IDE’s theme.
GetURI
The path of the tab’s file in the project, such as "/MyProject/Sources/Data.bin". String. It has no twinbasic: in front: put that in front of it for FileSystem.ResolvePath. A designer opened with Editors.Open, for no file, gets an empty string.
Syntax: host.GetURI As String
SetFileData
Gives the IDE the file’s new bytes.
Syntax: host.SetFileData bytes
- bytes
- required The whole file. Byte(), passed ByRef. For an empty file, Sample 24 passes an array with no elements, made with
SafeArrayCreateVector, rather than an erased one, which its comments say the IDE does not take.
The IDE keeps the bytes as the tab’s contents, and the tab is marked as changed. The file on disk changes only when the project or the tab is saved; then the designer’s OnSaveCompleted runs. SetFileData calls no OnFileDataChanged.
Call it at each change, as Samples 24, 25 and 27 do, so that a save writes what the user sees and a restart of the compiler gives the designer its unsaved bytes back.
Note BETA 1045
When SetFileData gives back the bytes the file was saved with, the IDE takes the tab as unchanged, and closing it asks nothing, but the tab’s changed mark stays until the next save.
See Also
- Designer class
- DesignerToolbox class
- ToolWindow class – the same page, in a window of its own