I added a button to my glsp view to switch views (you already answered me)
but after developing the switch button and binding what was injected, the view isn’t rendered. I have no errors.
by the way, I haven’t tested my work yet, so please your feedback
is appreciated concerning the developing.
button.ts
@injectable()
export class ButtonOverlay extends AbstractUIExtension {
@inject(TYPES.IActionDispatcher)
protected readonly actionDispatcher: IActionDispatcher;
@inject(OpenerService)
protected readonly openerService: OpenerService;
static readonly ID = "button-overlay";
protected initializeContents(containerElement: HTMLElement): void {
containerElement.appendChild(
this.createButton(
"btn_switch_view",
"Switch to table view",
"arrow-both",
SwitchViewAction.create('my-view-uri', {})
)
);
}
protected createButton(
id: string,
label: string,
codiconId: string,
action: SwitchViewAction
): HTMLElement {
const baseDiv = document.getElementById(this.options.baseDiv);
if (baseDiv) {
const button = document.createElement("div");
const insertedDiv = baseDiv.insertBefore(button, baseDiv.firstChild);
button.id = id;
button.classList.add("overlay-button");
const icon = this.createIcon(codiconId);
insertedDiv.appendChild(icon);
insertedDiv.onclick = () => {
const uri = new URI(action.uri);
open(this.openerService, uri, action.openerOptions);
}
insertedDiv.insertAdjacentText("beforeend", label);
return button;
}
return document.createElement("div");
}
protected createIcon(codiconId: string): HTMLElement {
const icon = document.createElement("i");
icon.classList.add(...codiconCSSClasses(codiconId), "overlay-icon");
return icon;
}
}
export interface SwitchViewAction {
readonly kind: string;
readonly uri: string;
readonly openerOptions?: object;
}
export class SwitchViewAction implements SwitchViewAction {
static readonly KIND = "switchView";
constructor(readonly uri: string, readonly openerOptions?: object) { }
// get kind() {
// return SwitchViewAction.KIND;
// }
static create(uri: string, openerOptions?: object): SwitchViewAction {
return new SwitchViewAction(uri, openerOptions);
}
}
and inside di.config.ts
:
bind(ButtonOverlay).toSelf().inSingletonScope();
bind(TYPES.IUIExtension).toService(ButtonOverlay);
bind(OpenerService).to(ButtonOverlay).inSingletonScope();