How to use the @theia/core.Disposable.create function in @theia/core

To help you get started, we’ve selected a few @theia/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / plugin-ext / src / main / browser / menus / menus-contribution-handler.ts View on Github external
toDispose.push(this.commands.registerCommand(command, handler));

        const { when } = action;
        const whenKeys = when && this.contextKeyService.parseKeys(when);
        let onDidChange;
        if (whenKeys && whenKeys.size) {
            const onDidChangeEmitter = new Emitter();
            toDispose.push(onDidChangeEmitter);
            onDidChange = onDidChangeEmitter.event;
            this.contextKeyService.onDidChange.maxListeners = this.contextKeyService.onDidChange.maxListeners + 1;
            toDispose.push(this.contextKeyService.onDidChange(event => {
                if (event.affects(whenKeys)) {
                    onDidChangeEmitter.fire(undefined);
                }
            }));
            toDispose.push(Disposable.create(() => {
                this.contextKeyService.onDidChange.maxListeners = this.contextKeyService.onDidChange.maxListeners - 1;
            }));
        }

        // handle group and priority
        // if group is empty or white space is will be set to navigation
        // ' ' => ['navigation', 0]
        // 'navigation@1' => ['navigation', 1]
        // '1_rest-client@2' => ['1_rest-client', 2]
        // if priority is not a number it will be set to 0
        // navigation@test => ['navigation', 0]
        const [group, sort] = (action.group || 'navigation').split('@');
        const item: Mutable = { id, command: id, group: group.trim() || 'navigation', priority: ~~sort || undefined, when, onDidChange };
        toDispose.push(this.tabBarToolbar.registerItem(item));

        toDispose.push(this.onDidRegisterCommand(action.command, pluginCommand => {
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / menus / menus-contribution-handler.ts View on Github external
protected onDidRegisterCommand(id: string, cb: (command: Command) => void): Disposable {
        const command = this.commands.getCommand(id);
        if (command) {
            cb(command);
            return Disposable.NULL;
        }
        const toDispose = new DisposableCollection();
        // Registering a menu action requires the related command to be already registered.
        // But Theia plugin registers the commands dynamically via the Commands API.
        // Let's wait for ~2 sec. It should be enough to finish registering all the contributed commands.
        // FIXME: remove this workaround (timer) once the https://github.com/theia-ide/theia/issues/3344 is fixed
        const handle = setTimeout(() => toDispose.push(this.onDidRegisterCommand(id, cb)), 2000);
        toDispose.push(Disposable.create(() => clearTimeout(handle)));
        return toDispose;
    }
github eclipse-theia / theia / packages / plugin-ext / src / hosted / browser / hosted-plugin.ts View on Github external
thenable.push((async () => {
                try {
                    const activationEvents = [...this.activationEvents];
                    await manager.$start({ plugins, configStorage, activationEvents });
                    if (toDisconnect.disposed) {
                        return;
                    }
                    for (const contributions of hostContributions) {
                        started++;
                        const plugin = contributions.plugin;
                        const id = plugin.metadata.model.id;
                        contributions.state = PluginContributions.State.STARTED;
                        console.log(`[${this.clientId}][${id}]: Started plugin.`);
                        toDisconnect.push(contributions.push(Disposable.create(() => {
                            console.log(`[${this.clientId}][${id}]: Stopped plugin.`);
                            manager.$stop(id);
                        })));

                        this.activateByWorkspaceContains(manager, plugin);
                    }
                } catch (e) {
                    console.error(`Failed to start plugins for '${host}' host`, e);
                }
            })());
        }
github eclipse-theia / theia / packages / extension-manager / src / common / extension-manager.ts View on Github external
constructor(extension: protocol.Extension,
        protected readonly server: protocol.ExtensionServer,
        protected readonly manager: ExtensionManager) {
        super();
        Object.assign(this, extension);
        this.toDispose.push(this.onDidChangedEmitter);

        manager.onDidChange.maxListeners = manager.onDidChange.maxListeners + 1;
        this.toDispose.push(manager.onDidChange(change => {
            if (change.name === this.name) {
                Object.assign(this, change);
                this.onDidChangedEmitter.fire(change);
            }
        }));
        this.toDispose.push(Disposable.create(() =>
            manager.onDidChange.maxListeners = manager.onDidChange.maxListeners - 1)
        );
    }
github eclipse-theia / theia / packages / monaco / src / browser / monaco-editor-model.ts View on Github external
protected doAutoSave(): void {
        if (this.autoSave === 'on') {
            const token = this.cancelSave();
            this.toDisposeOnAutoSave.dispose();
            const handle = window.setTimeout(() => {
                this.scheduleSave(TextDocumentSaveReason.AfterDelay, token);
            }, this.autoSaveDelay);
            this.toDisposeOnAutoSave.push(Disposable.create(() =>
                window.clearTimeout(handle)),
            );
        }
    }
github eclipse-theia / theia / packages / debug / src / browser / view / debug-toolbar-widget.tsx View on Github external
focus(): void {
        if (!this.doFocus()) {
            this.onRender.push(Disposable.create(() => this.doFocus()));
            this.update();
        }
    }
    protected doFocus(): boolean {
github eclipse-theia / theia / packages / debug / src / browser / editor / debug-breakpoint-widget.tsx View on Github external
}
                    for (const { completion } of items) {
                        completion.range = monaco.Range.fromPositions(position.delta(0, -overwriteBefore), position);
                        suggestions.push(completion);
                    }
                }
                return { suggestions };
            }
        }));
        this.toDispose.push(this.zone.onDidLayoutChange(dimension => this.layout(dimension)));
        this.toDispose.push(input.getControl().onDidChangeModelContent(() => {
            const heightInLines = input.getControl().getModel()!.getLineCount() + 1;
            this.zone.layout(heightInLines);
            this.updatePlaceholder();
        }));
        this.toDispose.push(Disposable.create(() => ReactDOM.unmountComponentAtNode(selectNode)));
    }
github eclipse-theia / theia / packages / plugin-ext / src / hosted / browser / hosted-plugin.ts View on Github external
protected async obtainManager(host: string, hostContributions: PluginContributions[], toDisconnect: DisposableCollection): Promise {
        let manager = this.managers.get(host);
        if (!manager) {
            const pluginId = getPluginId(hostContributions[0].plugin.metadata.model);
            const rpc = this.initRpc(host, pluginId);
            toDisconnect.push(rpc);

            manager = rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT);
            this.managers.set(host, manager);
            toDisconnect.push(Disposable.create(() => this.managers.delete(host)));

            const [extApi, globalState, workspaceState, webviewResourceRoot, webviewCspSource, defaultShell] = await Promise.all([
                this.server.getExtPluginAPI(),
                this.pluginServer.getAllStorageValues(undefined),
                this.pluginServer.getAllStorageValues({
                    workspace: this.workspaceService.workspace,
                    roots: this.workspaceService.tryGetRoots()
                }),
                this.webviewEnvironment.resourceRoot(),
                this.webviewEnvironment.cspSource(),
                this.terminalService.getDefaultShell()
            ]);
            if (toDisconnect.disposed) {
                return undefined;
            }