Merge pull request #162741 from microsoft/tyriar/162713

Move to registerWorkbenchAction usage in terminal
This commit is contained in:
Daniel Imms 2022-10-05 09:11:21 -07:00 committed by GitHub
commit 6557095aee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,59 +3,52 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls'; import { Schemas } from 'vs/base/common/network';
import { Registry } from 'vs/platform/registry/common/platform'; import { URI } from 'vs/base/common/uri';
import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions'; import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; import { localize } from 'vs/nls';
import { TERMINAL_ACTION_CATEGORY, TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal'; import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { Action } from 'vs/base/common/actions';
import { ITerminalGroupService, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { INativeEnvironmentService } from 'vs/platform/environment/common/environment'; import { INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver'; import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { URI } from 'vs/base/common/uri'; import { ITerminalGroupService, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { Schemas } from 'vs/base/common/network';
export function registerRemoteContributions() { export function registerRemoteContributions() {
const actionRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions); registerAction2(class extends Action2 {
actionRegistry.registerWorkbenchAction(SyncActionDescriptor.from(CreateNewLocalTerminalAction), 'Terminal: Create New Integrated Terminal (Local)', TERMINAL_ACTION_CATEGORY); constructor() {
} super({
id: TerminalCommandId.NewLocal,
export class CreateNewLocalTerminalAction extends Action { title: { value: localize('workbench.action.terminal.newLocal', "Create New Integrated Terminal (Local)"), original: 'Create New Integrated Terminal (Local)' },
static readonly ID = TerminalCommandId.NewLocal; f1: true
static readonly LABEL = nls.localize('workbench.action.terminal.newLocal', "Create New Integrated Terminal (Local)"); });
}
constructor( async run(accessor: ServicesAccessor) {
id: string, label: string, const historyService = accessor.get(IHistoryService);
@ITerminalService private readonly _terminalService: ITerminalService, const remoteAuthorityResolverService = accessor.get(IRemoteAuthorityResolverService);
@ITerminalGroupService private readonly _terminalGroupService: ITerminalGroupService, const nativeEnvironmentService = accessor.get(INativeEnvironmentService);
@INativeEnvironmentService private readonly _nativeEnvironmentService: INativeEnvironmentService, const terminalService = accessor.get(ITerminalService);
@IRemoteAuthorityResolverService private readonly _remoteAuthorityResolverService: IRemoteAuthorityResolverService, const terminalGroupService = accessor.get(ITerminalGroupService);
@IHistoryService private readonly _historyService: IHistoryService let cwd: URI | undefined;
) { try {
super(id, label); const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(Schemas.vscodeRemote);
} if (activeWorkspaceRootUri) {
const canonicalUri = await remoteAuthorityResolverService.getCanonicalURI(activeWorkspaceRootUri);
override async run(): Promise<any> { if (canonicalUri.scheme === Schemas.file) {
let cwd: URI | undefined; cwd = canonicalUri;
try { }
const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.vscodeRemote);
if (activeWorkspaceRootUri) {
const canonicalUri = await this._remoteAuthorityResolverService.getCanonicalURI(activeWorkspaceRootUri);
if (canonicalUri.scheme === Schemas.file) {
cwd = canonicalUri;
} }
} catch { }
if (!cwd) {
cwd = nativeEnvironmentService.userHome;
}
const instance = await terminalService.createTerminal({ cwd });
if (!instance) {
return Promise.resolve(undefined);
} }
} catch { }
if (!cwd) {
cwd = this._nativeEnvironmentService.userHome;
}
const instance = await this._terminalService.createTerminal({ cwd });
if (!instance) {
return Promise.resolve(undefined);
}
this._terminalService.setActiveInstance(instance); terminalService.setActiveInstance(instance);
return this._terminalGroupService.showPanel(true); return terminalGroupService.showPanel(true);
} }
});
} }