Skip to content

Commit

Permalink
fix bugs & polish (#132501)
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge authored Sep 7, 2021
1 parent 769d5fb commit 6252610
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 38 deletions.
84 changes: 49 additions & 35 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,11 @@ export function registerTerminalActions() {
precondition: TerminalContextKeys.processSupported
});
}
async run(accessor: ServicesAccessor) {
return accessor.get(ITerminalService).activeInstance?.changeIcon();
async run(accessor: ServicesAccessor, resource: unknown) {
const terminalService = accessor.get(ITerminalService);
const castedResource = URI.isUri(resource) ? resource : undefined;
const instance = terminalService.getInstanceFromResource(castedResource) || terminalService.activeInstance;
instance?.changeIcon();
}
});
registerAction2(class extends Action2 {
Expand Down Expand Up @@ -790,8 +793,11 @@ export function registerTerminalActions() {
precondition: TerminalContextKeys.processSupported
});
}
async run(accessor: ServicesAccessor) {
return accessor.get(ITerminalService).activeInstance?.changeColor();
async run(accessor: ServicesAccessor, resource: unknown) {
const terminalService = accessor.get(ITerminalService);
const castedResource = URI.isUri(resource) ? resource : undefined;
const instance = terminalService.getInstanceFromResource(castedResource) || terminalService.activeInstance;
instance?.changeColor();
}
});
registerAction2(class extends Action2 {
Expand Down Expand Up @@ -832,10 +838,14 @@ export function registerTerminalActions() {
precondition: TerminalContextKeys.processSupported
});
}
async run(accessor: ServicesAccessor) {
return accessor.get(ITerminalService).activeInstance?.rename();
async run(accessor: ServicesAccessor, resource: unknown) {
const terminalService = accessor.get(ITerminalService);
const castedResource = URI.isUri(resource) ? resource : undefined;
const instance = terminalService.getInstanceFromResource(castedResource) || terminalService.activeInstance;
instance?.rename();
}
});

registerAction2(class extends Action2 {
constructor() {
super({
Expand Down Expand Up @@ -2046,12 +2056,20 @@ export function refreshTerminalActions(detectedProfiles: ITerminalProfile[]) {
}
async run(accessor: ServicesAccessor, eventOrOptionsOrProfile: MouseEvent | ICreateTerminalOptions | ITerminalProfile | { profileName: string } | undefined, profile?: ITerminalProfile) {
const terminalService = accessor.get(ITerminalService);

if (!terminalService.isProcessSupportRegistered) {
return;
}

const terminalGroupService = accessor.get(ITerminalGroupService);
const workspaceContextService = accessor.get(IWorkspaceContextService);
const commandService = accessor.get(ICommandService);

let event: MouseEvent | PointerEvent | KeyboardEvent | undefined;
let options: ICreateTerminalOptions | undefined;
let instance: ITerminalInstance | undefined;
let cwd: string | URI | undefined;

if (typeof eventOrOptionsOrProfile === 'object' && eventOrOptionsOrProfile && 'profileName' in eventOrOptionsOrProfile) {
const config = terminalService.availableProfiles.find(profile => profile.profileName === eventOrOptionsOrProfile.profileName);
if (!config) {
Expand All @@ -2065,47 +2083,43 @@ export function refreshTerminalActions(detectedProfiles: ITerminalProfile[]) {
options = convertOptionsOrProfileToOptions(eventOrOptionsOrProfile);
}

const folders = workspaceContextService.getWorkspace().folders;
// split terminal
if (event && (event.altKey || event.ctrlKey)) {
const parentTerminal = terminalService.activeInstance;
if (parentTerminal) {
const cwd = await getCwdForSplit(terminalService.configHelper, parentTerminal);
cwd = await getCwdForSplit(terminalService.configHelper, parentTerminal);
await terminalService.createTerminal({ location: { parentTerminal }, config: options?.config, cwd });
return;
}
}

if (terminalService.isProcessSupportRegistered) {
let instance: ITerminalInstance | undefined;
let cwd: string | URI | undefined;
if (folders.length > 1) {
// multi-root workspace, create root picker
const options: IPickOptions<IQuickPickItem> = {
placeHolder: localize('workbench.action.terminal.newWorkspacePlaceholder', "Select current working directory for new terminal")
};
const workspace = await commandService.executeCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, [options]);
if (!workspace) {
// Don't create the instance if the workspace picker was canceled
return;
}
cwd = workspace.uri;
const folders = workspaceContextService.getWorkspace().folders;
if (folders.length > 1) {
// multi-root workspace, create root picker
const options: IPickOptions<IQuickPickItem> = {
placeHolder: localize('workbench.action.terminal.newWorkspacePlaceholder', "Select current working directory for new terminal")
};
const workspace = await commandService.executeCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, [options]);
if (!workspace) {
// Don't create the instance if the workspace picker was canceled
return;
}
cwd = workspace.uri;
}

if (options) {
instance = await terminalService.createTerminal(options);
} else {
instance = await terminalService.showProfileQuickPick('createInstance', cwd);
}
if (options) {
instance = await terminalService.createTerminal(options);
} else {
instance = await terminalService.showProfileQuickPick('createInstance', cwd);
}

if (instance) {
terminalService.setActiveInstance(instance);
if (instance.target === TerminalLocation.Editor) {
await instance.focusWhenReady(true);
} else {
await terminalGroupService.showPanel(true);
}
if (instance) {
terminalService.setActiveInstance(instance);
if (instance.target === TerminalLocation.Editor) {
await instance.focusWhenReady(true);
} else {
await terminalGroupService.showPanel(true);
}

}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ export class TerminalEditorInput extends EditorInput {
}
}

public override getDescription(): string | undefined {

This comment has been minimized.

Copy link
@meganrogge

meganrogge Sep 7, 2021

Author Contributor

note this is only displayed when workbench.editor.labelFormat is long. not sure if we want to override that?

return this._terminalInstance?.shellLaunchConfig.description;
}

public override toUntyped(): IUntypedEditorInput {
return {
resource: this.resource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { DeserializedTerminalEditorInput } from 'vs/workbench/contrib/terminal/b
import { getInstanceFromResource, parseTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
import { ILocalTerminalService, IOffProcessTerminalService } from 'vs/workbench/contrib/terminal/common/terminal';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IEditorService, ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';

Expand Down Expand Up @@ -163,13 +163,14 @@ export class TerminalEditorService extends Disposable implements ITerminalEditor
if (resource) {
await this._editorService.openEditor({
resource,
description: instance.shellLaunchConfig.description,
options:
{
pinned: true,
forceReload: true,
preserveFocus: editorOptions?.preserveFocus
}
}, editorOptions?.viewColumn);
}, editorOptions?.viewColumn || ACTIVE_GROUP);
}
}

Expand Down Expand Up @@ -230,7 +231,7 @@ export class TerminalEditorService extends Disposable implements ITerminalEditor
this._onDidChangeInstances.fire();
}

getInstanceFromResource(resource: URI | undefined): ITerminalInstance | undefined {
getInstanceFromResource(resource?: URI): ITerminalInstance | undefined {
return getInstanceFromResource(this.instances, resource);
}

Expand All @@ -247,6 +248,7 @@ export class TerminalEditorService extends Disposable implements ITerminalEditor
if (resource) {
this._editorService.openEditor({
resource: URI.revive(resource),
description: instance.shellLaunchConfig.description,
options:
{
pinned: true,
Expand Down

0 comments on commit 6252610

Please sign in to comment.