提交 2de9e462 编写于 作者: B Benjamin Pasero

extract title area control

上级 90eb74e3
......@@ -26,7 +26,7 @@ export function forEach<T>(array: T[], callback: (element: T, remove: Function)
}
}
export function equals<T>(one: T[], other: T[], itemEquals: (a: T, b: T) => boolean): boolean {
export function equals<T>(one: T[], other: T[], itemEquals: (a: T, b: T) => boolean = (a, b) => a === b): boolean {
if (one.length !== other.length) {
return false;
}
......
......@@ -124,7 +124,7 @@ export interface IEditorInput extends IEventEmitter {
/**
* Returns the display description of this input.
*/
getDescription(): string;
getDescription(verbose?: boolean): string;
/**
* Returns if this input is dirty or not.
......
......@@ -182,6 +182,9 @@ export class ContributableActionProvider implements IActionProvider {
// Helper function used in parts to massage actions before showing in action areas
export function prepareActions(actions: IAction[]): IAction[] {
if (!actions.length) {
return actions;
}
// Patch order if not provided
for (let l = 0; l < actions.length; l++) {
......
......@@ -23,7 +23,7 @@ import {Part} from 'vs/workbench/browser/part';
import {IEditorRegistry, Extensions as EditorExtensions, BaseEditor, EditorDescriptor} from 'vs/workbench/browser/parts/editor/baseEditor';
import {EditorInput, EditorOptions, TextEditorOptions, ConfirmResult, EditorInputEvent} from 'vs/workbench/common/editor';
import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor';
import {SideBySideEditorControl, Rochade, ISideBySideEditorControl, ProgressState, ITitleAreaState} from 'vs/workbench/browser/parts/editor/sideBySideEditorControl';
import {SideBySideEditorControl, Rochade, ISideBySideEditorControl, ProgressState} from 'vs/workbench/browser/parts/editor/sideBySideEditorControl';
import {WorkbenchProgressService} from 'vs/workbench/services/progress/browser/progressService';
import {GroupArrangement} from 'vs/workbench/services/editor/common/editorService';
import {IEditorPart} from 'vs/workbench/services/editor/browser/editorService';
......@@ -140,13 +140,9 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
private onEditorDirty(identifier: EditorIdentifier): void {
const position = this.stacks.positionOfGroup(identifier.group);
const group = identifier.group;
// we pin every editor that becomes dirty
this.pinEditor(position, identifier.editor, false /* we update the UI right after */);
// Update UI
this.sideBySideControl.updateTitleArea({ position, preview: group.previewEditor, editorCount: group.count });
this.pinEditor(position, identifier.editor);
}
private onEditorDisposed(identifier: EditorIdentifier): void {
......@@ -230,9 +226,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
const pinned = (options && (options.pinned || typeof options.index === 'number')) || input.isDirty();
group.openEditor(input, { active: true, pinned, index: options && options.index });
// Set the title early enough
this.sideBySideControl.setTitleLabel(position, input, group.isPinned(input), this.stacks.isActive(group));
// Progress Monitor & Ref Counting
this.editorOpenToken[position]++;
const editorOpenToken = this.editorOpenToken[position];
......@@ -416,13 +409,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
this._onEditorsChanged.fire();
}
// Update Title Area
if (inputChanged) {
this.doRecreateEditorTitleArea(); // full title update
} else {
this.sideBySideControl.updateTitleArea({ position, preview: group.previewEditor, editorCount: group.count }); // little update for position
}
timerEvent.stop();
// Fullfill promise with Editor that is being used
......@@ -487,7 +473,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
this.doCloseActiveEditor(group, focusNext);
}
// Closing inactive editor is just a model and title update
// Closing inactive editor is just a model update
else {
this.doCloseInactiveEditor(group, input);
}
......@@ -514,9 +500,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Closing inactive editor is just a model update
group.closeEditor(input);
// Update UI
this.sideBySideControl.updateTitleArea({ position: this.stacks.positionOfGroup(group), preview: group.previewEditor, editorCount: group.count });
}
private doCloseGroup(group: EditorGroup): void {
......@@ -565,9 +548,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Rochade as needed
this.rochade(rochade);
// Clear Title Area for Position
this.sideBySideControl.clearTitleArea(position);
// Emit Editor move event
if (rochade !== Rochade.NONE) {
this._onEditorsMoved.fire();
......@@ -634,9 +614,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Update stacks model: close non active editors supporting the direction
group.closeEditors(group.activeEditor, direction);
// Update UI
this.sideBySideControl.updateTitleArea({ position: this.stacks.positionOfGroup(group), preview: group.previewEditor, editorCount: group.count });
}
// Finally: we are asked to close editors around a non-active editor
......@@ -729,9 +706,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Restore focus
this.focusGroup(this.stacks.positionOfGroup(fromGroup));
// Update all title areas
this.doRecreateEditorTitleArea();
// Events
this._onEditorsMoved.fire();
}
......@@ -768,9 +742,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Update stacks model
group.moveEditor(input, toIndex);
group.pin(input);
// Update UI
this.doRecreateEditorTitleArea();
}
private doMoveEditorAcrossGroups(input: EditorInput, from: EditorGroup, to: EditorGroup, index?: number): void {
......@@ -797,7 +768,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
this.sideBySideControl = this.instantiationService.createInstance(SideBySideEditorControl, contentArea);
this.toUnbind.push(this.sideBySideControl.onGroupFocusChanged(() => this.onGroupFocusChanged()));
this.toUnbind.push(this.sideBySideControl.onEditorTitleDoubleclick((position) => this.onEditorTitleDoubleclick(position)));
// get settings
this.memento = this.getMemento(this.storageService, MementoScope.WORKSPACE);
......@@ -818,16 +788,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
if (activeEditor) {
this._onEditorsChanged.fire();
}
// Update Title Area
this.doRecreateEditorTitleArea();
}
private onEditorTitleDoubleclick(position: Position): void {
const group = this.stacks.groupAt(position);
if (group) {
this.pinEditor(position, group.activeEditor);
}
}
public replaceEditors(editors: { toReplace: EditorInput, replaceWith: EditorInput, options?: EditorOptions }[]): TPromise<BaseEditor[]> {
......@@ -1031,7 +991,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
}
}
public pinEditor(position: Position, input: EditorInput, updateTitleArea = true): void {
public pinEditor(position: Position, input: EditorInput): void {
const group = this.stacks.groupAt(position);
if (group) {
if (group.isPinned(input)) {
......@@ -1040,11 +1000,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Update stacks model
group.pin(input);
// Update UI
if (updateTitleArea) {
this.sideBySideControl.updateTitleArea({ position, preview: group.previewEditor, editorCount: group.count });
}
}
}
......@@ -1079,25 +1034,10 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// Update stacks model
group.unpin(input);
// Update UI
this.sideBySideControl.updateTitleArea({ position, preview: group.previewEditor, editorCount: group.count });
});
}
}
private doRecreateEditorTitleArea(): void {
const titleAreaState: ITitleAreaState[] = this.stacks.groups.map((group, index) => {
return {
position: this.stacks.positionOfGroup(group),
preview: group.previewEditor,
editorCount: group.count
};
});
this.sideBySideControl.recreateTitleArea(titleAreaState);
}
public layout(dimension: Dimension): Dimension[] {
// Pass to super
......
......@@ -57,7 +57,7 @@
color: #333333;
}
.vs .monaco-workbench > .part.editor > .content .inactive .title .title-label a {
.vs .monaco-workbench > .part.editor > .content > .one-editor-container .title.inactive .title-label a {
color: rgba(51, 51, 51, 0.5);
}
......@@ -65,7 +65,7 @@
color: white;
}
.vs-dark .monaco-workbench > .part.editor > .content .inactive .title .title-label a {
.vs-dark .monaco-workbench > .part.editor > .content > .one-editor-container .title.inactive .title-label a {
color: rgba(255, 255, 255, 0.5);
}
......@@ -91,7 +91,7 @@
flex: initial;
}
.monaco-workbench > .part.editor > .content .inactive .title .title-actions {
.monaco-workbench > .part.editor > .content > .one-editor-container .title.inactive .title-actions {
opacity: 0.5;
}
......
/*---------------------------------------------------------------------------------------------
* 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 'vs/css!./media/notabstitle';
import {prepareActions} from 'vs/workbench/browser/actionBarRegistry';
import errors = require('vs/base/common/errors');
import arrays = require('vs/base/common/arrays');
import {Builder, $} from 'vs/base/browser/builder';
import {IEditorGroup} from 'vs/workbench/common/editor';
import DOM = require('vs/base/browser/dom');
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 {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {IMessageService} from 'vs/platform/message/common/message';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {TitleControl} from 'vs/workbench/browser/parts/editor/titleControl';
export class NoTabsTitleControl extends TitleControl {
private titleContainer: Builder;
private titleLabel: Builder;
private titleDecoration: Builder;
private titleDescription: Builder;
private groupActionsToolbar: ToolBar;
private editorActionsToolbar: ToolBar;
private currentPrimaryEditorActionIds: string[];
private currentSecondaryEditorActionIds: string[];
private currentPrimaryGroupActionIds: string[];
private currentSecondaryGroupActionIds: string[];
constructor(
@IContextMenuService contextMenuService: IContextMenuService,
@IInstantiationService instantiationService: IInstantiationService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@IKeybindingService keybindingService: IKeybindingService,
@ITelemetryService telemetryService: ITelemetryService,
@IMessageService messageService: IMessageService
) {
super(contextMenuService, instantiationService, editorService, editorGroupService, keybindingService, telemetryService, messageService);
this.currentPrimaryEditorActionIds = [];
this.currentSecondaryEditorActionIds = [];
this.currentPrimaryGroupActionIds = [];
this.currentSecondaryGroupActionIds = [];
}
public setContext(group: IEditorGroup): void {
super.setContext(group);
this.editorActionsToolbar.context = { group };
this.groupActionsToolbar.context = { group };
}
public create(parent: Builder): void {
this.titleContainer = $(parent);
// Pin on double click
parent.on(DOM.EventType.DBLCLICK, (e: MouseEvent) => {
DOM.EventHelper.stop(e);
this.onTitleDoubleClick();
});
// Detect mouse click
parent.on(DOM.EventType.MOUSE_UP, (e: MouseEvent) => {
DOM.EventHelper.stop(e, false);
this.onTitleClick(e);
});
// Left Title Decoration
parent.div({
'class': 'title-decoration'
}, (div) => {
this.titleDecoration = div;
});
// Left Title Label & Description
parent.div({
'class': 'title-label'
}, (div) => {
// Label
this.titleLabel = $(div).a();
// Description
this.titleDescription = $(div).span();
});
// Right Actions Container
parent.div({
'class': 'title-actions'
}, (div) => {
// Editor actions
this.editorActionsToolbar = this.doCreateToolbar(div);
// Group actions
this.groupActionsToolbar = this.doCreateToolbar(div);
this.groupActionsToolbar.getContainer().addClass('editor-group-toolbar');
});
}
private onTitleDoubleClick(): void {
if (!this.context) {
return;
}
const group = this.context;
const position = this.stacks.positionOfGroup(group);
this.editorGroupService.pinEditor(position, group.activeEditor);
}
private onTitleClick(e: MouseEvent): void {
if (!this.context) {
return;
}
const group = this.context;
const position = this.stacks.positionOfGroup(group);
// Close editor on middle mouse click
if (e.button === 1 /* Middle Button */) {
this.editorService.closeEditor(position, group.activeEditor).done(null, errors.onUnexpectedError);
}
// Focus editor group unless click on toolbar
else if (this.stacks.groups.length === 1 && !this.targetInToolbar(<any>e.target || e.srcElement)) {
this.editorGroupService.focusGroup(position);
}
}
private targetInToolbar(target: HTMLElement): boolean {
return DOM.isAncestor(target, this.editorActionsToolbar.getContainer().getHTMLElement()) || DOM.isAncestor(target, this.groupActionsToolbar.getContainer().getHTMLElement());
}
protected redraw(): void {
if (!this.context) {
return;
}
const group = this.context;
const editor = group.activeEditor;
if (!editor) {
this.editorActionsToolbar.setActions([], [])();
this.groupActionsToolbar.setActions([], [])();
this.currentPrimaryEditorActionIds = [];
this.currentSecondaryEditorActionIds = [];
this.currentPrimaryGroupActionIds = [];
this.currentSecondaryGroupActionIds = [];
return; // return early if we are being closed
}
const isPinned = group.isPinned(group.activeEditor);
const isActive = this.stacks.isActive(group);
// Pinned state
if (isPinned) {
this.titleContainer.addClass('pinned');
} else {
this.titleContainer.removeClass('pinned');
}
// Activity state
if (isActive) {
this.titleContainer.removeClass('inactive');
} else {
this.titleContainer.addClass('inactive');
}
// Editor Title
let name = editor.getName() || '';
let description = isActive ? (editor.getDescription() || '') : '';
let verboseDescription = editor.getDescription(true) || '';
if (description === verboseDescription) {
verboseDescription = ''; // dont repeat what is already shown
}
this.titleLabel.safeInnerHtml(name);
this.titleLabel.title(verboseDescription);
this.titleDescription.safeInnerHtml(description);
this.titleDescription.title(verboseDescription);
// Editor Decoration
if (editor.isDirty()) {
this.titleDecoration.addClass('dirty');
} else {
this.titleDecoration.removeClass('dirty');
}
// Update Editor Actions Toolbar
const editorActions = this.getEditorActions(group);
const primaryEditorActions = prepareActions(editorActions.primary);
const secondaryEditorActions = prepareActions(editorActions.secondary);
const primaryEditorActionIds = primaryEditorActions.map(a => a.id);
const secondaryEditorActionIds = secondaryEditorActions.map(a => a.id);
if (!arrays.equals(primaryEditorActionIds, this.currentPrimaryEditorActionIds) || !arrays.equals(secondaryEditorActionIds, this.currentSecondaryEditorActionIds)) {
this.editorActionsToolbar.setActions(primaryEditorActions, secondaryEditorActions)();
this.editorActionsToolbar.addPrimaryAction(this.closeEditorAction)();
this.currentPrimaryEditorActionIds = primaryEditorActionIds;
this.currentSecondaryEditorActionIds = secondaryEditorActionIds;
}
// Update Group Actions Toolbar
const groupActions = this.getGroupActions(group);
const primaryGroupActionIds = groupActions.primary.map(a => a.id);
const secondaryGroupActionIds = groupActions.secondary.map(a => a.id);
if (!arrays.equals(primaryGroupActionIds, this.currentPrimaryGroupActionIds) || !arrays.equals(secondaryGroupActionIds, this.currentSecondaryGroupActionIds)) {
this.groupActionsToolbar.setActions(groupActions.primary, groupActions.secondary)();
this.currentPrimaryGroupActionIds = primaryGroupActionIds;
this.currentSecondaryGroupActionIds = secondaryGroupActionIds;
}
}
public dispose(): void {
super.dispose();
// Toolbars
this.groupActionsToolbar.dispose();
this.editorActionsToolbar.dispose();
}
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* 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 nls = require('vs/nls');
import {Registry} from 'vs/platform/platform';
import {Scope, IActionBarRegistry, Extensions} from 'vs/workbench/browser/actionBarRegistry';
import {IAction, Action} from 'vs/base/common/actions';
import errors = require('vs/base/common/errors');
import {Builder} from 'vs/base/browser/builder';
import {BaseEditor, IEditorInputActionContext} from 'vs/workbench/browser/parts/editor/baseEditor';
import {RunOnceScheduler} from 'vs/base/common/async';
import {IEditorStacksModel, IEditorGroup} 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 {Position} from 'vs/platform/editor/common/editor';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {IMessageService, Severity} from 'vs/platform/message/common/message';
import {QuickOpenAction} from 'vs/workbench/browser/quickopen';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {ShowEditorsInLeftGroupAction, ShowAllEditorsAction, ShowEditorsInCenterGroupAction, ShowEditorsInRightGroupAction, CloseEditorsInGroupAction, MoveGroupLeftAction, MoveGroupRightAction, SplitEditorAction, CloseEditorAction} from 'vs/workbench/browser/parts/editor/editorActions';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
export interface IToolbarActions {
primary: IAction[];
secondary: IAction[];
}
export interface ITitleAreaControl {
setContext(group: IEditorGroup): void;
create(parent: Builder): void;
dispose(): void;
}
export abstract class TitleControl {
protected stacks: IEditorStacksModel;
protected context: IEditorGroup;
protected closeEditorAction: CloseEditorAction;
protected showEditorsOfLeftGroup: QuickOpenAction;
protected showEditorsOfCenterGroup: QuickOpenAction;
protected showEditorsOfRightGroup: QuickOpenAction;
protected moveGroupLeftAction: MoveGroupLeftAction;
protected moveGroupRightAction: MoveGroupRightAction;
protected closeEditorsInGroupAction: CloseEditorsInGroupAction;
protected splitEditorAction: SplitEditorAction;
protected showAllEditorsAction: ShowAllEditorsAction;
private mapActionsToEditors: { [editorId: string]: IToolbarActions; };
private scheduler: RunOnceScheduler;
protected toDispose: IDisposable[];
constructor(
@IContextMenuService protected contextMenuService: IContextMenuService,
@IInstantiationService protected instantiationService: IInstantiationService,
@IWorkbenchEditorService protected editorService: IWorkbenchEditorService,
@IEditorGroupService protected editorGroupService: IEditorGroupService,
@IKeybindingService protected keybindingService: IKeybindingService,
@ITelemetryService protected telemetryService: ITelemetryService,
@IMessageService protected messageService: IMessageService
) {
this.toDispose = [];
this.stacks = editorGroupService.getStacksModel();
this.mapActionsToEditors = Object.create(null);
this.scheduler = new RunOnceScheduler(() => this.redraw(), 0);
this.toDispose.push(this.scheduler);
this.initActions();
}
public setContext(group: IEditorGroup): void {
this.context = group;
this.scheduler.schedule();
}
protected abstract redraw();
private initActions(): void {
this.closeEditorAction = this.instantiationService.createInstance(CloseEditorAction, CloseEditorAction.ID, nls.localize('close', "Close"));
this.showAllEditorsAction = this.instantiationService.createInstance(ShowAllEditorsAction, ShowAllEditorsAction.ID, nls.localize('showEditors', "Show Editors"));
this.splitEditorAction = this.instantiationService.createInstance(SplitEditorAction, SplitEditorAction.ID, SplitEditorAction.LABEL);
this.moveGroupLeftAction = this.instantiationService.createInstance(MoveGroupLeftAction, MoveGroupLeftAction.ID, nls.localize('moveLeft', "Move Left"));
this.moveGroupRightAction = this.instantiationService.createInstance(MoveGroupRightAction, MoveGroupRightAction.ID, nls.localize('moveRight', "Move Right"));
this.closeEditorsInGroupAction = this.instantiationService.createInstance(CloseEditorsInGroupAction, CloseEditorsInGroupAction.ID, nls.localize('closeAll', "Close All"));
this.showEditorsOfLeftGroup = this.instantiationService.createInstance(ShowEditorsInLeftGroupAction, ShowEditorsInLeftGroupAction.ID, nls.localize('showEditors', "Show Editors"));
this.showEditorsOfCenterGroup = this.instantiationService.createInstance(ShowEditorsInCenterGroupAction, ShowEditorsInCenterGroupAction.ID, nls.localize('showEditors', "Show Editors"));
this.showEditorsOfRightGroup = this.instantiationService.createInstance(ShowEditorsInRightGroupAction, ShowEditorsInRightGroupAction.ID, nls.localize('showEditors', "Show Editors"));
[this.showEditorsOfLeftGroup, this.showEditorsOfCenterGroup, this.showEditorsOfRightGroup, this.showAllEditorsAction].forEach(a => a.class = 'show-group-editors-action');
}
protected doCreateToolbar(container: Builder): ToolBar {
const toolbar = new ToolBar(container.getHTMLElement(), this.contextMenuService, {
actionItemProvider: (action: Action) => this.actionItemProvider(action),
orientation: ActionsOrientation.HORIZONTAL,
ariaLabel: nls.localize('araLabelEditorActions', "Editor actions"),
getKeyBinding: (action) => {
const opts = this.keybindingService.lookupKeybindings(action.id);
if (opts.length > 0) {
return opts[0]; // only take the first one
}
return null;
}
});
// Action Run Handling
this.toDispose.push(toolbar.actionRunner.addListener2(BaseEventType.RUN, (e: any) => {
// Check for Error
if (e.error && !errors.isPromiseCanceledError(e.error)) {
this.messageService.show(Severity.Error, e.error);
}
// Log in telemetry
if (this.telemetryService) {
this.telemetryService.publicLog('workbenchActionExecuted', { id: e.action.id, from: 'editorPart' });
}
}));
return toolbar;
}
protected actionItemProvider(action: Action): IActionItem {
if (!this.context) {
return null;
}
const group = this.context;
const position = this.stacks.positionOfGroup(group);
const editor = this.editorService.getVisibleEditors()[position];
let actionItem: IActionItem;
// Check Active Editor
if (editor instanceof BaseEditor) {
actionItem = editor.getActionItem(action);
}
// Check Registry
if (!actionItem) {
let actionBarRegistry = <IActionBarRegistry>Registry.as(Extensions.Actionbar);
actionItem = actionBarRegistry.getActionItemForContext(Scope.EDITOR, { input: editor && editor.input, editor, position }, action);
}
return actionItem;
}
protected getEditorActions(group: IEditorGroup): IToolbarActions {
const position = this.stacks.positionOfGroup(group);
const isActive = this.stacks.isActive(group);
const primary: IAction[] = [];
const secondary: IAction[] = [];
const editor = this.editorService.getVisibleEditors()[position];
if (isActive && editor instanceof BaseEditor) {
let editorActions = this.mapActionsToEditors[editor.getId()];
if (!editorActions) {
editorActions = this.getEditorActionsForContext(editor);
this.mapActionsToEditors[editor.getId()] = editorActions;
}
primary.push(...editorActions.primary);
secondary.push(...editorActions.secondary);
// Handle Editor Input Actions
let editorInputActions = this.getEditorActionsForContext({ input: editor.input, editor, position: editor.position });
primary.push(...editorInputActions.primary);
secondary.push(...editorInputActions.secondary);
}
return { primary, secondary };
}
protected getEditorActionsForContext(context: BaseEditor): IToolbarActions;
protected getEditorActionsForContext(context: IEditorInputActionContext): IToolbarActions;
protected getEditorActionsForContext(context: any): IToolbarActions {
let primaryActions: IAction[] = [];
let secondaryActions: IAction[] = [];
// From Editor
if (context instanceof BaseEditor) {
primaryActions.push(...(<BaseEditor>context).getActions());
secondaryActions.push(...(<BaseEditor>context).getSecondaryActions());
}
// From Contributions
let actionBarRegistry = <IActionBarRegistry>Registry.as(Extensions.Actionbar);
primaryActions.push(...actionBarRegistry.getActionBarActionsForContext(Scope.EDITOR, context));
secondaryActions.push(...actionBarRegistry.getSecondaryActionBarActionsForContext(Scope.EDITOR, context));
return {
primary: primaryActions,
secondary: secondaryActions
};
}
protected getGroupActions(group: IEditorGroup): IToolbarActions {
const position = this.stacks.positionOfGroup(group);
const editor = this.editorService.getVisibleEditors()[position];
const primary: IAction[] = [];
const isOverflowing = group.count > 1;
const groupCount = this.stacks.groups.length;
// Overflow
if (isOverflowing) {
let overflowAction: Action;
if (groupCount === 1) {
overflowAction = this.showAllEditorsAction;
} else {
switch (this.stacks.positionOfGroup(group)) {
case Position.LEFT:
overflowAction = this.showEditorsOfLeftGroup;
break;
case Position.CENTER:
overflowAction = (groupCount === 2) ? this.showEditorsOfRightGroup : this.showEditorsOfCenterGroup;
break;
case Position.RIGHT:
overflowAction = this.showEditorsOfRightGroup;
break;
}
}
primary.push(overflowAction);
}
// Splitting
if (editor && editor instanceof BaseEditor && editor.supportsSplitEditor()) {
primary.push(this.splitEditorAction);
}
// Make sure enablement is good
switch (this.stacks.positionOfGroup(group)) {
case Position.LEFT:
this.moveGroupLeftAction.enabled = false;
this.moveGroupRightAction.enabled = this.stacks.groups.length > 1;
break;
case Position.CENTER:
this.moveGroupRightAction.enabled = this.stacks.groups.length > 2;
break;
case Position.RIGHT:
this.moveGroupRightAction.enabled = false;
break;
}
// Return actions
const secondary = [
this.moveGroupLeftAction,
this.moveGroupRightAction,
new Separator(),
this.closeEditorsInGroupAction
];
return { primary, secondary };
}
public dispose(): void {
dispose(this.toDispose);
// Actions
[
this.splitEditorAction,
this.showAllEditorsAction,
this.showEditorsOfLeftGroup,
this.showEditorsOfCenterGroup,
this.showEditorsOfRightGroup,
this.closeEditorAction,
this.moveGroupLeftAction,
this.moveGroupRightAction,
this.closeEditorsInGroupAction
].forEach((action) => {
action.dispose();
});
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册