未验证 提交 c2d0a69f 编写于 作者: L Logan Ramos 提交者: GitHub

Implements a starting tab reading API (#131998)

* Clean up proposed.d.ts

* More API Polish

* Allow resource to be undefined

* Fix hygiene

* Address feedback

* Remove unnecessary iteration

* Use index from map
上级 45a1f368
......@@ -2291,20 +2291,58 @@ declare module 'vscode' {
//#region https://github.com/Microsoft/vscode/issues/15178
// TODO@API must be a class
// TODO@API @lramos15 Call this XYZTabs
export interface OpenEditorInfo {
//viewColumn: ViewColumn; // todo @lramos15
name: string;
resource: Uri; // make optional @lramos15
isActive: boolean;
/**
* Represents a tab within the window
*/
export interface Tab {
/**
* The text displayed on the tab
*/
readonly label: string;
/**
* The position of the tab
*/
readonly viewColumn: ViewColumn;
/**
* The resource represented by the tab if availble.
* Note: Not all editor types have a resource associated with them
*/
readonly resource?: Uri;
/**
* Whether or not the tab is currently active
* Dictated by being the selected tab in the active group
*/
readonly isActive: boolean;
}
export namespace window {
export const openEditors: ReadonlyArray<OpenEditorInfo>;
/**
* A list of all opened tabs
* Ordered from left to right
*/
export const tabs: readonly Tab[];
/**
* The currently active tab
* Undefined if no tabs are currently opened
*/
export const activeTab: Tab | undefined;
/**
* An {@link Event} which fires when the array of {@link window.tabs tabs}
* has changed.
*/
export const onDidChangeTabs: Event<readonly Tab[]>;
/**
* An {@link Event} which fires when the {@link window.activeTab activeTab}
* has changed.
*/
export const onDidChangeActiveTab: Event<Tab | undefined>;
// todo@API @lramos15 proper event type {}
export const onDidChangeOpenEditors: Event<void>;
}
//#endregion
......
......@@ -4,17 +4,13 @@
*--------------------------------------------------------------------------------------------*/
import { DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { ExtHostContext, IExtHostEditorTabsShape, IExtHostContext, MainContext, IEditorTabDto } from 'vs/workbench/api/common/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { EditorResourceAccessor, Verbosity } from 'vs/workbench/common/editor';
import { EditorResourceAccessor } from 'vs/workbench/common/editor';
import { editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
export interface ITabInfo {
name: string;
resource: URI;
}
@extHostNamedCustomer(MainContext.MainThreadEditorTabs)
export class MainThreadEditorTabs {
......@@ -42,13 +38,13 @@ export class MainThreadEditorTabs {
const tabs: IEditorTabDto[] = [];
for (const group of this._editorGroupsService.groups) {
for (const editor of group.editors) {
if (editor.isDisposed() || !editor.resource) {
if (editor.isDisposed()) {
continue;
}
tabs.push({
group: group.id,
name: editor.getTitle(Verbosity.SHORT) ?? '',
resource: EditorResourceAccessor.getOriginalUri(editor) ?? editor.resource,
viewColumn: editorGroupToColumn(this._editorGroupsService, group),
label: editor.getName(),
resource: EditorResourceAccessor.getCanonicalUri(editor),
isActive: (this._editorGroupsService.activeGroup === group) && group.isActive(editor)
});
}
......
......@@ -731,14 +731,22 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
checkProposedApiEnabled(extension);
return extHostUriOpeners.registerExternalUriOpener(extension.identifier, id, opener, metadata);
},
get openEditors() {
get tabs() {
checkProposedApiEnabled(extension);
return extHostEditorTabs.tabs;
},
get onDidChangeOpenEditors() {
get activeTab() {
checkProposedApiEnabled(extension);
return extHostEditorTabs.activeTab;
},
get onDidChangeTabs() {
checkProposedApiEnabled(extension);
return extHostEditorTabs.onDidChangeTabs;
},
get onDidChangeActiveTab() {
checkProposedApiEnabled(extension);
return extHostEditorTabs.onDidChangeActiveTab;
},
getInlineCompletionItemController<T extends vscode.InlineCompletionItem>(provider: vscode.InlineCompletionItemProvider<T>): vscode.InlineCompletionController<T> {
checkProposedApiEnabled(extension);
return InlineCompletionController.get(provider);
......
......@@ -46,7 +46,7 @@ import { WorkspaceTrustRequestOptions } from 'vs/platform/workspace/common/works
import { ExtensionActivationReason } from 'vs/workbench/api/common/extHostExtensionActivator';
import { ExtHostInteractive } from 'vs/workbench/api/common/extHostInteractive';
import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
import { DebugConfigurationProviderTriggerKind } from 'vs/workbench/api/common/extHostTypes';
import { DebugConfigurationProviderTriggerKind, ViewColumn } from 'vs/workbench/api/common/extHostTypes';
import * as tasks from 'vs/workbench/api/common/shared/tasks';
import { TreeDataTransferDTO } from 'vs/workbench/api/common/shared/treeDataTransfer';
import { SaveReason } from 'vs/workbench/common/editor';
......@@ -640,9 +640,9 @@ export interface MainThreadEditorTabsShape extends IDisposable {
}
export interface IEditorTabDto {
group: number;
name: string;
resource: UriComponents;
viewColumn: ViewColumn;
label: string;
resource?: UriComponents;
isActive: boolean;
}
......
......@@ -8,18 +8,21 @@ import { IEditorTabDto, IExtHostEditorTabsShape } from 'vs/workbench/api/common/
import { URI } from 'vs/base/common/uri';
import { Emitter, Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ViewColumn } from 'vs/workbench/api/common/extHostTypes';
export interface IEditorTab {
name: string;
group: number;
resource: vscode.Uri
label: string;
viewColumn: ViewColumn;
resource?: vscode.Uri
isActive: boolean
}
export interface IExtHostEditorTabs extends IExtHostEditorTabsShape {
readonly _serviceBrand: undefined;
tabs: readonly IEditorTab[];
onDidChangeTabs: Event<void>;
activeTab: IEditorTab | undefined;
onDidChangeActiveTab: Event<IEditorTab | undefined>;
onDidChangeTabs: Event<IEditorTab[]>;
}
export const IExtHostEditorTabs = createDecorator<IExtHostEditorTabs>('IExtHostEditorTabs');
......@@ -27,24 +30,38 @@ export const IExtHostEditorTabs = createDecorator<IExtHostEditorTabs>('IExtHostE
export class ExtHostEditorTabs implements IExtHostEditorTabs {
readonly _serviceBrand: undefined;
private readonly _onDidChangeTabs = new Emitter<void>();
readonly onDidChangeTabs: Event<void> = this._onDidChangeTabs.event;
private readonly _onDidChangeTabs = new Emitter<IEditorTab[]>();
readonly onDidChangeTabs: Event<IEditorTab[]> = this._onDidChangeTabs.event;
private readonly _onDidChangeActiveTab = new Emitter<IEditorTab | undefined>();
readonly onDidChangeActiveTab: Event<IEditorTab | undefined> = this._onDidChangeActiveTab.event;
private _tabs: IEditorTab[] = [];
private _activeTab: IEditorTab | undefined;
get tabs(): readonly IEditorTab[] {
return this._tabs;
}
get activeTab(): IEditorTab | undefined {
return this._activeTab;
}
$acceptEditorTabs(tabs: IEditorTabDto[]): void {
this._tabs = tabs.map(dto => {
return {
name: dto.name,
group: dto.group,
let activeIndex = -1;
this._tabs = tabs.map((dto, index) => {
if (dto.isActive) {
activeIndex = index;
}
return Object.freeze({
label: dto.label,
viewColumn: dto.viewColumn,
resource: URI.revive(dto.resource),
isActive: dto.isActive
};
});
});
this._onDidChangeTabs.fire();
this._activeTab = activeIndex === -1 ? undefined : this._tabs[activeIndex];
this._onDidChangeActiveTab.fire(this._activeTab);
this._onDidChangeTabs.fire(this._tabs);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册