How to use the inversify.postConstruct function in inversify

To help you get started, we’ve selected a few inversify 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 / cpp / src / browser / cpp-language-client-contribution.ts View on Github external
@inject(ILogger)
    protected readonly logger: ILogger;

    constructor(
        @inject(Workspace) protected readonly workspace: Workspace,
        @inject(Languages) protected readonly languages: Languages,
        @inject(LanguageClientFactory) protected readonly languageClientFactory: LanguageClientFactory,
        @inject(SemanticHighlightingService) protected readonly semanticHighlightingService: SemanticHighlightingService,
    ) {
        super(workspace, languages, languageClientFactory);
    }

    /**
     * Initialize the client contribution.
     */
    @postConstruct()
    protected init(): void {
        this.cppBuildConfigurations.onActiveConfigChange2(() => this.onActiveBuildConfigChanged());
        this.cppPreferences.onPreferenceChanged(() => this.restart());
    }

    /**
     * Handle the language client `onReady` event.
     * @param languageClient the language client.
     */
    protected onReady(languageClient: ILanguageClient): void {
        super.onReady(languageClient);

        // Display the C/C++ build configurations status bar element to select active build config
        this.cppBuildConfigurationsStatusBarElement.show();
    }
github eclipse-theia / theia / packages / debug / src / browser / view / debug-widget.ts View on Github external
@inject(DebugViewModel)
    readonly model: DebugViewModel;

    @inject(DebugSessionManager)
    readonly sessionManager: DebugSessionManager;

    @inject(DebugConfigurationWidget)
    protected readonly toolbar: DebugConfigurationWidget;

    @inject(DebugSessionWidget)
    protected readonly sessionWidget: DebugSessionWidget;

    @inject(ProgressLocationService)
    protected readonly progressLocationService: ProgressLocationService;

    @postConstruct()
    protected init(): void {
        this.id = DebugWidget.ID;
        this.title.label = DebugWidget.LABEL;
        this.title.caption = DebugWidget.LABEL;
        this.title.closable = true;
        this.title.iconClass = 'debug-tab-icon';
        this.addClass('theia-debug-container');
        this.toDispose.pushAll([
            this.toolbar,
            this.sessionWidget,
            this.sessionManager.onDidCreateDebugSession(session => this.model.push(session)),
            this.sessionManager.onDidDestroyDebugSession(session => this.model.delete(session))
        ]);
        for (const session of this.sessionManager.sessions) {
            this.model.push(session);
        }
github eclipse-theia / theia / packages / navigator / src / browser / navigator-tree.ts View on Github external
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 ********************************************************************************/

import { injectable, inject, postConstruct } from 'inversify';
import { FileTree, DirNode } from '@theia/filesystem/lib/browser';
import { FileStat } from '@theia/filesystem/lib/common';
import URI from '@theia/core/lib/common/uri';
import { TreeNode, CompositeTreeNode, SelectableTreeNode } from '@theia/core/lib/browser';
import { FileNavigatorFilter } from './navigator-filter';

@injectable()
export class FileNavigatorTree extends FileTree {

    @inject(FileNavigatorFilter) protected readonly filter: FileNavigatorFilter;

    @postConstruct()
    protected init(): void {
        this.toDispose.push(this.filter.onFilterChanged(() => this.refresh()));
    }

    async resolveChildren(parent: CompositeTreeNode): Promise {
        if (WorkspaceNode.is(parent)) {
            return parent.children;
        }
        return this.filter.filter(super.resolveChildren(parent));
    }

    protected toNodeId(uri: URI, parent: CompositeTreeNode): string {
        const workspaceRootNode = WorkspaceRootNode.find(parent);
        if (workspaceRootNode) {
            return this.createId(workspaceRootNode, uri);
        }
github eclipse-theia / theia / packages / scm / src / browser / scm-context-key-service.ts View on Github external
export class ScmContextKeyService {

    @inject(ContextKeyService)
    protected readonly contextKeyService: ContextKeyService;

    protected _scmProvider: ContextKey;
    get scmProvider(): ContextKey {
        return this._scmProvider;
    }

    protected _scmResourceGroup: ContextKey;
    get scmResourceGroup(): ContextKey {
        return this._scmResourceGroup;
    }

    @postConstruct()
    protected init(): void {
        this._scmProvider = this.contextKeyService.createKey('scmProvider', undefined);
        this._scmResourceGroup = this.contextKeyService.createKey('scmResourceGroup', undefined);
    }

    match(expression: string | undefined): boolean {
        return !expression || this.contextKeyService.match(expression);
    }

}
github eclipse-theia / theia / packages / output / src / common / output-channel.ts View on Github external
protected readonly channelDeleteEmitter = new Emitter<{ channelName: string }>();
    protected readonly channelAddedEmitter = new Emitter();
    protected readonly selectedChannelEmitter: Emitter = new Emitter();
    protected readonly listOrSelectionEmitter: Emitter = new Emitter();
    readonly onChannelDelete = this.channelDeleteEmitter.event;
    readonly onChannelAdded = this.channelAddedEmitter.event;
    readonly onSelectedChannelChange = this.selectedChannelEmitter.event;
    readonly onListOrSelectionChange = this.listOrSelectionEmitter.event;

    protected toDispose = new DisposableCollection();

    @inject(OutputPreferences)
    protected readonly preferences: OutputPreferences;

    @postConstruct()
    protected init(): void {
        this.getChannels().forEach(this.registerListener.bind(this));
        this.toDispose.push(this.onChannelAdded(channel => {
            this.listOrSelectionEmitter.fire(undefined);
            this.registerListener(channel);
        }));
        this.toDispose.push(this.onChannelDelete(event => {
            this.listOrSelectionEmitter.fire(undefined);
            if (this.selectedChannel && this.selectedChannel.name === event.channelName) {
                this.selectedChannel = this.getVisibleChannels()[0];
            }
        }));
    }

    protected registerListener(outputChannel: OutputChannel): void {
        if (!this.selectedChannel) {
github eclipse-theia / theia / packages / debug / src / browser / editor / debug-exception-widget.tsx View on Github external
info: DebugExceptionInfo
    lineNumber: number
    column: number
}

@injectable()
export class DebugExceptionWidget implements Disposable {

    @inject(DebugEditor)
    readonly editor: DebugEditor;

    protected zone: MonacoEditorZoneWidget;

    protected readonly toDispose = new DisposableCollection();

    @postConstruct()
    protected async init(): Promise {
        this.toDispose.push(this.zone = new MonacoEditorZoneWidget(this.editor.getControl()));
        this.zone.containerNode.classList.add('theia-debug-exception-widget');
        this.toDispose.push(Disposable.create(() => ReactDOM.unmountComponentAtNode(this.zone.containerNode)));
    }

    dispose(): void {
        this.toDispose.dispose();
    }

    show({ info, lineNumber, column }: ShowDebugExceptionParams): void {
        this.render(info);

        const fontInfo = this.editor.getControl().getConfiguration().fontInfo;
        this.zone.containerNode.style.fontSize = `${fontInfo.fontSize}px`;
        this.zone.containerNode.style.lineHeight = `${fontInfo.lineHeight}px`;
github eclipse-theia / theia / packages / getting-started / src / browser / getting-started-widget.tsx View on Github external
@inject(ApplicationServer)
    protected readonly appServer: ApplicationServer;

    @inject(CommandRegistry)
    protected readonly commandRegistry: CommandRegistry;

    @inject(FileSystem)
    protected readonly fileSystem: FileSystem;

    @inject(LabelProvider)
    protected readonly labelProvider: LabelProvider;

    @inject(WorkspaceService)
    protected readonly workspaceService: WorkspaceService;

    @postConstruct()
    protected async init(): Promise {
        this.id = GettingStartedWidget.ID;
        this.title.label = GettingStartedWidget.LABEL;
        this.title.caption = GettingStartedWidget.LABEL;
        this.title.closable = true;

        this.applicationInfo = await this.appServer.getApplicationInfo();
        this.recentWorkspaces = await this.workspaceService.recentWorkspaces();
        this.stat = await this.fileSystem.getCurrentUserHome();
        this.home = this.stat ? new URI(this.stat.uri).path.toString() : undefined;
        this.update();
    }

    /**
     * Render the content of the widget.
     */
github eclipse-theia / theia / packages / task / src / browser / task-contribution.ts View on Github external
}

export interface TaskProvider {
    /** Returns the Task Configurations which are provides programmatically to the system. */
    provideTasks(): Promise;
}

@injectable()
export class TaskResolverRegistry {

    protected readonly onWillProvideTaskResolverEmitter = new Emitter();
    readonly onWillProvideTaskResolver = this.onWillProvideTaskResolverEmitter.event;

    protected resolvers: Map;

    @postConstruct()
    protected init(): void {
        this.resolvers = new Map();
    }

    /** Registers the given Task Resolver to resolve the Task Configurations of the specified type. */
    register(type: string, resolver: TaskResolver): Disposable {
        this.resolvers.set(type, resolver);
        return {
            dispose: () => this.resolvers.delete(type)
        };
    }

    async getResolver(type: string): Promise {
        await WaitUntilEvent.fire(this.onWillProvideTaskResolverEmitter, {});
        return this.resolvers.get(type);
    }
github eclipse-theia / theia / packages / navigator / src / browser / navigator-widget.tsx View on Github external
constructor(
        @inject(TreeProps) readonly props: TreeProps,
        @inject(FileNavigatorModel) readonly model: FileNavigatorModel,
        @inject(ContextMenuRenderer) contextMenuRenderer: ContextMenuRenderer,
        @inject(CommandService) protected readonly commandService: CommandService,
        @inject(SelectionService) protected readonly selectionService: SelectionService,
        @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService,
        @inject(ApplicationShell) protected readonly shell: ApplicationShell,
        @inject(FileSystem) protected readonly fileSystem: FileSystem
    ) {
        super(props, model, contextMenuRenderer);
        this.id = FILE_NAVIGATOR_ID;
        this.addClass(CLASS);
    }

    @postConstruct()
    protected init(): void {
        super.init();
        this.updateSelectionContextKeys();
        this.toDispose.pushAll([
            this.model.onSelectionChanged(() =>
                this.updateSelectionContextKeys()
            ),
            this.model.onExpansionChanged(node => {
                if (node.expanded && node.children.length === 1) {
                    const child = node.children[0];
                    if (ExpandableTreeNode.is(child) && !child.expanded) {
                        this.model.expandNode(child);
                    }
                }

            })
github javascript-obfuscator / javascript-obfuscator / src / storages / string-array / StringArrayStorage.ts View on Github external
* @param {IOptions} options
     */
    constructor (
        @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
            identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
        @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils,
        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
        @inject(ServiceIdentifiers.IOptions) options: IOptions
    ) {
        super(randomGenerator, options);

        this.identifierNamesGenerator = identifierNamesGeneratorFactory(options);
        this.arrayUtils = arrayUtils;
    }

    @postConstruct()
    public initialize (): void {
        super.initialize();

        const baseStringArrayName: string = this.identifierNamesGenerator
            .generate(StringArrayStorage.stringArrayNameLength);
        const baseStringArrayCallsWrapperName: string = this.identifierNamesGenerator
            .generate(StringArrayStorage.stringArrayNameLength);
        const stringArrayName: string = `${this.options.identifiersPrefix}${baseStringArrayName}`;
        const stringArrayCallsWrapperName: string = `${this.options.identifiersPrefix}${baseStringArrayCallsWrapperName}`;

        this.storageId = `${stringArrayName}|${stringArrayCallsWrapperName}`;
    }

    /**
     * @param {number} rotationValue
     */