Skip to content

Commit

Permalink
bring back editor actions for #7666
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jul 14, 2016
1 parent 26cdf6a commit 99aa1bc
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 153 deletions.
52 changes: 6 additions & 46 deletions src/vs/workbench/browser/parts/editor/noTabsTitleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
'use strict';

import 'vs/css!./media/notabstitle';
import {IAction} from 'vs/base/common/actions';
import {prepareActions} from 'vs/workbench/browser/actionBarRegistry';
import errors = require('vs/base/common/errors');
import arrays = require('vs/base/common/arrays');
import {IEditorGroup, EditorInput} from 'vs/workbench/common/editor';
import {IEditorGroup} from 'vs/workbench/common/editor';
import DOM = require('vs/base/browser/dom');
import {ToolBar} from 'vs/base/browser/ui/toolbar/toolbar';
import {TitleControl} from 'vs/workbench/browser/parts/editor/titleControl';

export class NoTabsTitleControl extends TitleControl {
Expand All @@ -21,11 +17,6 @@ export class NoTabsTitleControl extends TitleControl {
private titleDecoration: HTMLElement;
private titleDescription: HTMLElement;

private editorActionsToolbar: ToolBar;

private currentPrimaryEditorActionIds: string[] = [];
private currentSecondaryEditorActionIds: string[] = [];

public setContext(group: IEditorGroup): void {
super.setContext(group);

Expand Down Expand Up @@ -67,11 +58,11 @@ export class NoTabsTitleControl extends TitleControl {
// Right Actions Container
const actionsContainer = document.createElement('div');
DOM.addClass(actionsContainer, 'title-actions');

this.editorActionsToolbar = this.doCreateToolbar(actionsContainer);

this.titleContainer.appendChild(actionsContainer);

// Editor actions toolbar
this.createEditorActionsToolBar(actionsContainer);

// Context Menu
this.toDispose.push(DOM.addDisposableListener(this.titleContainer, DOM.EventType.CONTEXT_MENU, (e: Event) => this.onContextMenu({ group: this.context, editor: this.context.activeEditor }, e, this.titleContainer)));
}
Expand Down Expand Up @@ -121,10 +112,7 @@ export class NoTabsTitleControl extends TitleControl {
this.titleLabel.innerText = '';
this.titleDescription.innerText = '';

this.editorActionsToolbar.setActions([], [])();

this.currentPrimaryEditorActionIds = [];
this.currentSecondaryEditorActionIds = [];
this.clearEditorActionsToolbar();

return; // return early if we are being closed
}
Expand Down Expand Up @@ -168,34 +156,6 @@ export class NoTabsTitleControl extends TitleControl {
}

// Update Editor Actions Toolbar
let primaryEditorActions: IAction[] = [];
let secondaryEditorActions: IAction[] = [];
if (isActive) {
const editorActions = this.getEditorActions({ group, editor });
primaryEditorActions = prepareActions(editorActions.primary);
if (isActive && editor instanceof EditorInput && editor.supportsSplitEditor()) {
primaryEditorActions.push(this.splitEditorAction);
}
secondaryEditorActions = prepareActions(editorActions.secondary);
}

const primaryEditorActionIds = primaryEditorActions.map(a => a.id);
primaryEditorActionIds.push(this.closeEditorAction.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;
}
}

public dispose(): void {
super.dispose();

// Toolbars
this.editorActionsToolbar.dispose();
this.updateEditorActionsToolbar();
}
}
67 changes: 7 additions & 60 deletions src/vs/workbench/browser/parts/editor/tabsTitleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@

import 'vs/css!./media/tabstitle';
import nls = require('vs/nls');
import {IAction} from 'vs/base/common/actions';
import {prepareActions} from 'vs/workbench/browser/actionBarRegistry';
import arrays = require('vs/base/common/arrays');
import errors = require('vs/base/common/errors');
import DOM = require('vs/base/browser/dom');
import {isMacintosh} from 'vs/base/common/platform';
import {MIME_BINARY} from 'vs/base/common/mime';
import {Position} from 'vs/platform/editor/common/editor';
import {IEditorGroup, IEditorIdentifier, asFileEditorInput} from 'vs/workbench/common/editor';
import {ToolBar} from 'vs/base/browser/ui/toolbar/toolbar';
import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import {CommonKeybindings as Kb, KeyCode} from 'vs/base/common/keyCodes';
import {ActionBar, Separator} from 'vs/base/browser/ui/actionbar/actionbar';
import {ActionBar} from 'vs/base/browser/ui/actionbar/actionbar';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
Expand All @@ -42,13 +38,8 @@ export class TabsTitleControl extends TitleControl {
private tabsContainer: HTMLElement;
private activeTab: HTMLElement;
private scrollbar: ScrollableElement;

private editorActionsToolbar: ToolBar;
private tabDisposeables: IDisposable[] = [];

private currentPrimaryGroupActionIds: string[] = [];
private currentSecondaryGroupActionIds: string[] = [];

constructor(
@IContextMenuService contextMenuService: IContextMenuService,
@IInstantiationService instantiationService: IInstantiationService,
Expand All @@ -64,9 +55,6 @@ export class TabsTitleControl extends TitleControl {
) {
super(contextMenuService, instantiationService, configurationService, editorService, editorGroupService, keybindingService, telemetryService, messageService, menuService, quickOpenService);

this.currentPrimaryGroupActionIds = [];
this.currentSecondaryGroupActionIds = [];

this.tabDisposeables = [];
}

Expand Down Expand Up @@ -160,11 +148,13 @@ export class TabsTitleControl extends TitleControl {
}
}));

