mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user