editrour group service - tab options

This commit is contained in:
isidor
2016-12-21 16:07:11 +01:00
parent 2130c88630
commit b0ff2a6751
8 changed files with 83 additions and 89 deletions

View File

@@ -71,9 +71,9 @@ function registerActiveEditorMoveCommand(): void {
}
function moveActiveEditor(args: ActiveEditorMoveArguments = {}, accessor: ServicesAccessor): void {
const tabsShown = accessor.get(IEditorGroupService).areTabsShown();
const showTabs = accessor.get(IEditorGroupService).getTabOptions().showTabs;
args.to = args.to || ActiveEditorMovePositioning.RIGHT;
args.by = tabsShown ? args.by || ActiveEditorMovePositioningBy.TAB : ActiveEditorMovePositioningBy.GROUP;
args.by = showTabs ? args.by || ActiveEditorMovePositioningBy.TAB : ActiveEditorMovePositioningBy.GROUP;
args.value = types.isUndefined(args.value) ? 1 : args.value;
const activeEditor = accessor.get(IWorkbenchEditorService).getActiveEditor();

View File

@@ -20,7 +20,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
import { isMacintosh } from 'vs/base/common/platform';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { Position, POSITIONS } from 'vs/platform/editor/common/editor';
import { IEditorGroupService, GroupArrangement, GroupOrientation } from 'vs/workbench/services/group/common/groupService';
import { IEditorGroupService, ITabOptions, GroupArrangement, GroupOrientation } from 'vs/workbench/services/group/common/groupService';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -31,7 +31,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { TabsTitleControl } from 'vs/workbench/browser/parts/editor/tabsTitleControl';
import { TitleControl, ITitleAreaControl } from 'vs/workbench/browser/parts/editor/titleControl';
import { NoTabsTitleControl } from 'vs/workbench/browser/parts/editor/noTabsTitleControl';
import { IEditorStacksModel, IStacksModelChangeEvent, IWorkbenchEditorConfiguration, IEditorGroup, EditorOptions, TextEditorOptions, IEditorIdentifier } from 'vs/workbench/common/editor';
import { IEditorStacksModel, IStacksModelChangeEvent, IEditorGroup, EditorOptions, TextEditorOptions, IEditorIdentifier } from 'vs/workbench/common/editor';
import { extractResources } from 'vs/base/browser/dnd';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { getCodeEditor } from 'vs/editor/common/services/codeEditorService';
@@ -106,9 +106,7 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
private layoutVertically: boolean;
private showTabs: boolean;
private showTabCloseButton: boolean;
private showIcons: boolean;
private tabOptions: ITabOptions;
private silos: Builder[];
private silosSize: number[];
@@ -166,7 +164,7 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
this.toDispose.push(this.onStacksChangeScheduler);
this.stacksChangedBuffer = [];
this.updateTabOptions(this.configurationService.getConfiguration<IWorkbenchEditorConfiguration>());
this.updateTabOptions(this.editorGroupService.getTabOptions());
const editorGroupOrientation = groupOrientation || 'vertical';
this.layoutVertically = (editorGroupOrientation !== 'horizontal');
@@ -210,22 +208,13 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
private registerListeners(): void {
this.toDispose.push(this.stacks.onModelChanged(e => this.onStacksChanged(e)));
this.toDispose.push(this.configurationService.onDidUpdateConfiguration(e => this.updateTabOptions(e.config, true)));
this.toDispose.push(this.editorGroupService.onShowTabsChanged(() => this.updateTabOptions(this.configurationService.getConfiguration<IWorkbenchEditorConfiguration>(), true)));
this.toDispose.push(this.editorGroupService.onTabOptionsChanged(options => this.updateTabOptions(options, true)));
this.extensionService.onReady().then(() => this.onExtensionsReady());
}
private updateTabOptions(config: IWorkbenchEditorConfiguration, refresh?: boolean): void {
const showTabCloseButton = this.showTabCloseButton;
this.showTabs = this.editorGroupService.areTabsShown();
if (config.workbench && config.workbench.editor) {
this.showTabCloseButton = config.workbench.editor.showTabCloseButton;
this.showIcons = config.workbench.editor.showIcons;
} else {
this.showTabCloseButton = true;
this.showIcons = false;
}
private updateTabOptions(tabOptions: ITabOptions, refresh?: boolean): void {
const showTabCloseButton = this.tabOptions ? this.tabOptions.showTabCloseButton : false;
this.tabOptions = tabOptions;
if (!refresh) {
return; // return early if no refresh is needed
@@ -237,14 +226,14 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
// TItle Container
const titleContainer = $(titleControl.getContainer());
if (this.showTabs) {
if (this.tabOptions.showTabs) {
titleContainer.addClass('tabs');
} else {
titleContainer.removeClass('tabs');
}
const showingIcons = titleContainer.hasClass('show-file-icons');
if (this.showIcons) {
if (this.tabOptions.showIcons) {
titleContainer.addClass('show-file-icons');
} else {
titleContainer.removeClass('show-file-icons');
@@ -255,14 +244,14 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
const usingTabs = (titleControl instanceof TabsTitleControl);
// Recreate title when tabs change
if (usingTabs !== this.showTabs) {
if (usingTabs !== this.tabOptions.showTabs) {
titleControl.dispose();
titleContainer.empty();
this.createTitleControl(this.stacks.groupAt(position), this.silos[position], titleContainer, this.getInstantiationService(position));
}
// Refresh title when icons change
else if (showingIcons !== this.showIcons || showTabCloseButton !== this.showTabCloseButton) {
else if (showingIcons !== this.tabOptions.showIcons || showTabCloseButton !== this.tabOptions.showTabCloseButton) {
titleControl.refresh();
}
}
@@ -894,10 +883,10 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
// Title containers
const titleContainer = $(container).div({ 'class': 'title' });
if (this.showTabs) {
if (this.tabOptions.showTabs) {
titleContainer.addClass('tabs');
}
if (this.showIcons) {
if (this.tabOptions.showIcons) {
titleContainer.addClass('show-file-icons');
}
this.hookTitleDragListener(titleContainer);
@@ -1091,7 +1080,7 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
if ($this.layoutVertically) {
overlay.style({ left: '0', width: '100%' });
} else {
overlay.style({ top: $this.showTabs ? `${EditorGroupsControl.EDITOR_TITLE_HEIGHT}px` : 0, height: $this.showTabs ? `calc(100% - ${EditorGroupsControl.EDITOR_TITLE_HEIGHT}px` : '100%' });
overlay.style({ top: $this.tabOptions.showTabs ? `${EditorGroupsControl.EDITOR_TITLE_HEIGHT}px` : 0, height: $this.tabOptions.showTabs ? `calc(100% - ${EditorGroupsControl.EDITOR_TITLE_HEIGHT}px` : '100%' });
}
}
@@ -1114,8 +1103,8 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
containers.forEach((container, index) => {
if (container && DOM.isAncestor(target, container.getHTMLElement())) {
overlay = $('div').style({
top: $this.showTabs ? `${EditorGroupsControl.EDITOR_TITLE_HEIGHT}px` : 0,
height: $this.showTabs ? `calc(100% - ${EditorGroupsControl.EDITOR_TITLE_HEIGHT}px` : '100%'
top: $this.tabOptions.showTabs ? `${EditorGroupsControl.EDITOR_TITLE_HEIGHT}px` : 0,
height: $this.tabOptions.showTabs ? `calc(100% - ${EditorGroupsControl.EDITOR_TITLE_HEIGHT}px` : '100%'
}).id(overlayId);
overlay.appendTo(container);
@@ -1202,7 +1191,7 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
}
private createTitleControl(context: IEditorGroup, silo: Builder, container: Builder, instantiationService: IInstantiationService): void {
const titleAreaControl = instantiationService.createInstance<ITitleAreaControl>(this.showTabs ? TabsTitleControl : NoTabsTitleControl);
const titleAreaControl = instantiationService.createInstance<ITitleAreaControl>(this.tabOptions.showTabs ? TabsTitleControl : NoTabsTitleControl);
titleAreaControl.create(container.getHTMLElement());
titleAreaControl.setContext(context);
titleAreaControl.refresh(true /* instant */);

View File

@@ -15,6 +15,7 @@ import strings = require('vs/base/common/strings');
import arrays = require('vs/base/common/arrays');
import types = require('vs/base/common/types');
import errors = require('vs/base/common/errors');
import * as objects from 'vs/base/common/objects';
import { getCodeEditor } from 'vs/editor/common/services/codeEditorService';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { Scope as MementoScope } from 'vs/workbench/common/memento';
@@ -23,7 +24,7 @@ import { BaseEditor, EditorDescriptor } from 'vs/workbench/browser/parts/editor/
import { IEditorRegistry, Extensions as EditorExtensions, EditorInput, EditorOptions, ConfirmResult, IWorkbenchEditorConfiguration, IEditorDescriptor, TextEditorOptions, SideBySideEditorInput } 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 } from 'vs/workbench/services/group/common/groupService';
import { IEditorGroupService, GroupOrientation, GroupArrangement, ITabOptions } from 'vs/workbench/services/group/common/groupService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEditorPart } from 'vs/workbench/services/editor/browser/editorService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
@@ -83,14 +84,13 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
private editorGroupsControl: IEditorGroupsControl;
private memento: any;
private stacks: EditorStacksModel;
private previewEditors: boolean;
private showTabs: boolean;
private tabOptions: ITabOptions;
private _onEditorsChanged: Emitter<void>;
private _onEditorsMoved: Emitter<void>;
private _onEditorOpenFail: Emitter<EditorInput>;
private _onGroupOrientationChanged: Emitter<void>;
private _onShowTabsChanged: Emitter<void>;
private _onTabOptionsChanged: Emitter<ITabOptions>;
// The following data structures are partitioned into array of Position as provided by Services.POSITION array
private visibleEditors: BaseEditor[];
@@ -116,7 +116,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
this._onEditorsMoved = new Emitter<void>();
this._onEditorOpenFail = new Emitter<EditorInput>();
this._onGroupOrientationChanged = new Emitter<void>();
this._onShowTabsChanged = new Emitter<void>();
this._onTabOptionsChanged = new Emitter<ITabOptions>();
this.visibleEditors = [];
@@ -134,11 +134,21 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
const config = configurationService.getConfiguration<IWorkbenchEditorConfiguration>();
if (config && config.workbench && config.workbench.editor) {
const editorConfig = config.workbench.editor;
this.previewEditors = editorConfig.enablePreview;
this.showTabs = editorConfig.showTabs;
this.tabOptions = {
previewEditors: editorConfig.enablePreview,
showIcons: editorConfig.showIcons,
showTabs: editorConfig.showTabs,
showTabCloseButton: editorConfig.showTabCloseButton
};
this.telemetryService.publicLog('workbenchEditorConfiguration', editorConfig);
} else {
this.tabOptions = {
previewEditors: true,
showIcons: false,
showTabs: true,
showTabCloseButton: true
};
}
this.registerListeners();
@@ -158,7 +168,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Pin all preview editors of the user chose to disable preview
const newPreviewEditors = editorConfig.enablePreview;
if (this.previewEditors !== newPreviewEditors && !newPreviewEditors) {
if (this.tabOptions.previewEditors !== newPreviewEditors && !newPreviewEditors) {
this.stacks.groups.forEach(group => {
if (group.previewEditor) {
this.pinEditor(group, group.previewEditor);
@@ -166,7 +176,17 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
});
}
this.previewEditors = newPreviewEditors;
const oldTabOptions = objects.clone(this.tabOptions);
this.tabOptions = {
previewEditors: newPreviewEditors,
showIcons: editorConfig.showIcons,
showTabCloseButton: editorConfig.showTabCloseButton,
showTabs: editorConfig.showTabs
};
if (!objects.equals(oldTabOptions, this.tabOptions)) {
this._onTabOptionsChanged.fire(this.tabOptions);
}
}
}
@@ -205,17 +225,12 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
return this._onGroupOrientationChanged.event;
}
public get onShowTabsChanged(): Event<void> {
return this._onShowTabsChanged.event;
public get onTabOptionsChanged(): Event<ITabOptions> {
return this._onTabOptionsChanged.event;
}
public areTabsShown(): boolean {
return this.showTabs;
}
public setShowTabs(value: boolean) {
this.showTabs = value;
this._onShowTabsChanged.fire();
public getTabOptions(): ITabOptions {
return this.tabOptions;
}
public openEditor(input: EditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise<BaseEditor>;
@@ -263,7 +278,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// while the UI is not yet ready. Clients have to deal with this fact and we have to make sure that the
// stacks model gets updated if any of the UI updating fails with an error.
const group = this.ensureGroup(position, !options || !options.preserveFocus);
const pinned = !this.previewEditors || (options && (options.pinned || typeof options.index === 'number')) || input.isDirty();
const pinned = !this.tabOptions.previewEditors || (options && (options.pinned || typeof options.index === 'number')) || input.isDirty();
const active = (group.count === 0) || !options || !options.inactive;
group.openEditor(input, { active, pinned, index: options && options.index });

View File

@@ -362,7 +362,7 @@ export class TabsTitleControl extends TitleControl {
tabContainer.setAttribute('role', 'presentation'); // cannot use role "tab" here due to https://github.com/Microsoft/vscode/issues/8659
DOM.addClass(tabContainer, 'tab monaco-editor-background');
if (!this.showTabCloseButton) {
if (!this.tabOptions.showTabCloseButton) {
DOM.addClass(tabContainer, 'no-close-button');
} else {
DOM.removeClass(tabContainer, 'no-close-button');

View File

@@ -17,14 +17,14 @@ import { BaseEditor, IEditorInputActionContext } from 'vs/workbench/browser/part
import { RunOnceScheduler } from 'vs/base/common/async';
import { isCommonCodeEditor, isCommonDiffEditor } from 'vs/editor/common/editorCommon';
import arrays = require('vs/base/common/arrays');
import { IEditorStacksModel, IEditorGroup, IEditorIdentifier, EditorInput, IWorkbenchEditorConfiguration, IStacksModelChangeEvent, toResource } from 'vs/workbench/common/editor';
import { IEditorStacksModel, IEditorGroup, IEditorIdentifier, EditorInput, IStacksModelChangeEvent, toResource } from 'vs/workbench/common/editor';
import { EventType as BaseEventType } from 'vs/base/common/events';
import { IActionItem, ActionsOrientation, Separator } from 'vs/base/browser/ui/actionbar/actionbar';
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IEditorGroupService, ITabOptions } from 'vs/workbench/services/group/common/groupService';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
@@ -77,10 +77,7 @@ export abstract class TitleControl implements ITitleAreaControl {
private parent: HTMLElement;
private previewEditors: boolean;
private showTabs: boolean;
protected showTabCloseButton: boolean;
protected tabOptions: ITabOptions;
private currentPrimaryEditorActionIds: string[] = [];
private currentSecondaryEditorActionIds: string[] = [];
protected editorActionsToolbar: ToolBar;
@@ -111,7 +108,7 @@ export abstract class TitleControl implements ITitleAreaControl {
this.stacks = editorGroupService.getStacksModel();
this.mapActionsToEditors = Object.create(null);
this.updateTabOptions(configurationService.getConfiguration<IWorkbenchEditorConfiguration>());
this.tabOptions = this.editorGroupService.getTabOptions();
this.scheduler = new RunOnceScheduler(() => this.onSchedule(), 0);
this.toDispose.push(this.scheduler);
@@ -142,8 +139,7 @@ export abstract class TitleControl implements ITitleAreaControl {
}
private registerListeners(): void {
this.toDispose.push(this.configurationService.onDidUpdateConfiguration(e => this.updateTabOptions(e.config)));
this.toDispose.push(this.editorGroupService.onShowTabsChanged(() => this.updateTabOptions(this.configurationService.getConfiguration<IWorkbenchEditorConfiguration>())));
this.toDispose.push(this.editorGroupService.onTabOptionsChanged(options => this.tabOptions = options));
this.toDispose.push(this.stacks.onModelChanged(e => this.onStacksChanged(e)));
}
@@ -153,12 +149,6 @@ export abstract class TitleControl implements ITitleAreaControl {
}
}
private updateTabOptions(config: IWorkbenchEditorConfiguration): void {
this.previewEditors = config.workbench && config.workbench.editor && config.workbench.editor.enablePreview;
this.showTabs = this.editorGroupService.areTabsShown();
this.showTabCloseButton = config.workbench && config.workbench.editor && config.workbench.editor.showTabCloseButton;
}
private updateSplitActionEnablement(): void {
if (!this.context) {
return;
@@ -384,7 +374,7 @@ export abstract class TitleControl implements ITitleAreaControl {
secondaryEditorActions = prepareActions(editorActions.secondary);
}
if (this.showTabs) {
if (this.tabOptions.showTabs) {
if (secondaryEditorActions.length > 0) {
secondaryEditorActions.push(new Separator());
}
@@ -394,7 +384,7 @@ export abstract class TitleControl implements ITitleAreaControl {
}
const primaryEditorActionIds = primaryEditorActions.map(a => a.id);
if (!this.showTabs) {
if (!this.tabOptions.showTabs) {
primaryEditorActionIds.push(this.closeEditorAction.id); // always show "Close" when tabs are disabled
}
@@ -408,7 +398,7 @@ export abstract class TitleControl implements ITitleAreaControl {
) {
this.editorActionsToolbar.setActions(primaryEditorActions, secondaryEditorActions)();
if (!this.showTabs) {
if (!this.tabOptions.showTabs) {
this.editorActionsToolbar.addPrimaryAction(this.closeEditorAction)();
}
@@ -475,13 +465,13 @@ export abstract class TitleControl implements ITitleAreaControl {
this.closeOtherEditorsAction
];
if (this.showTabs) {
if (this.tabOptions.showTabs) {
actions.push(this.closeRightEditorsAction);
}
actions.push(this.closeEditorsInGroupAction);
if (this.previewEditors) {
if (this.tabOptions.previewEditors) {
actions.push(new Separator(), this.pinEditorAction);
}