diff --git a/src/vs/workbench/browser/parts/editor/editorCommands.ts b/src/vs/workbench/browser/parts/editor/editorCommands.ts index 3ea08428627..fc5ba177a1a 100644 --- a/src/vs/workbench/browser/parts/editor/editorCommands.ts +++ b/src/vs/workbench/browser/parts/editor/editorCommands.ts @@ -8,11 +8,11 @@ import * as types from 'vs/base/common/types'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; -import { ActiveEditorMoveArguments, ActiveEditorMovePositioning, ActiveEditorMovePositioningBy, EditorCommands } from 'vs/workbench/common/editor'; +import { ActiveEditorMoveArguments, ActiveEditorMovePositioning, ActiveEditorMovePositioningBy, EditorCommands, TextCompareEditorVisible } from 'vs/workbench/common/editor'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditor, Position, POSITIONS } from 'vs/platform/editor/common/editor'; import { EditorContextKeys } from 'vs/editor/common/editorCommon'; -import { TextCompareEditorVisible, TextDiffEditor } from 'vs/workbench/browser/parts/editor/textDiffEditor'; +import { TextDiffEditor } from 'vs/workbench/browser/parts/editor/textDiffEditor'; import { EditorStacksModel } from 'vs/workbench/common/editor/editorStacksModel'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { IMessageService, Severity, CloseAction } from 'vs/platform/message/common/message'; diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index a087d318f48..162ea2b23e7 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -21,7 +21,7 @@ import { toErrorMessage } from 'vs/base/common/errorMessage'; import { Scope as MementoScope } from 'vs/workbench/common/memento'; import { Part } from 'vs/workbench/browser/part'; import { BaseEditor, EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor'; -import { IEditorRegistry, Extensions as EditorExtensions, EditorInput, EditorOptions, ConfirmResult, IWorkbenchEditorConfiguration, IEditorDescriptor, TextEditorOptions, SideBySideEditorInput } from 'vs/workbench/common/editor'; +import { IEditorRegistry, Extensions as EditorExtensions, EditorInput, EditorOptions, ConfirmResult, IWorkbenchEditorConfiguration, IEditorDescriptor, TextEditorOptions, SideBySideEditorInput, TextCompareEditorVisible, TEXT_DIFF_EDITOR_ID } from 'vs/workbench/common/editor'; import { EditorGroupsControl, Rochade, IEditorGroupsControl, ProgressState } from 'vs/workbench/browser/parts/editor/editorGroupsControl'; import { WorkbenchProgressService } from 'vs/workbench/services/progress/browser/progressService'; import { IEditorGroupService, GroupOrientation, GroupArrangement, ITabOptions } from 'vs/workbench/services/group/common/groupService'; @@ -37,6 +37,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IProgressService } from 'vs/platform/progress/common/progress'; import { EditorStacksModel, EditorGroup, EditorIdentifier, GroupEvent } from 'vs/workbench/common/editor/editorStacksModel'; import Event, { Emitter } from 'vs/base/common/event'; +import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; class ProgressMonitor { @@ -93,6 +94,8 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService private _onGroupOrientationChanged: Emitter; private _onTabOptionsChanged: Emitter; + private textCompareEditorVisible: IContextKey; + // The following data structures are partitioned into array of Position as provided by Services.POSITION array private visibleEditors: BaseEditor[]; private instantiatedEditors: BaseEditor[][]; @@ -109,6 +112,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService @IStorageService private storageService: IStorageService, @IPartService private partService: IPartService, @IConfigurationService private configurationService: IConfigurationService, + @IContextKeyService contextKeyService: IContextKeyService, @IInstantiationService private instantiationService: IInstantiationService ) { super(id); @@ -132,6 +136,8 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService this.stacks = this.instantiationService.createInstance(EditorStacksModel, restoreFromStorage); + this.textCompareEditorVisible = TextCompareEditorVisible.bindTo(contextKeyService); + const config = configurationService.getConfiguration(); if (config && config.workbench && config.workbench.editor) { const editorConfig = config.workbench.editor; @@ -350,6 +356,9 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService // Indicate to editor that it is now visible editor.setVisible(true, position); + // Update text compare editor visible context + this.updateTextCompareEditorVisible(); + // Make sure the editor is layed out this.editorGroupsControl.layout(position); @@ -595,6 +604,9 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService editor.clearInput(); editor.setVisible(false); + // Update text compare editor visible context + this.updateTextCompareEditorVisible(); + // Clear active editor this.visibleEditors[position] = null; @@ -607,6 +619,10 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService } } + private updateTextCompareEditorVisible(): void { + this.textCompareEditorVisible.set(this.visibleEditors.some(e => e && e.isVisible() && e.getId() === TEXT_DIFF_EDITOR_ID)); + } + public closeAllEditors(except?: Position): TPromise { let groups = this.stacks.groups.reverse(); // start from the end to prevent layout to happen through rochade diff --git a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts index 246a4d3948d..621985ff420 100644 --- a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts @@ -12,7 +12,6 @@ import { Builder } from 'vs/base/browser/builder'; import { Action, IAction } from 'vs/base/common/actions'; import { onUnexpectedError } from 'vs/base/common/errors'; import types = require('vs/base/common/types'); -import { Position } from 'vs/platform/editor/common/editor'; import { IDiffEditor } from 'vs/editor/browser/editorBrowser'; import { IDiffEditorOptions, IEditorOptions } from 'vs/editor/common/editorCommon'; import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor'; @@ -31,13 +30,10 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IThemeService } from 'vs/workbench/services/themes/common/themeService'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; -export const TextCompareEditorVisible = new RawContextKey('textCompareEditorVisible', false); - /** * The text editor that leverages the diff text editor for the editing experience. */ @@ -49,22 +45,17 @@ export class TextDiffEditor extends BaseTextEditor { private nextDiffAction: NavigateAction; private previousDiffAction: NavigateAction; - private textDiffEditorVisible: IContextKey; - constructor( @ITelemetryService telemetryService: ITelemetryService, @IInstantiationService instantiationService: IInstantiationService, @IStorageService storageService: IStorageService, @IConfigurationService configurationService: IConfigurationService, @IWorkbenchEditorService private editorService: IWorkbenchEditorService, - @IContextKeyService contextKeyService: IContextKeyService, @IThemeService themeService: IThemeService, @IEditorGroupService private editorGroupService: IEditorGroupService, @ITextFileService textFileService: ITextFileService ) { super(TextDiffEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService); - - this.textDiffEditorVisible = TextCompareEditorVisible.bindTo(contextKeyService); } public getTitle(): string { @@ -263,12 +254,6 @@ export class TextDiffEditor extends BaseTextEditor { super.clearInput(); } - public setEditorVisible(visible: boolean, position: Position): void { - this.textDiffEditorVisible.set(visible); - - super.setEditorVisible(visible, position); - } - public getDiffNavigator(): DiffNavigator { return this.diffNavigator; } diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 927e46b9ef1..4717f2ec35c 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -16,6 +16,9 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { SyncDescriptor, AsyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { IInstantiationService, IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation'; +import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; + +export const TextCompareEditorVisible = new RawContextKey('textCompareEditorVisible', false); export enum ConfirmResult { SAVE,