Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import { container } from 'tsyringe';
import { WebviewController } from './webview-controller';
/**
* Registry for webview controllers. Provides a single point for maintaining
* and extending the list of available controllers.
*/
export class WebviewControllerRegistry {
private readonly _controllers: WebviewController[] = [];
/**
* Creates a new registry and registers itself in the dependency injection container.
* @param token The dependency injection token to register the registry instance under.
*/
constructor(token: string) {
container.registerInstance(token, this);
}
/**
* Register a controller with the registry.
*/
register<T extends WebviewController>(token: string, controller: T): T {
this._controllers.push(controller);
container.registerInstance(token, controller);
return controller;
}
/**
* Get all registered controllers.
*/
getAll(): WebviewController[] {
return this._controllers;
}
/**
* Find a controller by its view type or panel id.
*/
findById(id: string): WebviewController | undefined {
return this._controllers.find(c => c.viewType === id || c.panelId === id);
}
/**
* Collect all available targets (panels and views) from registered controllers.
*/
collectTargets(): { kind: 'panel' | 'view'; id: string; label: string }[] {
const items: { kind: 'panel' | 'view'; id: string; label: string }[] = [];
for (const c of this._controllers) {
if (c.panelId && c.panelTitle) {
items.push({ kind: 'panel', id: c.panelId, label: `panel: ${c.panelId}` });
}
if (c.viewType) {
items.push({ kind: 'view', id: c.viewType, label: `view: ${c.viewType}` });
}
}
return items;
}
}
|