diff --git a/src/vs/workbench/contrib/remote/browser/tunnelView.ts b/src/vs/workbench/contrib/remote/browser/tunnelView.ts index a99acd36f569a0ba3e00c045f676a03626dc60a7..efa84164465e713a41054c015a1267e00ea53f48 100644 --- a/src/vs/workbench/contrib/remote/browser/tunnelView.ts +++ b/src/vs/workbench/contrib/remote/browser/tunnelView.ts @@ -927,6 +927,43 @@ export namespace OpenPortInBrowserAction { } } +namespace OpenPortInBrowserCommandPaletteAction { + export const ID = 'remote.tunnel.openCommandPalette'; + export const LABEL = nls.localize('remote.tunnel.openCommandPalette', "Open Port in Browser"); + + interface QuickPickTunnel extends IQuickPickItem { + tunnel?: TunnelItem; + } + + export function handler(): ICommandHandler { + return async (accessor, arg) => { + const model = accessor.get(IRemoteExplorerService).tunnelModel; + const quickPickService = accessor.get(IQuickInputService); + const openerService = accessor.get(IOpenerService); + const commandService = accessor.get(ICommandService); + const options: QuickPickTunnel[] = [...model.forwarded, ...model.detected].map(value => { + const tunnelItem = TunnelItem.createFromTunnel(value[1]); + return { + label: tunnelItem.label, + description: tunnelItem.description, + tunnel: tunnelItem + }; + }); + if (options.length === 0) { + options.push({ + label: nls.localize('remote.tunnel.openCommandPaletteNone', "No ports currently forwarded. Open the ports view to get started.") + }); + } + const picked = await quickPickService.pick(options, { placeHolder: nls.localize('remote.tunnel.openCommandPalettePick', "Choose the port to open") }); + if (picked && picked.tunnel) { + return OpenPortInBrowserAction.run(model, openerService, makeAddress(picked.tunnel.remoteHost, picked.tunnel.remotePort)); + } else if (picked) { + return commandService.executeCommand(`${TUNNEL_VIEW_ID}.focus`); + } + }; + } +} + namespace CopyAddressAction { export const INLINE_ID = 'remote.tunnel.copyAddressInline'; export const COMMANDPALETTE_ID = 'remote.tunnel.copyAddressCommandPalette'; @@ -1033,6 +1070,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ CommandsRegistry.registerCommand(ClosePortAction.COMMANDPALETTE_ID, ClosePortAction.commandPaletteHandler()); CommandsRegistry.registerCommand(OpenPortInBrowserAction.ID, OpenPortInBrowserAction.handler()); +CommandsRegistry.registerCommand(OpenPortInBrowserCommandPaletteAction.ID, OpenPortInBrowserCommandPaletteAction.handler()); KeybindingsRegistry.registerCommandAndKeybindingRule({ id: CopyAddressAction.INLINE_ID, weight: KeybindingWeight.WorkbenchContrib + tunnelViewCommandsWeightBonus, @@ -1064,6 +1102,13 @@ MenuRegistry.appendMenuItem(MenuId.CommandPalette, ({ }, when: forwardedPortsViewEnabled })); +MenuRegistry.appendMenuItem(MenuId.CommandPalette, ({ + command: { + id: OpenPortInBrowserCommandPaletteAction.ID, + title: OpenPortInBrowserCommandPaletteAction.LABEL + }, + when: forwardedPortsViewEnabled +})); MenuRegistry.appendMenuItem(MenuId.TunnelTitle, ({ group: 'navigation', order: 0,