diff --git a/src/vs/workbench/contrib/remote/browser/remote.contribution.ts b/src/vs/workbench/contrib/remote/browser/remote.contribution.ts index 95960da2b623e1..10dc461b6e2d20 100644 --- a/src/vs/workbench/contrib/remote/browser/remote.contribution.ts +++ b/src/vs/workbench/contrib/remote/browser/remote.contribution.ts @@ -3,6 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { localize } from '../../../../nls.js'; +import { Action2, registerAction2 } from '../../../../platform/actions/common/actions.js'; import { IWorkbenchContributionsRegistry, WorkbenchPhase, Extensions as WorkbenchExtensions, registerWorkbenchContribution2 } from '../../../common/contributions.js'; import { Registry } from '../../../../platform/registry/common/platform.js'; import { ShowCandidateContribution } from './showCandidate.js'; @@ -10,8 +12,29 @@ import { LifecyclePhase } from '../../../services/lifecycle/common/lifecycle.js' import { TunnelFactoryContribution } from './tunnelFactory.js'; import { RemoteAgentConnectionStatusListener, RemoteMarkers } from './remote.js'; import { RemoteStatusIndicator } from './remoteIndicator.js'; -import { AutomaticPortForwarding, ForwardedPortsView, PortRestore } from './remoteExplorer.js'; +import { AutomaticPortForwarding, ForwardedPortsView, PortRestore, TOGGLE_VIEW_ACTION_ID } from './remoteExplorer.js'; import { InitialRemoteConnectionHealthContribution } from './remoteConnectionHealth.js'; +import { IViewsService } from '../../../services/views/common/viewsService.js'; +import { TUNNEL_VIEW_ID } from '../../../services/remote/common/remoteExplorerService.js'; +import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js'; + +registerAction2(class extends Action2 { + constructor() { + super({ + id: TOGGLE_VIEW_ACTION_ID, + title: localize('remote.togglePortsView', "Toggle Forwarded Ports View"), + }); + } + + async run(accessor: ServicesAccessor): Promise { + const viewsService = accessor.get(IViewsService); + if (viewsService.isViewVisible(TUNNEL_VIEW_ID)) { + viewsService.closeView(TUNNEL_VIEW_ID); + } else { + await viewsService.openView(TUNNEL_VIEW_ID, true); + } + } +}); const workbenchContributionsRegistry = Registry.as(WorkbenchExtensions.Workbench); registerWorkbenchContribution2(ShowCandidateContribution.ID, ShowCandidateContribution, WorkbenchPhase.BlockRestore); diff --git a/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts b/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts index be867aa3712b89..f282b78527b64e 100644 --- a/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts +++ b/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts @@ -39,6 +39,7 @@ import { IPreferencesService } from '../../../services/preferences/common/prefer import { IStorageService, StorageScope } from '../../../../platform/storage/common/storage.js'; export const VIEWLET_ID = 'workbench.view.remote'; +export const TOGGLE_VIEW_ACTION_ID = 'remoteExplorer.toggleForwardedPortsView'; export class ForwardedPortsView extends Disposable implements IWorkbenchContribution { private readonly contextKeyListener = this._register(new MutableDisposable()); @@ -166,7 +167,7 @@ export class ForwardedPortsView extends Disposable implements IWorkbenchContribu text: `$(radio-tower) ${text}`, ariaLabel: tooltip, tooltip, - command: `${TUNNEL_VIEW_ID}.focus` + command: TOGGLE_VIEW_ACTION_ID }; } }