提交 cae277a2 编写于 作者: A Alex Ross

Add a command for open port in browser

Part of https://github.com/microsoft/vscode/issues/111402
上级 2fb5b5b6
......@@ -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<QuickPickTunnel>(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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册