Skip to content

Commit 06200a6

Browse files
authored
Merge pull request microsoft#259422 from microsoft/tyriar/copilot_fix-258895__259417
Add new terminal window to + menu, create 'new' section
2 parents 7063963 + 64bf6c6 commit 06200a6

File tree

5 files changed

+43
-31
lines changed

5 files changed

+43
-31
lines changed

src/vs/workbench/contrib/terminal/browser/terminal.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ export interface ITerminalService extends ITerminalInstanceHost {
287287
*/
288288
createTerminal(options?: ICreateTerminalOptions): Promise<ITerminalInstance>;
289289

290+
/**
291+
* Creates and focuses a terminal.
292+
* @param options The options to create the terminal with, when not specified the default
293+
* profile will be used at the default target.
294+
*/
295+
createAndFocusTerminal(options?: ICreateTerminalOptions): Promise<ITerminalInstance>;
296+
290297
/**
291298
* Creates a detached xterm instance which is not attached to the DOM or
292299
* tracked as a terminal instance.

src/vs/workbench/contrib/terminal/browser/terminalMenus.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ICreateTerminalOptions, ITerminalLocationOptions, ITerminalService } fr
1616
import { TerminalCommandId, TERMINAL_VIEW_ID } from '../common/terminal.js';
1717
import { TerminalContextKeys, TerminalContextKeyStrings } from '../common/terminalContextKey.js';
1818
import { terminalStrings } from '../common/terminalStrings.js';
19-
import { ACTIVE_GROUP, SIDE_GROUP } from '../../../services/editor/common/editorService.js';
19+
import { ACTIVE_GROUP, AUX_WINDOW_GROUP, SIDE_GROUP } from '../../../services/editor/common/editorService.js';
2020
import { DisposableStore } from '../../../../base/common/lifecycle.js';
2121

2222
const enum ContextMenuGroup {
@@ -719,39 +719,45 @@ export function getTerminalActionBarArgs(location: ITerminalLocationOptions, pro
719719
className: string;
720720
dropdownIcon?: string;
721721
} {
722-
let dropdownActions: IAction[] = [];
723-
let submenuActions: IAction[] = [];
724-
profiles = profiles.filter(e => !e.isAutoDetected);
722+
const dropdownActions: IAction[] = [];
723+
const submenuActions: IAction[] = [];
725724
const splitLocation = (location === TerminalLocation.Editor || (typeof location === 'object' && 'viewColumn' in location && location.viewColumn === ACTIVE_GROUP)) ? { viewColumn: SIDE_GROUP } : { splitActiveTerminal: true };
725+
726+
dropdownActions.push(disposableStore.add(new Action(TerminalCommandId.New, terminalStrings.new, undefined, true, () => terminalService.createAndFocusTerminal())));
727+
dropdownActions.push(disposableStore.add(new Action(TerminalCommandId.NewInNewWindow, terminalStrings.newInNewWindow.short, undefined, true, () => terminalService.createAndFocusTerminal({
728+
location: { viewColumn: AUX_WINDOW_GROUP }
729+
}))));
730+
dropdownActions.push(disposableStore.add(new Action(TerminalCommandId.Split, terminalStrings.split.value, undefined, true, () => terminalService.createAndFocusTerminal({
731+
location: splitLocation
732+
}))));
733+
dropdownActions.push(new Separator());
734+
735+
profiles = profiles.filter(e => !e.isAutoDetected);
726736
for (const p of profiles) {
727737
const isDefault = p.profileName === defaultProfileName;
728738
const options: ICreateTerminalOptions = { config: p, location };
729739
const splitOptions: ICreateTerminalOptions = { config: p, location: splitLocation };
730740
const sanitizedProfileName = p.profileName.replace(/[\n\r\t]/g, '');
731741
dropdownActions.push(disposableStore.add(new Action(TerminalCommandId.NewWithProfile, isDefault ? localize('defaultTerminalProfile', "{0} (Default)", sanitizedProfileName) : sanitizedProfileName, undefined, true, async () => {
732-
const instance = await terminalService.createTerminal(options);
733-
terminalService.setActiveInstance(instance);
734-
await terminalService.focusActiveInstance();
742+
await terminalService.createAndFocusTerminal(options);
735743
})));
736744
submenuActions.push(disposableStore.add(new Action(TerminalCommandId.Split, isDefault ? localize('defaultTerminalProfile', "{0} (Default)", sanitizedProfileName) : sanitizedProfileName, undefined, true, async () => {
737-
const instance = await terminalService.createTerminal(splitOptions);
738-
terminalService.setActiveInstance(instance);
739-
await terminalService.focusActiveInstance();
745+
await terminalService.createAndFocusTerminal(splitOptions);
740746
})));
741747
}
742748

743749
for (const contributed of contributedProfiles) {
744750
const isDefault = contributed.title === defaultProfileName;
745751
const title = isDefault ? localize('defaultTerminalProfile', "{0} (Default)", contributed.title.replace(/[\n\r\t]/g, '')) : contributed.title.replace(/[\n\r\t]/g, '');
746-
dropdownActions.push(disposableStore.add(new Action('contributed', title, undefined, true, () => terminalService.createTerminal({
752+
dropdownActions.push(disposableStore.add(new Action('contributed', title, undefined, true, () => terminalService.createAndFocusTerminal({
747753
config: {
748754
extensionIdentifier: contributed.extensionIdentifier,
749755
id: contributed.id,
750756
title
751757
},
752758
location
753759
}))));
754-
submenuActions.push(disposableStore.add(new Action('contributed-split', title, undefined, true, () => terminalService.createTerminal({
760+
submenuActions.push(disposableStore.add(new Action('contributed-split', title, undefined, true, () => terminalService.createAndFocusTerminal({
755761
config: {
756762
extensionIdentifier: contributed.extensionIdentifier,
757763
id: contributed.id,
@@ -761,25 +767,13 @@ export function getTerminalActionBarArgs(location: ITerminalLocationOptions, pro
761767
}))));
762768
}
763769

764-
const defaultProfileAction = dropdownActions.find(d => d.label.endsWith('(Default)'));
765-
if (defaultProfileAction) {
766-
dropdownActions = dropdownActions.filter(d => d !== defaultProfileAction).sort((a, b) => a.label.localeCompare(b.label));
767-
dropdownActions.unshift(defaultProfileAction);
768-
}
769-
770770
if (dropdownActions.length > 0) {
771-
dropdownActions.push(new SubmenuAction('split.profile', localize('splitTerminal', 'Split Terminal'), submenuActions));
771+
dropdownActions.push(new SubmenuAction('split.profile', localize('split.profile', 'Split Terminal with Profile'), submenuActions));
772772
dropdownActions.push(new Separator());
773773
}
774774
const actions = dropdownMenu.getActions();
775775
dropdownActions.push(...Separator.join(...actions.map(a => a[1])));
776776

777-
const defaultSubmenuProfileAction = submenuActions.find(d => d.label.endsWith('(Default)'));
778-
if (defaultSubmenuProfileAction) {
779-
submenuActions = submenuActions.filter(d => d !== defaultSubmenuProfileAction).sort((a, b) => a.label.localeCompare(b.label));
780-
submenuActions.unshift(defaultSubmenuProfileAction);
781-
}
782-
783777
const dropdownAction = disposableStore.add(new Action('refresh profiles', localize('launchProfile', 'Launch Profile...'), 'codicon-chevron-down', true));
784778
return { dropdownAction, dropdownMenuActions: dropdownActions, className: `terminal-tab-actions-${terminalService.resolveLocation(location)}` };
785779
}

src/vs/workbench/contrib/terminal/browser/terminalService.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,13 @@ export class TerminalService extends Disposable implements ITerminalService {
10361036
return instance;
10371037
}
10381038

1039+
async createAndFocusTerminal(options?: ICreateTerminalOptions): Promise<ITerminalInstance> {
1040+
const instance = await this.createTerminal(options);
1041+
this.setActiveInstance(instance);
1042+
await instance.focusWhenReady();
1043+
return instance;
1044+
}
1045+
10391046
private async _getContributedProfile(shellLaunchConfig: IShellLaunchConfig, options?: ICreateTerminalOptions): Promise<IExtensionTerminalProfile | undefined> {
10401047
if (options?.config && 'extensionIdentifier' in options.config) {
10411048
return options.config;

src/vs/workbench/contrib/terminal/browser/terminalView.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class TerminalViewPane extends ViewPane {
7676
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
7777
@IViewDescriptorService viewDescriptorService: IViewDescriptorService,
7878
@IConfigurationService private readonly _configurationService: IConfigurationService,
79-
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
79+
@IContextMenuService contextMenuService: IContextMenuService,
8080
@IInstantiationService private readonly _instantiationService: IInstantiationService,
8181
@ITerminalService private readonly _terminalService: ITerminalService,
8282
@ITerminalConfigurationService private readonly _terminalConfigurationService: ITerminalConfigurationService,
@@ -89,10 +89,8 @@ export class TerminalViewPane extends ViewPane {
8989
@IMenuService private readonly _menuService: IMenuService,
9090
@ITerminalProfileService private readonly _terminalProfileService: ITerminalProfileService,
9191
@ITerminalProfileResolverService private readonly _terminalProfileResolverService: ITerminalProfileResolverService,
92-
@IThemeService private readonly _themeService: IThemeService,
93-
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService
9492
) {
95-
super(options, keybindingService, _contextMenuService, _configurationService, _contextKeyService, viewDescriptorService, _instantiationService, openerService, themeService, hoverService);
93+
super(options, keybindingService, contextMenuService, _configurationService, _contextKeyService, viewDescriptorService, _instantiationService, openerService, themeService, hoverService);
9694
this._register(this._terminalService.onDidRegisterProcessSupport(() => {
9795
this._onDidChangeViewWelcomeState.fire();
9896
}));
@@ -293,7 +291,10 @@ export class TerminalViewPane extends ViewPane {
293291
case TerminalCommandId.New: {
294292
if (action instanceof MenuItemAction) {
295293
const actions = getTerminalActionBarArgs(TerminalLocation.Panel, this._terminalProfileService.availableProfiles, this._getDefaultProfileName(), this._terminalProfileService.contributedProfiles, this._terminalService, this._dropdownMenu, this._disposableStore);
296-
this._newDropdown.value = new DropdownWithPrimaryActionViewItem(action, actions.dropdownAction, actions.dropdownMenuActions, actions.className, { hoverDelegate: options.hoverDelegate }, this._contextMenuService, this._keybindingService, this._notificationService, this._contextKeyService, this._themeService, this._accessibilityService);
294+
this._newDropdown.value = this._instantiationService.createInstance(DropdownWithPrimaryActionViewItem, action, actions.dropdownAction, actions.dropdownMenuActions, actions.className, {
295+
hoverDelegate: options.hoverDelegate,
296+
getKeyBinding: (action: IAction) => this._keybindingService.lookupKeybinding(action.id, this._contextKeyService)
297+
});
297298
this._newDropdown.value?.update(actions.dropdownAction, actions.dropdownMenuActions);
298299
return this._newDropdown.value;
299300
}

src/vs/workbench/contrib/terminal/common/terminalStrings.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export const terminalStrings = {
2525
},
2626
moveToEditor: localize2('moveToEditor', "Move Terminal into Editor Area"),
2727
moveIntoNewWindow: localize2('moveIntoNewWindow', "Move Terminal into New Window"),
28-
newInNewWindow: localize2('newInNewWindow', "New Terminal in New Window"),
28+
newInNewWindow: {
29+
...localize2('newInNewWindow', "New Terminal in New Window"),
30+
short: localize('newInNewWindow.short', "New in New Window")
31+
},
2932
moveToTerminalPanel: localize2('workbench.action.terminal.moveToTerminalPanel', "Move Terminal into Panel"),
3033
changeIcon: localize2('workbench.action.terminal.changeIcon', "Change Icon..."),
3134
changeColor: localize2('workbench.action.terminal.changeColor', "Change Color..."),

0 commit comments

Comments
 (0)