/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; import { TPromise } from 'vs/base/common/winjs.base'; import { GroupIdentifier, IWorkbenchEditorConfiguration, IWorkbenchEditorPartConfiguration, EditorOptions, TextEditorOptions, IEditorInput } from 'vs/workbench/common/editor'; import { EditorGroup } from 'vs/workbench/common/editor/editorGroup'; import { INextEditorGroup, GroupDirection, IAddGroupOptions, IMergeGroupOptions } from 'vs/workbench/services/group/common/nextEditorGroupsService'; import { IDisposable } from 'vs/base/common/lifecycle'; import { Dimension } from 'vs/base/browser/dom'; import { Event } from 'vs/base/common/event'; import { assign } from 'vs/base/common/objects'; import { IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration'; import { ISerializableView } from 'vs/base/browser/ui/grid/grid'; import { getCodeEditor } from 'vs/editor/browser/editorBrowser'; export const EDITOR_TITLE_HEIGHT = 35; export const EDITOR_MIN_DIMENSIONS = new Dimension(220, 70); export const EDITOR_MAX_DIMENSIONS = new Dimension(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); export interface INextEditorPartOptions extends IWorkbenchEditorPartConfiguration { iconTheme?: string; } export const DEFAULT_EDITOR_PART_OPTIONS: INextEditorPartOptions = { showTabs: true, tabCloseButton: 'right', tabSizing: 'fit', showIcons: true, enablePreview: true, labelFormat: 'default', iconTheme: 'vs-seti', revealIfOpen: false }; export function impactsEditorPartOptions(event: IConfigurationChangeEvent): boolean { return event.affectsConfiguration('workbench.editor') || event.affectsConfiguration('workbench.iconTheme'); } export function getEditorPartOptions(config: IWorkbenchEditorConfiguration): INextEditorPartOptions { const options: INextEditorPartOptions = assign(Object.create(null), DEFAULT_EDITOR_PART_OPTIONS); if (!config || !config.workbench) { return options; } if (typeof config.workbench.iconTheme === 'string') { options.iconTheme = config.workbench.iconTheme; } if (config.workbench.editor) { assign(options, config.workbench.editor); } return options; } export interface INextEditorPartOptionsChangeEvent { oldPartOptions: INextEditorPartOptions; newPartOptions: INextEditorPartOptions; } export interface INextEditorGroupsAccessor { readonly groups: INextEditorGroupView[]; readonly activeGroup: INextEditorGroupView; readonly partOptions: INextEditorPartOptions; readonly onDidEditorPartOptionsChange: Event; getGroup(identifier: GroupIdentifier): INextEditorGroupView; activateGroup(identifier: INextEditorGroupView | GroupIdentifier): INextEditorGroupView; focusGroup(identifier: INextEditorGroupView | GroupIdentifier): INextEditorGroupView; addGroup(location: INextEditorGroupView | GroupIdentifier, direction: GroupDirection, options?: IAddGroupOptions): INextEditorGroupView; mergeGroup(group: INextEditorGroupView | GroupIdentifier, target: INextEditorGroupView | GroupIdentifier, options?: IMergeGroupOptions): INextEditorGroupView; moveGroup(group: INextEditorGroupView | GroupIdentifier, location: INextEditorGroupView | GroupIdentifier, direction: GroupDirection): INextEditorGroupView; copyGroup(group: INextEditorGroupView | GroupIdentifier, location: INextEditorGroupView | GroupIdentifier, direction: GroupDirection): INextEditorGroupView; removeGroup(group: INextEditorGroupView | GroupIdentifier): void; } export interface INextEditorGroupView extends IDisposable, ISerializableView, INextEditorGroup { readonly group: EditorGroup; readonly whenRestored: TPromise; readonly disposed: boolean; readonly onDidFocus: Event; readonly onWillDispose: Event; isEmpty(): boolean; setActive(isActive: boolean): void; setLabel(label: string): void; shutdown(): void; } export function getActiveTextEditorOptions(group: INextEditorGroup, expectedActiveEditor?: IEditorInput, presetOptions?: EditorOptions): EditorOptions { const activeGroupCodeEditor = group.activeControl ? getCodeEditor(group.activeControl.getControl()) : void 0; if (activeGroupCodeEditor) { if (!expectedActiveEditor || expectedActiveEditor.matches(group.activeEditor)) { return TextEditorOptions.fromEditor(activeGroupCodeEditor, presetOptions); } } return presetOptions || new EditorOptions(); }