// Editor Actions
// Editor Actions Container
const editorActionsContainer = document.createElement('div');
DOM.addClass(editorActionsContainer, 'editor-actions');
this.titleContainer.appendChild(editorActionsContainer);
this.editorActionsToolbar = this.doCreateToolbar(editorActionsContainer);

// Editor Actions Toolbar
this.createEditorActionsToolBar(editorActionsContainer);
}

public allowDragging(element: HTMLElement): boolean {
Expand Down Expand Up @@ -221,17 +211,7 @@ export class TabsTitleControl extends TitleControl {
});

// Update Editor Actions Toolbar
const groupActions = this.getGroupActions(group);
const primaryGroupActions = groupActions.primary;
const secondaryGroupActions = groupActions.secondary;
const primaryGroupActionIds = primaryGroupActions.map(a => a.id);
const secondaryGroupActionIds = secondaryGroupActions.map(a => a.id);

if (!arrays.equals(primaryGroupActionIds, this.currentPrimaryGroupActionIds) || !arrays.equals(secondaryGroupActionIds, this.currentSecondaryGroupActionIds)) {
this.editorActionsToolbar.setActions(primaryGroupActions, secondaryGroupActions)();
this.currentPrimaryGroupActionIds = primaryGroupActionIds;
this.currentSecondaryGroupActionIds = secondaryGroupActionIds;
}
this.updateEditorActionsToolbar();

// Ensure the active tab is always revealed
this.layout();
Expand All @@ -243,10 +223,7 @@ export class TabsTitleControl extends TitleControl {
if (!editor) {
this.clearTabs();

this.editorActionsToolbar.setActions([], [])();

this.currentPrimaryGroupActionIds = [];
this.currentSecondaryGroupActionIds = [];
this.clearEditorActionsToolbar();

return; // return early if we are being closed
}
Expand Down Expand Up @@ -346,10 +323,6 @@ export class TabsTitleControl extends TitleControl {
scrollLeft: this.activeTab.offsetLeft
});
}

// Update enablement of certain actions that depend on overflow
const isOverflowing = (totalContainerWidth > visibleContainerWidth);
this.showEditorsInGroupAction.enabled = isOverflowing;
}

private hookTabListeners(tab: HTMLElement, identifier: IEditorIdentifier): void {
Expand Down Expand Up @@ -531,30 +504,4 @@ export class TabsTitleControl extends TitleControl {

return !isCopy || source.id === target.id;
}

protected getContextMenuActions(identifier: IEditorIdentifier): IAction[] {
const actions = super.getContextMenuActions(identifier);
const {editor, group} = identifier;

// Actions: For active editor
if (group.isActive(editor)) {
const editorActions = this.getEditorActions(identifier);
if (editorActions.primary.length) {
actions.push(new Separator(), ...prepareActions(editorActions.primary));
}

if (editorActions.secondary.length) {
actions.push(new Separator(), ...prepareActions(editorActions.secondary));
}
}

return actions;
}

public dispose(): void {
super.dispose();

// Toolbar
this.editorActionsToolbar.dispose();
}
}
Loading

0 comments on commit 99aa1bc

Please sign in to comment.