add copy and try a few other things
This commit is contained in:
parent
0c226cd099
commit
50b6b81f20
5 changed files with 43 additions and 23 deletions
|
@ -37,10 +37,11 @@ import { isIOS, isWindows } from 'vs/base/common/platform';
|
|||
import { setupTerminalMenus } from 'vs/workbench/contrib/terminal/browser/terminalMenus';
|
||||
import { TerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminalInstanceService';
|
||||
import { registerTerminalPlatformConfiguration } from 'vs/platform/terminal/common/terminalPlatformConfiguration';
|
||||
import { TerminalEditor, TerminalInputSerializer } from 'vs/workbench/contrib/terminal/browser/terminalEditor';
|
||||
import { EditorExtensions, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
|
||||
import { EditorDescriptor, IEditorRegistry } from 'vs/workbench/browser/editor';
|
||||
import { TerminalInputSerializer, TerminalEditor } from 'vs/workbench/contrib/terminal/browser/terminalEditor';
|
||||
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
|
||||
import { terminalStrings } from 'vs/workbench/contrib/terminal/common/terminalStrings';
|
||||
|
||||
// Register services
|
||||
registerSingleton(ITerminalService, TerminalService, true);
|
||||
|
@ -71,7 +72,7 @@ Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
|
|||
EditorDescriptor.create(
|
||||
TerminalEditor,
|
||||
TerminalEditor.ID,
|
||||
nls.localize('terminal.editor.label', "Terminal")
|
||||
terminalStrings.terminalEditor.value
|
||||
),
|
||||
[
|
||||
new SyncDescriptor(TerminalEditorInput)
|
||||
|
|
|
@ -204,10 +204,11 @@ export function registerTerminalActions() {
|
|||
});
|
||||
}
|
||||
async run(accessor: ServicesAccessor) {
|
||||
const terminalService = accessor.get(ITerminalService);
|
||||
const editorService = accessor.get(IEditorService);
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const input: TerminalEditorInput = instantiationService.createInstance(TerminalEditorInput);
|
||||
await editorService.openEditor(input, { pinned: true });
|
||||
const input = TerminalEditorInput.copy(terminalService, instantiationService);
|
||||
await editorService.openEditor(input, { pinned: true, forceReload: true });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -4,13 +4,14 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Dimension } from 'vs/base/browser/dom';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { IEditorOptions } from 'vs/platform/editor/common/editor';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
|
||||
import { IEditorInputSerializer } from 'vs/workbench/common/editor';
|
||||
import { ITerminalInstance, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
import { IEditorInputSerializer, IEditorOpenContext } from 'vs/workbench/common/editor';
|
||||
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
|
||||
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
|
||||
|
@ -19,41 +20,45 @@ export class TerminalEditor extends EditorPane {
|
|||
|
||||
public static readonly ID = 'terminalEditor';
|
||||
|
||||
private _instance: ITerminalInstance | undefined;
|
||||
private _parentElement: HTMLElement | undefined;
|
||||
private _isAttached: boolean = false;
|
||||
private _editorInput!: TerminalEditorInput;
|
||||
|
||||
|
||||
override async setInput(newInput: TerminalEditorInput, options: IEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken) {
|
||||
this._editorInput = newInput;
|
||||
await super.setInput(newInput, options, context, token);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
protected createEditor(parent: HTMLElement): void {
|
||||
this._parentElement = parent;
|
||||
this._instance = this._terminalService.createInstance({});
|
||||
}
|
||||
|
||||
layout(dimension: Dimension): void {
|
||||
if (this._instance) {
|
||||
this._instance.layout(dimension);
|
||||
if (this._editorInput?.terminalInstance) {
|
||||
this._editorInput.terminalInstance.layout(dimension);
|
||||
}
|
||||
}
|
||||
|
||||
override setVisible(visible: boolean, group?: IEditorGroup): void {
|
||||
super.setVisible(visible, group);
|
||||
|
||||
if (!this._instance) {
|
||||
if (!this._editorInput?.terminalInstance) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._isAttached) {
|
||||
this._instance.attachToElement(this._parentElement!);
|
||||
this._editorInput.terminalInstance.attachToElement(this._parentElement!);
|
||||
this._isAttached = true;
|
||||
}
|
||||
this._instance.setVisible(visible);
|
||||
this._editorInput.terminalInstance.setVisible(visible);
|
||||
}
|
||||
|
||||
constructor(
|
||||
@ITelemetryService telemetryService: ITelemetryService,
|
||||
@IThemeService themeService: IThemeService,
|
||||
@IStorageService storageService: IStorageService,
|
||||
@ITerminalService private readonly _terminalService: ITerminalService
|
||||
) {
|
||||
|
||||
super(TerminalEditor.ID, telemetryService, themeService, storageService);
|
||||
|
@ -70,9 +75,6 @@ export class TerminalInputSerializer implements IEditorInputSerializer {
|
|||
}
|
||||
|
||||
public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): TerminalEditorInput {
|
||||
try {
|
||||
return new TerminalEditorInput();
|
||||
} catch { }
|
||||
return new TerminalEditorInput();
|
||||
throw new Error('not implemented');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,29 +5,41 @@
|
|||
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
||||
import { terminalStrings } from 'vs/workbench/contrib/terminal/common/terminalStrings';
|
||||
import { ITerminalInstance, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
|
||||
export const terminalInputId = 'workbench.editors.terminal';
|
||||
export class TerminalEditorInput extends EditorInput {
|
||||
|
||||
static readonly ID = terminalInputId;
|
||||
static readonly RESOURCE = URI.from({ scheme: Schemas.vscodeTerminal });
|
||||
|
||||
override get typeId(): string {
|
||||
return TerminalEditorInput.ID;
|
||||
}
|
||||
|
||||
get resource(): URI | undefined {
|
||||
return TerminalEditorInput.RESOURCE;
|
||||
private readonly _terminalInstance: ITerminalInstance;
|
||||
|
||||
get terminalInstance(): ITerminalInstance {
|
||||
return this._terminalInstance!;
|
||||
}
|
||||
|
||||
get resource(): URI {
|
||||
return URI.from({ scheme: Schemas.vscodeTerminal, path: this._terminalInstance!.instanceId.toString() });
|
||||
}
|
||||
|
||||
constructor(
|
||||
instance: ITerminalInstance
|
||||
) {
|
||||
super();
|
||||
this._terminalInstance = instance;
|
||||
}
|
||||
|
||||
static copy(terminalService: ITerminalService, instantiationService: IInstantiationService): TerminalEditorInput {
|
||||
return new TerminalEditorInput(terminalService.createInstance({}));
|
||||
}
|
||||
|
||||
override getName() {
|
||||
return terminalStrings.terminalEditorInput.value;
|
||||
return this.terminalInstance.title;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,5 +38,9 @@ export const terminalStrings = {
|
|||
terminalEditorInput: {
|
||||
value: localize('terminal.editor.input', "Terminal"),
|
||||
original: 'Terminal'
|
||||
},
|
||||
terminalEditor: {
|
||||
value: localize('terminal.editor.label', "Terminal"),
|
||||
original: 'Terminal Editor'
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue