How to use the @theia/core.DisposableCollection 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 / hosted / browser / hosted-plugin.ts View on Github external
protected async doLoad(): Promise {
        const toDisconnect = new DisposableCollection(Disposable.create(() => { /* mark as connected */ }));
        toDisconnect.push(Disposable.create(() => this.preserveWebviews()));
        this.server.onDidCloseConnection(() => toDisconnect.dispose());

        // process empty plugins as well in order to properly remove stale plugin widgets
        await this.syncPlugins();

        // make sure that the previous state, including plugin widgets, is restored
        // and core layout is initialized, i.e. explorer, scm, debug views are already added to the shell
        // but shell is not yet revealed
        await this.appState.reachedState('initialized_layout');

        if (toDisconnect.disposed) {
            // if disconnected then don't try to load plugin contributions
            return;
        }
        const contributionsByHost = this.loadContributions(toDisconnect);
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 / main / browser / text-editor-main.ts View on Github external
private setEditor(editor?: MonacoEditor): void {
        if (this.editor === editor) {
            return;
        }

        this.editorListeners.dispose();
        this.editorListeners = new DisposableCollection();
        this.editor = editor;

        if (this.editor) {
            const monaco = this.editor.getControl();
            this.editorListeners.push(this.editor.onSelectionChanged(_ => {
                this.updateProperties();
            }));
            this.editorListeners.push(monaco.onDidChangeModel(() => {
                this.setEditor(undefined);
            }));
            this.editorListeners.push(monaco.onDidChangeCursorSelection(e => {
                this.updateProperties(e.source);
            }));
            this.editorListeners.push(monaco.onDidChangeConfiguration(() => {
                this.updateProperties();
            }));
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / menus / menus-contribution-handler.ts View on Github external
protected registerTitleAction(location: string, action: Menu, handler: CommandHandler): Disposable {
        const toDispose = new DisposableCollection();
        const id = this.createSyntheticCommandId(action.command, { prefix: `__plugin.${location.replace('/', '.')}.action.` });
        const command: Command = { id };
        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);
                }
github eclipse-theia / theia / packages / outline-view / src / browser / outline-view-service.ts View on Github external
createWidget(): Promise {
        this.widget = this.factory();
        const disposables = new DisposableCollection();
        disposables.push(this.widget.onDidChangeOpenStateEmitter.event(open => this.onDidChangeOpenStateEmitter.fire(open)));
        disposables.push(this.widget.model.onOpenNode(node => this.onDidOpenEmitter.fire(node as OutlineSymbolInformationNode)));
        disposables.push(this.widget.model.onSelectionChanged(selection => this.onDidSelectEmitter.fire(selection[0] as OutlineSymbolInformationNode)));
        this.widget.disposed.connect(() => {
            this.widget = undefined;
            disposables.dispose();
        });
        return Promise.resolve(this.widget);
    }
}
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / keybindings / keybindings-contribution-handler.ts View on Github external
handle(contributions: PluginContribution): Disposable {
        if (!contributions || !contributions.keybindings) {
            return Disposable.NULL;
        }
        const toDispose = new DisposableCollection();
        for (const raw of contributions.keybindings) {
            const keybinding = this.toKeybinding(raw);
            if (keybinding) {
                toDispose.push(this.keybindingRegistry.registerKeybinding(keybinding, true));
            }
        }
        return toDispose;
    }