How to use the @theia/core/lib/common/disposable.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 / view / plugin-view-registry.ts View on Github external
const identifier = this.toPluginViewWidgetIdentifier(viewId);
            const widget = await this.widgetManager.getOrCreateWidget(PLUGIN_VIEW_FACTORY_ID, identifier);
            if (containerWidget.getTrackableWidgets().indexOf(widget) === -1) {
                containerWidget.addWidget(widget, {
                    initiallyCollapsed: !!containerWidget.getParts().length
                });
            }
            const part = containerWidget.getPartFor(widget);
            if (part) {
                const tryFireOnDidExpandView = () => {
                    if (!part.collapsed && part.isVisible) {
                        toFire.dispose();
                    }
                };
                const toFire = new DisposableCollection(
                    Disposable.create(() => this.onDidExpandViewEmitter.fire(viewId)),
                    part.onCollapsed(tryFireOnDidExpandView),
                    part.onVisibilityChanged(tryFireOnDidExpandView)
                );
                tryFireOnDidExpandView();
            }
        }
    }
github eclipse-theia / theia / packages / task / src / browser / task-definition-registry.ts View on Github external
register(definition: TaskDefinition): Disposable {
        const taskType = definition.taskType;
        const definitions = this.definitions.get(taskType) || [];
        definitions.push(definition);
        this.definitions.set(taskType, definitions);
        this.onDidRegisterTaskDefinitionEmitter.fire(undefined);
        return Disposable.create(() => {
            const index = definitions.indexOf(definition);
            if (index !== -1) {
                definitions.splice(index, 1);
            }
            this.onDidUnregisterTaskDefinitionEmitter.fire(undefined);
        });
    }
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / text-editors-main.ts View on Github external
private onTextEditorAdd(editor: TextEditorMain): void {
        const id = editor.getId();
        const toDispose = new DisposableCollection(
            editor.onPropertiesChangedEvent(e => {
                this.proxy.$acceptEditorPropertiesChanged(id, e);
            }),
            Disposable.create(() => this.editorsToDispose.delete(id))
        );
        this.editorsToDispose.set(id, toDispose);
        this.toDispose.push(toDispose);
    }
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / debug / plugin-debug-service.ts View on Github external
registerDebugger(contribution: DebuggerContribution): Disposable {
        this.debuggers.push(contribution);
        return Disposable.create(() => {
            const index = this.debuggers.indexOf(contribution);
            if (index !== -1) {
                this.debuggers.splice(index, 1);
            }
        });
    }
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / terminal-main.ts View on Github external
protected async trackTerminal(terminal: TerminalWidget): Promise {
        let name = terminal.title.label;
        this.extProxy.$terminalCreated(terminal.id, name);
        const updateTitle = () => {
            if (name !== terminal.title.label) {
                name = terminal.title.label;
                this.extProxy.$terminalNameChanged(terminal.id, name);
            }
        };
        terminal.title.changed.connect(updateTitle);
        this.toDispose.push(Disposable.create(() => terminal.title.changed.disconnect(updateTitle)));

        const updateProcessId = () => terminal.processId.then(
            processId => this.extProxy.$terminalOpened(terminal.id, processId),
            () => {/*no-op*/ }
        );
        updateProcessId();
        this.toDispose.push(terminal.onDidOpen(() => updateProcessId()));
        this.toDispose.push(terminal.onTerminalDidClose(() => this.extProxy.$terminalClosed(terminal.id)));
    }
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / command-registry-main.ts View on Github external
$registerHandler(id: string): void {
        this.handlers.set(id, this.contributions.registerCommandHandler(id, (...args) =>
            this.proxy.$executeCommand(id, ...args)
        ));
        this.toDispose.push(Disposable.create(() => this.$unregisterHandler(id)));
    }
    $unregisterHandler(id: string): void {
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / plugin-icon-theme-service.ts View on Github external
protected async load(): Promise {
        if (this.styleSheetContent !== undefined) {
            return;
        }
        this.styleSheetContent = '';
        this.toUnload.push(Disposable.create(() => {
            this.styleSheetContent = undefined;
            this.hasFileIcons = undefined;
            this.hasFolderIcons = undefined;
            this.hidesExplorerArrows = undefined;
            this.icons.clear();
        }));

        const { content } = await this.fileSystem.resolveContent(this.uri);
        const json: RecursivePartial = jsoncparser.parse(content, undefined, { disallowComments: false });
        this.hidesExplorerArrows = !!json.hidesExplorerArrows;

        const uri = new URI(this.uri);
        const toUnwatch = await this.fsWatcher.watchFileChanges(uri);
        if (this.toUnload.disposed) {
            toUnwatch.dispose();
        } else {
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / plugin-icon-theme-service.ts View on Github external
activate(): Disposable {
        if (!this.toDeactivate.disposed) {
            return this.toDeactivate;
        }
        this.toDeactivate.push(Disposable.create(() => this.fireDidChange()));
        this.doActivate();
        return this.toDeactivate;
    }
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / debug / debug-main.ts View on Github external
);

        const toDispose = new DisposableCollection(
            Disposable.create(() => this.debuggerContributions.delete(debugType))
        );
        this.debuggerContributions.set(debugType, toDispose);
        toDispose.pushAll([
            this.adapterContributionRegistrator.registerDebugAdapterContribution(
                new PluginDebugAdapterContribution(description, this.debugExt, this.pluginService)
            ),
            this.sessionContributionRegistrator.registerDebugSessionContribution({
                debugType: description.type,
                debugSessionFactory: () => debugSessionFactory
            })
        ]);
        this.toDispose.push(Disposable.create(() => this.$unregisterDebuggerConfiguration(debugType)));
    }
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / status-bar-message-registry-main.ts View on Github external
command: string | undefined): Promise {
        const entry = {
            text: text || '',
            priority,
            alignment: alignment === types.StatusBarAlignment.Left ? StatusBarAlignment.LEFT : StatusBarAlignment.RIGHT,
            color: color && (this.colorRegistry.getCurrentColor(color) || color),
            tooltip,
            command
        };

        this.entries.set(id, entry);
        await this.delegate.setElement(id, entry);
        if (this.toDispose.disposed) {
            this.$dispose(id);
        } else {
            this.toDispose.push(Disposable.create(() => this.$dispose(id)));
        }
    }