mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
first steps towards Tab#input
This commit is contained in:
@@ -1325,6 +1325,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
WorkspaceTrustState: extHostTypes.WorkspaceTrustState,
|
||||
LanguageStatusSeverity: extHostTypes.LanguageStatusSeverity,
|
||||
QuickPickItemKind: extHostTypes.QuickPickItemKind,
|
||||
TextTabInput: extHostTypes.TextTabInput,
|
||||
TextDiffTabInput: extHostTypes.TextDiffTabInput,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -609,6 +609,51 @@ export interface ExtHostEditorInsetsShape {
|
||||
|
||||
//#region --- tabs model
|
||||
|
||||
export const enum TabInputKind {
|
||||
UnknownInput,
|
||||
TextInput,
|
||||
TextDiffInput,
|
||||
NotebookInput,
|
||||
NotebookDiffInput,
|
||||
CustomEditorInput
|
||||
}
|
||||
|
||||
export interface UnknownInputDto {
|
||||
kind: TabInputKind.UnknownInput;
|
||||
}
|
||||
|
||||
export interface TextInputDto {
|
||||
kind: TabInputKind.TextInput;
|
||||
uri: UriComponents;
|
||||
}
|
||||
|
||||
export interface TextDiffInputDto {
|
||||
kind: TabInputKind.TextDiffInput;
|
||||
original: UriComponents;
|
||||
modified: UriComponents;
|
||||
}
|
||||
|
||||
export interface NotebookInputDto {
|
||||
kind: TabInputKind.NotebookInput;
|
||||
notebookType: string;
|
||||
uri: UriComponents;
|
||||
}
|
||||
|
||||
export interface NotebookDiffInputDto {
|
||||
kind: TabInputKind.NotebookDiffInput;
|
||||
notebookType: string;
|
||||
original: UriComponents;
|
||||
modified: UriComponents;
|
||||
}
|
||||
|
||||
export interface CustomInputDto {
|
||||
kind: TabInputKind.CustomEditorInput;
|
||||
viewType: string;
|
||||
uri: UriComponents;
|
||||
}
|
||||
|
||||
export type AnyInputDto = UnknownInputDto | TextInputDto | TextDiffInputDto | NotebookInputDto | NotebookDiffInputDto | CustomInputDto;
|
||||
|
||||
export interface MainThreadEditorTabsShape extends IDisposable {
|
||||
// manage tabs: move, close, rearrange etc
|
||||
$moveTab(tabId: string, index: number, viewColumn: EditorGroupColumn): void;
|
||||
@@ -634,6 +679,7 @@ export interface IEditorTabDto {
|
||||
id: string;
|
||||
viewColumn: EditorGroupColumn;
|
||||
label: string;
|
||||
input: AnyInputDto;
|
||||
resource?: UriComponents;
|
||||
editorId?: string;
|
||||
isActive: boolean;
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
import type * as vscode from 'vscode';
|
||||
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
|
||||
import { IEditorTabDto, IEditorTabGroupDto, IExtHostEditorTabsShape, MainContext, MainThreadEditorTabsShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { IEditorTabDto, IEditorTabGroupDto, IExtHostEditorTabsShape, MainContext, MainThreadEditorTabsShape, TabInputKind } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ViewColumn } from 'vs/workbench/api/common/extHostTypes';
|
||||
import { TextDiffTabInput, TextTabInput, ViewColumn } from 'vs/workbench/api/common/extHostTypes';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
|
||||
export interface IExtHostEditorTabs extends IExtHostEditorTabsShape {
|
||||
@@ -19,17 +19,19 @@ export interface IExtHostEditorTabs extends IExtHostEditorTabsShape {
|
||||
|
||||
export const IExtHostEditorTabs = createDecorator<IExtHostEditorTabs>('IExtHostEditorTabs');
|
||||
|
||||
type AnyTab = TextTabInput | TextDiffTabInput;
|
||||
|
||||
class ExtHostEditorTab {
|
||||
private _apiObject: vscode.Tab | undefined;
|
||||
private _dto: IEditorTabDto;
|
||||
private _proxy: MainThreadEditorTabsShape;
|
||||
private _activeTabIdGetter: () => string;
|
||||
private _dto!: IEditorTabDto;
|
||||
private _input: AnyTab | undefined;
|
||||
private readonly _proxy: MainThreadEditorTabsShape;
|
||||
private readonly _activeTabIdGetter: () => string;
|
||||
|
||||
constructor(dto: IEditorTabDto, proxy: MainThreadEditorTabsShape, activeTabIdGetter: () => string) {
|
||||
this._dto = dto;
|
||||
this._proxy = proxy;
|
||||
this._activeTabIdGetter = activeTabIdGetter;
|
||||
this.acceptDtoUpdate(dto);
|
||||
}
|
||||
|
||||
get apiObject(): vscode.Tab {
|
||||
@@ -44,6 +46,9 @@ class ExtHostEditorTab {
|
||||
get label() {
|
||||
return that._dto.label;
|
||||
},
|
||||
get input() {
|
||||
return that._input;
|
||||
},
|
||||
get resource() {
|
||||
return URI.revive(that._dto.resource);
|
||||
},
|
||||
@@ -80,8 +85,19 @@ class ExtHostEditorTab {
|
||||
|
||||
acceptDtoUpdate(dto: IEditorTabDto) {
|
||||
this._dto = dto;
|
||||
this._input = this._initInput();
|
||||
}
|
||||
|
||||
private _initInput() {
|
||||
switch (this._dto.input.kind) {
|
||||
case TabInputKind.TextInput:
|
||||
return new TextTabInput(URI.revive(this._dto.input.uri));
|
||||
case TabInputKind.TextDiffInput:
|
||||
return new TextDiffTabInput(URI.revive(this._dto.input.original), URI.revive(this._dto.input.modified));
|
||||
// TODO@lramos15 support all the cases
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
class ExtHostEditorTabGroup {
|
||||
|
||||
@@ -3595,3 +3595,13 @@ export class TypeHierarchyItem {
|
||||
this.selectionRange = selectionRange;
|
||||
}
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
export class TextTabInput {
|
||||
constructor(readonly uri: URI) { }
|
||||
}
|
||||
|
||||
export class TextDiffTabInput {
|
||||
constructor(readonly original: URI, readonly modified: URI) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user