Skip to content

Commit

Permalink
Workbench editor renames (#91943)
Browse files Browse the repository at this point in the history
* IEditor => IEditorPane

* More panes:
* IVisibleEditor => IVisibleEditorPane
* ITextEditor => ITextEditorPane
* ITextDiffEditor => ITextDiffEditorPane

* imports - remove type alias

* More pane renames
* IEditorService#activeControl => activeEditorPane
* IEditorService#visibleControls => visibleEditorPanes

* More editor renames
* activeTextEditorWidget => activeTextEditorControl
* visibleTextEditorWidgets => visibleTextEditorControls
  • Loading branch information
bpasero authored Mar 3, 2020
1 parent 6829e20 commit 418d197
Show file tree
Hide file tree
Showing 81 changed files with 750 additions and 802 deletions.
20 changes: 10 additions & 10 deletions src/vs/workbench/api/browser/mainThreadDocumentsAndEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { MainThreadTextEditors } from 'vs/workbench/api/browser/mainThreadEditor
import { ExtHostContext, ExtHostDocumentsAndEditorsShape, IDocumentsAndEditorsDelta, IExtHostContext, IModelAddedData, ITextEditorAddData, MainContext } from 'vs/workbench/api/common/extHost.protocol';
import { EditorViewColumn, editorGroupToViewColumn } from 'vs/workbench/api/common/shared/editor';
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
import { IEditor as IWorkbenchEditor } from 'vs/workbench/common/editor';
import { IEditorPane } from 'vs/workbench/common/editor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
Expand Down Expand Up @@ -290,11 +290,11 @@ class MainThreadDocumentAndEditorStateComputer {
}

private _getActiveEditorFromEditorPart(): IEditor | undefined {
let result = this._editorService.activeTextEditorWidget;
if (isDiffEditor(result)) {
result = result.getModifiedEditor();
let activeTextEditorControl = this._editorService.activeTextEditorControl;
if (isDiffEditor(activeTextEditorControl)) {
activeTextEditorControl = activeTextEditorControl.getModifiedEditor();
}
return result;
return activeTextEditorControl;
}
}

Expand Down Expand Up @@ -435,17 +435,17 @@ export class MainThreadDocumentsAndEditors {
}

private _findEditorPosition(editor: MainThreadTextEditor): EditorViewColumn | undefined {
for (const workbenchEditor of this._editorService.visibleControls) {
if (editor.matches(workbenchEditor)) {
return editorGroupToViewColumn(this._editorGroupService, workbenchEditor.group);
for (const editorPane of this._editorService.visibleEditorPanes) {
if (editor.matches(editorPane)) {
return editorGroupToViewColumn(this._editorGroupService, editorPane.group);
}
}
return undefined;
}

findTextEditorIdFor(inputEditor: IWorkbenchEditor): string | undefined {
findTextEditorIdFor(editorPane: IEditorPane): string | undefined {
for (const [id, editor] of this._textEditors) {
if (editor.matches(inputEditor)) {
if (editor.matches(editorPane)) {
return id;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/browser/mainThreadEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ISingleEditOperation, ITextModel, ITextModelUpdateOptions, IIdentifiedS
import { IModelService } from 'vs/editor/common/services/modelService';
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
import { IApplyEditsOptions, IEditorPropertiesChangeData, IResolvedTextEditorConfiguration, ITextEditorConfigurationUpdate, IUndoStopOptions, TextEditorRevealType } from 'vs/workbench/api/common/extHost.protocol';
import { IEditor } from 'vs/workbench/common/editor';
import { IEditorPane } from 'vs/workbench/common/editor';
import { withNullAsUndefined } from 'vs/base/common/types';
import { equals } from 'vs/base/common/arrays';

Expand Down Expand Up @@ -413,7 +413,7 @@ export class MainThreadTextEditor {
return false;
}

public matches(editor: IEditor): boolean {
public matches(editor: IEditorPane): boolean {
if (!editor) {
return false;
}
Expand Down
14 changes: 7 additions & 7 deletions src/vs/workbench/api/browser/mainThreadEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {

private _getTextEditorPositionData(): ITextEditorPositionData {
const result: ITextEditorPositionData = Object.create(null);
for (let workbenchEditor of this._editorService.visibleControls) {
const id = this._documentsAndEditors.findTextEditorIdFor(workbenchEditor);
for (let editorPane of this._editorService.visibleEditorPanes) {
const id = this._documentsAndEditors.findTextEditorIdFor(editorPane);
if (id) {
result[id] = editorGroupToViewColumn(this._editorGroupService, workbenchEditor.group);
result[id] = editorGroupToViewColumn(this._editorGroupService, editorPane.group);
}
}
return result;
Expand Down Expand Up @@ -151,10 +151,10 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
async $tryHideEditor(id: string): Promise<void> {
const mainThreadEditor = this._documentsAndEditors.getEditor(id);
if (mainThreadEditor) {
const editors = this._editorService.visibleControls;
for (let editor of editors) {
if (mainThreadEditor.matches(editor)) {
return editor.group.closeEditor(editor.input);
const editorPanes = this._editorService.visibleEditorPanes;
for (let editorPane of editorPanes) {
if (mainThreadEditor.matches(editorPane)) {
return editorPane.group.closeEditor(editorPane.input);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/browser/mainThreadWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
return;
}

const activeInput = this._editorService.activeControl && this._editorService.activeControl.input;
const activeInput = this._editorService.activeEditorPane?.input;
const viewStates: extHostProtocol.WebviewPanelViewStateData = {};

const updateViewStatesForInput = (group: IEditorGroup, topLevelInput: IEditorInput, editorInput: IEditorInput) => {
Expand Down
16 changes: 8 additions & 8 deletions src/vs/workbench/browser/contextkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ export class WorkbenchContextKeysHandler extends Disposable {

private updateEditorContextKeys(): void {
const activeGroup = this.editorGroupService.activeGroup;
const activeControl = this.editorService.activeControl;
const visibleEditors = this.editorService.visibleControls;
const activeEditorPane = this.editorService.activeEditorPane;
const visibleEditorPanes = this.editorService.visibleEditorPanes;

this.textCompareEditorActiveContext.set(activeControl?.getId() === TEXT_DIFF_EDITOR_ID);
this.textCompareEditorVisibleContext.set(visibleEditors.some(control => control.getId() === TEXT_DIFF_EDITOR_ID));
this.textCompareEditorActiveContext.set(activeEditorPane?.getId() === TEXT_DIFF_EDITOR_ID);
this.textCompareEditorVisibleContext.set(visibleEditorPanes.some(editorPane => editorPane.getId() === TEXT_DIFF_EDITOR_ID));

if (visibleEditors.length > 0) {
if (visibleEditorPanes.length > 0) {
this.editorsVisibleContext.set(true);
} else {
this.editorsVisibleContext.reset();
Expand All @@ -204,9 +204,9 @@ export class WorkbenchContextKeysHandler extends Disposable {
this.activeEditorGroupIndex.set(activeGroup.index + 1); // not zero-indexed
this.activeEditorGroupLast.set(activeGroup.index === groupCount - 1);

if (activeControl) {
this.activeEditorContext.set(activeControl.getId());
this.activeEditorIsReadonly.set(activeControl.input.isReadonly());
if (activeEditorPane) {
this.activeEditorContext.set(activeEditorPane.getId());
this.activeEditorIsReadonly.set(activeEditorPane.input.isReadonly());
} else {
this.activeEditorContext.reset();
this.activeEditorIsReadonly.reset();
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/browser/dnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:

// Try to find editor view state from the visible editors that match given resource
let viewState: IEditorViewState | undefined = undefined;
const textEditorWidgets = editorService.visibleTextEditorWidgets;
for (const textEditorWidget of textEditorWidgets) {
if (isCodeEditor(textEditorWidget)) {
const model = textEditorWidget.getModel();
const textEditorControls = editorService.visibleTextEditorControls;
for (const textEditorControl of textEditorControls) {
if (isCodeEditor(textEditorControl)) {
const model = textEditorControl.getModel();
if (model?.uri?.toString() === file.resource.toString()) {
viewState = withNullAsUndefined(textEditorWidget.saveViewState());
viewState = withNullAsUndefined(textEditorControl.saveViewState());
break;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/vs/workbench/browser/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,22 +707,22 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
editor.updateOptions({ lineNumbers });
};

const editorWidgetSet = this.state.zenMode.editorWidgetSet;
const editorControlSet = this.state.zenMode.editorWidgetSet;
if (!lineNumbers) {
// Reset line numbers on all editors visible and non-visible
for (const editor of editorWidgetSet) {
for (const editor of editorControlSet) {
setEditorLineNumbers(editor);
}
editorWidgetSet.clear();
editorControlSet.clear();
} else {
this.editorService.visibleTextEditorWidgets.forEach(editor => {
if (!editorWidgetSet.has(editor)) {
editorWidgetSet.add(editor);
this.state.zenMode.transitionDisposables.add(editor.onDidDispose(() => {
editorWidgetSet.delete(editor);
this.editorService.visibleTextEditorControls.forEach(editorControl => {
if (!editorControlSet.has(editorControl)) {
editorControlSet.add(editorControl);
this.state.zenMode.transitionDisposables.add(editorControl.onDidDispose(() => {
editorControlSet.delete(editorControl);
}));
}
setEditorLineNumbers(editor);
setEditorLineNumbers(editorControl);
});
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/baseEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { Panel } from 'vs/workbench/browser/panel';
import { EditorInput, EditorOptions, IEditor, GroupIdentifier, IEditorMemento } from 'vs/workbench/common/editor';
import { EditorInput, EditorOptions, IEditorPane, GroupIdentifier, IEditorMemento } from 'vs/workbench/common/editor';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { CancellationToken } from 'vs/base/common/cancellation';
Expand Down Expand Up @@ -33,7 +33,7 @@ import { indexOfPath } from 'vs/base/common/extpath';
*
* This class is only intended to be subclassed and not instantiated.
*/
export abstract class BaseEditor extends Panel implements IEditor {
export abstract class BaseEditor extends Panel implements IEditorPane {

private static readonly EDITOR_MEMENTOS: Map<string, EditorMemento<any>> = new Map<string, EditorMemento<any>>();

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/binaryDiffEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class BinaryResourceDiffEditor extends SideBySideEditor {
}

getMetadata(): string | undefined {
const master = this.masterEditor;
const details = this.detailsEditor;
const master = this.masterEditorPane;
const details = this.detailsEditorPane;

if (master instanceof BaseBinaryResourceEditor && details instanceof BaseBinaryResourceEditor) {
return nls.localize('metadataDiff', "{0} ↔ {1}", details.getMetadata(), master.getMetadata());
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ export class BreadcrumbsControl {
}

private _getActiveCodeEditor(): ICodeEditor | undefined {
if (!this._editorGroup.activeControl) {
if (!this._editorGroup.activeEditorPane) {
return undefined;
}
let control = this._editorGroup.activeControl.getControl();
let control = this._editorGroup.activeEditorPane.getControl();
let editor: ICodeEditor | undefined;
if (isCodeEditor(control)) {
editor = control as ICodeEditor;
Expand Down Expand Up @@ -713,8 +713,8 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
widget.setFocused(undefined);
widget.setSelection(undefined);
if (groups.activeGroup.activeControl) {
groups.activeGroup.activeControl.focus();
if (groups.activeGroup.activeEditorPane) {
groups.activeGroup.activeEditorPane.focus();
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/parts/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { GroupIdentifier, IWorkbenchEditorConfiguration, EditorOptions, TextEditorOptions, IEditorInput, IEditorIdentifier, IEditorCloseEvent, IEditor, IEditorPartOptions, IEditorPartOptionsChangeEvent, EditorInput } from 'vs/workbench/common/editor';
import { GroupIdentifier, IWorkbenchEditorConfiguration, EditorOptions, TextEditorOptions, IEditorInput, IEditorIdentifier, IEditorCloseEvent, IEditorPane, IEditorPartOptions, IEditorPartOptionsChangeEvent, EditorInput } from 'vs/workbench/common/editor';
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
import { IEditorGroup, GroupDirection, IAddGroupOptions, IMergeGroupOptions, GroupsOrder, GroupsArrangement } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IDisposable } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -73,7 +73,7 @@ export interface IEditorOpeningEvent extends IEditorIdentifier {
* to return a promise that resolves to `undefined` to prevent the opening
* alltogether.
*/
prevent(callback: () => undefined | Promise<IEditor | undefined>): void;
prevent(callback: () => undefined | Promise<IEditorPane | undefined>): void;
}

export interface IEditorGroupsAccessor {
Expand Down Expand Up @@ -126,7 +126,7 @@ export interface IEditorGroupView extends IDisposable, ISerializableView, IEdito
}

export function getActiveTextEditorOptions(group: IEditorGroup, expectedActiveEditor?: IEditorInput, presetOptions?: EditorOptions): EditorOptions {
const activeGroupCodeEditor = group.activeControl ? getCodeEditor(group.activeControl.getControl()) : undefined;
const activeGroupCodeEditor = group.activeEditorPane ? getCodeEditor(group.activeEditorPane.getControl()) : undefined;
if (activeGroupCodeEditor) {
if (!expectedActiveEditor || expectedActiveEditor.matches(group.activeEditor)) {
return TextEditorOptions.fromEditor(activeGroupCodeEditor, presetOptions);
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/browser/parts/editor/editorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@ export class RevertAndCloseEditorAction extends Action {
}

async run(): Promise<void> {
const activeControl = this.editorService.activeControl;
if (activeControl) {
const editor = activeControl.input;
const group = activeControl.group;
const activeEditorPane = this.editorService.activeEditorPane;
if (activeEditorPane) {
const editor = activeEditorPane.input;
const group = activeEditorPane.group;

// first try a normal revert where the contents of the editor are restored
try {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/parts/editor/editorAutoSave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution
this.lastActiveEditorControlDisposable.clear();

// Listen to focus changes on control for auto save
const activeEditorControl = this.editorService.activeControl;
if (activeEditor && activeEditorControl) {
this.lastActiveEditorControlDisposable.add(activeEditorControl.onDidBlur(() => {
const activeEditorPane = this.editorService.activeEditorPane;
if (activeEditor && activeEditorPane) {
this.lastActiveEditorControlDisposable.add(activeEditorPane.onDidBlur(() => {
this.maybeTriggerAutoSave(SaveReason.FOCUS_CHANGE, { groupId: activeGroup.id, editor: activeEditor });
}));
}
Expand Down
28 changes: 13 additions & 15 deletions src/vs/workbench/browser/parts/editor/editorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
import * as types from 'vs/base/common/types';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { TextCompareEditorVisibleContext, EditorInput, IEditorIdentifier, IEditorCommandsContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, CloseDirection, IEditor, IEditorInput, IVisibleEditor } from 'vs/workbench/common/editor';
import { TextCompareEditorVisibleContext, EditorInput, IEditorIdentifier, IEditorCommandsContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, CloseDirection, IEditorInput, IVisibleEditorPane } from 'vs/workbench/common/editor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { TextDiffEditor } from 'vs/workbench/browser/parts/editor/textDiffEditor';
Expand Down Expand Up @@ -120,18 +120,18 @@ function moveActiveEditor(args: ActiveEditorMoveArguments = Object.create(null),
args.by = args.by || 'tab';
args.value = typeof args.value === 'number' ? args.value : 1;

const activeControl = accessor.get(IEditorService).activeControl;
if (activeControl) {
const activeEditorPane = accessor.get(IEditorService).activeEditorPane;
if (activeEditorPane) {
switch (args.by) {
case 'tab':
return moveActiveTab(args, activeControl, accessor);
return moveActiveTab(args, activeEditorPane, accessor);
case 'group':
return moveActiveEditorToGroup(args, activeControl, accessor);
return moveActiveEditorToGroup(args, activeEditorPane, accessor);
}
}
}

function moveActiveTab(args: ActiveEditorMoveArguments, control: IVisibleEditor, accessor: ServicesAccessor): void {
function moveActiveTab(args: ActiveEditorMoveArguments, control: IVisibleEditorPane, accessor: ServicesAccessor): void {
const group = control.group;
let index = group.getIndexOfEditor(control.input);
switch (args.to) {
Expand Down Expand Up @@ -159,7 +159,7 @@ function moveActiveTab(args: ActiveEditorMoveArguments, control: IVisibleEditor,
group.moveEditor(control.input, group, { index });
}

function moveActiveEditorToGroup(args: ActiveEditorMoveArguments, control: IVisibleEditor, accessor: ServicesAccessor): void {
function moveActiveEditorToGroup(args: ActiveEditorMoveArguments, control: IVisibleEditorPane, accessor: ServicesAccessor): void {
const editorGroupService = accessor.get(IEditorGroupsService);
const configurationService = accessor.get(IConfigurationService);

Expand Down Expand Up @@ -261,7 +261,7 @@ function registerDiffEditorCommands(): void {

function navigateInDiffEditor(accessor: ServicesAccessor, next: boolean): void {
const editorService = accessor.get(IEditorService);
const candidates = [editorService.activeControl, ...editorService.visibleControls].filter(e => e instanceof TextDiffEditor);
const candidates = [editorService.activeEditorPane, ...editorService.visibleEditorPanes].filter(e => e instanceof TextDiffEditor);

if (candidates.length > 0) {
const navigator = (<TextDiffEditor>candidates[0]).getDiffNavigator();
Expand Down Expand Up @@ -317,9 +317,9 @@ function registerDiffEditorCommands(): void {
function registerOpenEditorAtIndexCommands(): void {
const openEditorAtIndex: ICommandHandler = (accessor: ServicesAccessor, editorIndex: number): void => {
const editorService = accessor.get(IEditorService);
const activeControl = editorService.activeControl;
if (activeControl) {
const editor = activeControl.group.getEditorByIndex(editorIndex);
const activeEditorPane = editorService.activeEditorPane;
if (activeEditorPane) {
const editor = activeEditorPane.group.getEditorByIndex(editorIndex);
if (editor) {
editorService.openEditor(editor);
}
Expand Down Expand Up @@ -708,21 +708,19 @@ function getCommandsContext(resourceOrContext: URI | IEditorCommandsContext, con
return undefined;
}

function resolveCommandsContext(editorGroupService: IEditorGroupsService, context?: IEditorCommandsContext): { group: IEditorGroup, editor?: IEditorInput, control?: IEditor } {
function resolveCommandsContext(editorGroupService: IEditorGroupsService, context?: IEditorCommandsContext): { group: IEditorGroup, editor?: IEditorInput } {

// Resolve from context
let group = context && typeof context.groupId === 'number' ? editorGroupService.getGroup(context.groupId) : undefined;
let editor = group && context && typeof context.editorIndex === 'number' ? types.withNullAsUndefined(group.getEditorByIndex(context.editorIndex)) : undefined;
let control = group ? group.activeControl : undefined;

// Fallback to active group as needed
if (!group) {
group = editorGroupService.activeGroup;
editor = <EditorInput>group.activeEditor;
control = group.activeControl;
}

return { group, editor, control };
return { group, editor };
}

export function getMultiSelectedEditorContexts(editorContext: IEditorCommandsContext | undefined, listService: IListService, editorGroupService: IEditorGroupsService): IEditorCommandsContext[] {
Expand Down
Loading

0 comments on commit 418d197

Please sign in to comment.