Path: blob/main/src/vs/workbench/contrib/opener/browser/opener.contribution.ts
4780 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Disposable } from '../../../../base/common/lifecycle.js';6import { URI } from '../../../../base/common/uri.js';7import { ICommandService } from '../../../../platform/commands/common/commands.js';8import { IFileService } from '../../../../platform/files/common/files.js';9import { IOpener, IOpenerService, OpenExternalOptions, OpenInternalOptions } from '../../../../platform/opener/common/opener.js';10import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';11import { registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js';12import { REVEAL_IN_EXPLORER_COMMAND_ID } from '../../files/browser/fileConstants.js';1314class WorkbenchOpenerContribution extends Disposable implements IOpener {15public static readonly ID = 'workbench.contrib.opener';1617constructor(18@IOpenerService openerService: IOpenerService,19@ICommandService private readonly commandService: ICommandService,20@IFileService private readonly fileService: IFileService,21@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,22) {23super();2425this._register(openerService.registerOpener(this));26}2728async open(link: URI | string, options?: OpenInternalOptions | OpenExternalOptions): Promise<boolean> {29try {30const uri = typeof link === 'string' ? URI.parse(link) : link;31if (this.workspaceContextService.isInsideWorkspace(uri)) {32if ((await this.fileService.stat(uri)).isDirectory) {33await this.commandService.executeCommand(REVEAL_IN_EXPLORER_COMMAND_ID, uri);34return true;35}36}37} catch {38// noop39}4041return false;42}43}444546registerWorkbenchContribution2(WorkbenchOpenerContribution.ID, WorkbenchOpenerContribution, WorkbenchPhase.Eventually);474849