Skip to content

LayoutHub

Controls the layout. Extends MessageHub.

Basic Usage

If you are using the standard Dirigible view configuration, layout support is automatically enabled.

If you are making a custom view, you can include the API using the web link above.

To initialize it:

const layoutHub = new LayoutHub();

This hub is different compared to the others. All hubs listen to changes globally, meaning that, for example, if View A in Perspective A with Layout A sends a message using the WorkspaceHub that there is a change to a workspace and View B in Perspective B with Layout B is listening for workspace changes, then View B will receive that message despite being in a completely different perspective and layout.

The LayoutHub is going to react to changes only from views that are inside it, not to outside changes. If View A in Perspective A requests for View C to be opened, the view will be opened only in the Perspective A layout and Perspective B will not change.

Constructor

Properties

Param Type Description
[layoutId] string Layout id. By default, it's the perspective id.
[setId] boolean When creating a layout, this parameter must be set to true as it will register the current window object as a layout one and set a layoutId parameter in it. This will help all child views to get the layout id automatically.

Functions


Function Description Returns
getOpenedViews(ParamsObject) Returns a list of opened view ids. Promise
onGetOpenedViews(handlerFunc) Registers a listener. Triggered when a list of opened views is requested. Returns a function to unregister the listener. function
isViewOpen(IdParamObject) Returns true if a view is opened. Promise
onIsViewOpen(handlerFunc) Registers a listener. Triggered when a view opened state check is requested. Returns a function to unregister the listener. function
openView(IdParamObject) Opens a view. -
onOpenView(handlerFunc) Registers a listener. Triggered when a view should be opened. Returns a function to unregister the listener. function
focusView(IdParamObject) Focuses a view. -
onFocusView(handlerFunc) Registers a listener. Triggered when a view should be focused. Returns a function to unregister the listener. function
closeView(IdParamObject) Closes a view. -
onCloseView(handlerFunc) Registers a listener. Triggered when a view should be closed. Returns a function to unregister the listener. function
closeOtherViews(IdParamObject) Closes all other views. -
onCloseOtherViews(handlerFunc) Registers a listener. Triggered when other views should be closed. Returns a function to unregister the listener. function
closeAllViews(ParamsObject) Closes all views. -
onCloseAllViews(handlerFunc) Registers a listener. Triggered when all views should be closed. Returns a function to unregister the listener. function
setViewDirty(ViewDirtyObject) Sets the dirty state of a view. -
onViewDirty(handlerFunc) Registers a listener. Triggered when a view's dirty state should be changed. Returns a function to unregister the listener. function
openEditor(OpenEditorParams) Sends a message containing information on which editor has to be opened. -
onOpenEditor(handlerFunc) Triggered when an editor has to be opened. function
closeEditor(PathParams) Sends a message containing information on which editor has to be closed. -
onCloseEditor(handlerFunc) Triggered when an editor has to be closed. function
closeAllEditors(Params) Sends a message when all editors should be closed. -
onCloseAllEditors(handlerFunc) Triggered when editors have to be closed. function
setEditorDirty(EditorDirtyParams) Sends a message containing information on which editor has to be set to dirty. -
onSetEditorDirty(handlerFunc) Triggered when an editor has to be set as dirty. function
isEditorDirty(PathParams) Gets the dirty state of an editor. Promise
onIsEditorDirty(handlerFunc) Triggered when an editor's dirty state is requested. function
isEditorOpen(PathParams) Checks if an editor is open. Promise
onIsEditorOpen(handlerFunc) Triggered when performing a check for an open editor. function
getCurrentlyOpenedEditors(GetOpenedParams) Gets all file paths from the currently opened editors. Promise
onGetCurrentlyOpenedEditors(handlerFunc) Triggered when a list of opened files is requested. function
reloadEditorParams(PathParams) Tells an editor that it should reload its view parameters. -
onReloadEditorParams(handlerFunc) Triggered when an editor should reload its view parameters. function

Typedefs

IdParamObject : Object
ParamsObject : Object
ViewDirtyObject : Object
OpenEditorParams : Object
PathParams : Object
Params : Object
EditorDirtyParams : Object
GetOpenedParams : Object

Note

Params in square brackets are optional.

IdParamObject : Object

Properties

Param Type Description
id string View id.
[params] object Custom parameters. See ViewParameters.

ParamsObject : Object

Properties

Param Type Description
[params] object Custom parameters. See ViewParameters.

ViewDirtyObject : Object

Properties

Param Type Description
id string View id.
dirty boolean Dirty state.
[params] object Custom parameters. See ViewParameters.

OpenEditorParams : Object

Param Type Description
path string Full file path, including file name.
contentType string The file content type.
[editorId] string The ID of the preffered editor.
[params] Object.<any, any> Extra parameters that will be passed to the view parameters of the editor.

PathParams : Object

Param Type Description
path string Full file path, including file name.
[params] Object.<any, any> Extra parameters.

Params : Object

Param Type Description
[params] Object.<any, any> Extra parameters.

EditorDirtyParams : Object

Param Type Description
path string Full file path, including file name.
dirty boolean File dirty state.
[params] Object.<any, any> Extra parameters.

GetOpenedParams : Object

Param Type Description
basePath string If provided, it will only return files with a matching base path.

Example

If you want your view to just communicate with the layout that it's in:

const layoutHub = new LayoutHub();

If you want your view to just communicate with the layout that somewere else in the application:

const layoutHub = new LayoutHub('other-layout-id');

If you want your view/perspective to be registered as a layout or layout-containing and receive layout events:

const layoutHub = new LayoutHub('some-layout-id', true);

To open a view:

layoutHub.openView({
    id: 'exampleView',
    params: {
        title: 'Example',
    }
});