Designer class

The interface an addin implements for one tab of its designer. Its DesignerFactory makes one for each tab, and the IDE calls its methods as the tab opens, gets the file’s bytes, becomes active or not, is saved and closes. Every method is the IDE telling the designer something: none returns a value.

Private Class NotesDesigner
    Implements Designer
    Private Site As DesignerHost
    Private Box As HtmlElement

    Private Sub Designer_OnAttached(ByVal DesignerHost As DesignerHost)
        Set Site = DesignerHost
        Set Box = Site.RootDomElement.ChildDomElements.Add("box", "textarea")
        Box.Properties.style.width = "100%"
        Box.Properties.style.height = "100%"
        Box.AddEventListener("input", AddressOf BoxChanged)
    End Sub

    Private Sub Designer_OnFileDataChanged(ByRef byteData() As Byte)
        Box.Properties.value = StrConv(byteData, vbUnicode)
    End Sub

    Private Sub BoxChanged(ByVal e As HtmlEventProperties)
        Dim bytes() As Byte = StrConv(CStr(Box.Properties.value), vbFromUnicode)
        Site.SetFileData bytes
    End Sub

    Private Sub Designer_OnActivated(): End Sub
    Private Sub Designer_OnDeactivated(): End Sub
    Private Sub Designer_OnSaveCompleted(): End Sub
    Private Sub Designer_OnClosing(): End Sub
    Private Sub Designer_OnClosed(): End Sub
End Class

The designer keeps the DesignerHost it is given, builds its page in the host’s RootDomElement, shows the bytes it is given, and gives the IDE the new bytes with SetFileData at each change.

The order of the calls

When The calls
A file opens in the designer DesignerFactory.CreateDesigner, OnAttached, OnActivated, OnFileDataChanged. When another designer’s tab was the active one, its OnDeactivated comes between OnAttached and OnActivated.
Another tab is chosen, and then this one again OnDeactivated; later OnActivated.
The project is saved, or the tab with Ctrl+S OnSaveCompleted.
A tab with no changes is closed OnClosing, OnDeactivated, OnClosed.
A tab with changes is closed, and the user answers Discard Changes OnClosing, OnDeactivated, OnClosed. The file keeps the bytes it was saved with.
A tab with changes is closed, and the user answers Save OnDeactivated, OnClosed, then OnSaveCompleted. There is no OnClosing.
The compiler restarts The designer is gone with the compiler. The addin is loaded again, and for each tab of its designers the IDE calls CreateDesigner, OnAttached and OnFileDataChanged, with the tab’s bytes, the changes not saved yet included. There is no OnActivated, though the tab may be the active one.

OnActivated comes before the first OnFileDataChanged, so a designer has to be ready for it with no data yet.

Methods

OnActivated

The tab has become the active editor.

Syntax: designer.OnActivated()

OnAttached

The tab has been made, and DesignerHost is the designer’s way to it. The first call. Keep the host, and build the page here.

Syntax: designer.OnAttached( DesignerHost )

DesignerHost
The tab. As DesignerHost.

OnClosed

The tab has been closed. The last call. Let go of what the designer holds: its elements, its timers, its connections.

Syntax: designer.OnClosed()

OnClosing

The tab is closing without a save: it had no changes, or the user chose Discard Changes. A tab closed with Save gets no OnClosing.

Syntax: designer.OnClosing()

OnDeactivated

The tab is no longer the active editor: another tab has been chosen, or the tab is closing.

Syntax: designer.OnDeactivated()

OnFileDataChanged

The bytes of the file, for the designer to show. The IDE calls it as the file opens, and again after a restart of the compiler. It is not called after the designer’s own SetFileData, nor after a save.

Syntax: designer.OnFileDataChanged( byteData )

byteData
The file’s bytes. Byte(), passed ByRef. A new, empty file gives an array with no elements: test it with an error handler round UBound, as Samples 24 and 25 do.

OnSaveCompleted

The file has been written with the bytes the designer gave last. A designer that marks its changes can clear the marks here.

Syntax: designer.OnSaveCompleted()

See Also