Skip to content

Commit

Permalink
fix #40910
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jan 4, 2018
1 parent 0721df7 commit a88b6e1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 109 deletions.
70 changes: 37 additions & 33 deletions src/vs/workbench/browser/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ export class ContributableActionProvider implements IActionProvider {
}

public hasActions(tree: ITree, element: any): boolean {
let context = this.toContext(tree, element);
const context = this.toContext(tree, element);

let contributors = this.registry.getActionBarContributors(Scope.VIEWER);
const contributors = this.registry.getActionBarContributors(Scope.VIEWER);
for (let i = 0; i < contributors.length; i++) {
let contributor = contributors[i];
const contributor = contributors[i];
if (contributor.hasActions(context)) {
return true;
}
Expand All @@ -95,13 +95,13 @@ export class ContributableActionProvider implements IActionProvider {
}

public getActions(tree: ITree, element: any): TPromise<IAction[]> {
let actions: IAction[] = [];
let context = this.toContext(tree, element);
const actions: IAction[] = [];
const context = this.toContext(tree, element);

// Collect Actions
let contributors = this.registry.getActionBarContributors(Scope.VIEWER);
const contributors = this.registry.getActionBarContributors(Scope.VIEWER);
for (let i = 0; i < contributors.length; i++) {
let contributor = contributors[i];
const contributor = contributors[i];
if (contributor.hasActions(context)) {
actions.push(...contributor.getActions(context));
}
Expand All @@ -111,11 +111,11 @@ export class ContributableActionProvider implements IActionProvider {
}

public hasSecondaryActions(tree: ITree, element: any): boolean {
let context = this.toContext(tree, element);
const context = this.toContext(tree, element);

let contributors = this.registry.getActionBarContributors(Scope.VIEWER);
const contributors = this.registry.getActionBarContributors(Scope.VIEWER);
for (let i = 0; i < contributors.length; i++) {
let contributor = contributors[i];
const contributor = contributors[i];
if (contributor.hasSecondaryActions(context)) {
return true;
}
Expand All @@ -125,13 +125,13 @@ export class ContributableActionProvider implements IActionProvider {
}

public getSecondaryActions(tree: ITree, element: any): TPromise<IAction[]> {
let actions: IAction[] = [];
let context = this.toContext(tree, element);
const actions: IAction[] = [];
const context = this.toContext(tree, element);

// Collect Actions
let contributors = this.registry.getActionBarContributors(Scope.VIEWER);
const contributors = this.registry.getActionBarContributors(Scope.VIEWER);
for (let i = 0; i < contributors.length; i++) {
let contributor = contributors[i];
const contributor = contributors[i];
if (contributor.hasSecondaryActions(context)) {
actions.push(...contributor.getSecondaryActions(context));
}
Expand All @@ -141,13 +141,13 @@ export class ContributableActionProvider implements IActionProvider {
}

public getActionItem(tree: ITree, element: any, action: Action): BaseActionItem {
let contributors = this.registry.getActionBarContributors(Scope.VIEWER);
let context = this.toContext(tree, element);
const contributors = this.registry.getActionBarContributors(Scope.VIEWER);
const context = this.toContext(tree, element);

for (let i = contributors.length - 1; i >= 0; i--) {
let contributor = contributors[i];
const contributor = contributors[i];

let itemProvider = contributor.getActionItem(context, action);
const itemProvider = contributor.getActionItem(context, action);
if (itemProvider) {
return itemProvider;
}
Expand All @@ -164,24 +164,28 @@ export function prepareActions(actions: IAction[]): IAction[] {
}

// Patch order if not provided
let lastOrder = -1;
for (let l = 0; l < actions.length; l++) {
let a = <any>actions[l];
const a = <any>actions[l];
if (types.isUndefinedOrNull(a.order)) {
a.order = l;
a.order = lastOrder++;
}
lastOrder = a.order;
}

// Sort by order
actions = actions.sort((first: Action, second: Action) => {
let firstOrder = first.order;
let secondOrder = second.order;
const firstOrder = first.order;
const secondOrder = second.order;
if (firstOrder < secondOrder) {
return -1;
} else if (firstOrder > secondOrder) {
}

if (firstOrder > secondOrder) {
return 1;
} else {
return 0;
}

return 0;
});

// Clean up leading separators
Expand All @@ -203,7 +207,7 @@ export function prepareActions(actions: IAction[]): IAction[] {

// Clean up trailing separators
for (let h = actions.length - 1; h >= 0; h--) {
let isSeparator = actions[h].id === Separator.ID;
const isSeparator = actions[h].id === Separator.ID;
if (isSeparator) {
actions.splice(h, 1);
} else {
Expand All @@ -214,7 +218,7 @@ export function prepareActions(actions: IAction[]): IAction[] {
// Clean up separator duplicates
let foundAction = false;
for (let k = actions.length - 1; k >= 0; k--) {
let isSeparator = actions[k].id === Separator.ID;
const isSeparator = actions[k].id === Separator.ID;
if (isSeparator && !foundAction) {
actions.splice(k, 1);
} else if (!isSeparator) {
Expand Down Expand Up @@ -274,7 +278,7 @@ class ActionBarRegistry implements IActionBarRegistry {
this.instantiationService = service;

while (this.actionBarContributorConstructors.length > 0) {
let entry = this.actionBarContributorConstructors.shift();
const entry = this.actionBarContributorConstructors.shift();
this.createActionBarContributor(entry.scope, entry.ctor);
}
}
Expand All @@ -293,7 +297,7 @@ class ActionBarRegistry implements IActionBarRegistry {
}

public getActionBarActionsForContext(scope: string, context: any): IAction[] {
let actions: IAction[] = [];
const actions: IAction[] = [];

// Go through contributors for scope
this.getContributors(scope).forEach((contributor: ActionBarContributor) => {
Expand All @@ -308,7 +312,7 @@ class ActionBarRegistry implements IActionBarRegistry {
}

public getSecondaryActionBarActionsForContext(scope: string, context: any): IAction[] {
let actions: IAction[] = [];
const actions: IAction[] = [];

// Go through contributors
this.getContributors(scope).forEach((contributor: ActionBarContributor) => {
Expand All @@ -323,10 +327,10 @@ class ActionBarRegistry implements IActionBarRegistry {
}

public getActionItemForContext(scope: string, context: any, action: Action): BaseActionItem {
let contributors = this.getContributors(scope);
const contributors = this.getContributors(scope);
for (let i = 0; i < contributors.length; i++) {
let contributor = contributors[i];
let item = contributor.getActionItem(context, action);
const contributor = contributors[i];
const item = contributor.getActionItem(context, action);
if (item) {
return item;
}
Expand Down
33 changes: 19 additions & 14 deletions src/vs/workbench/browser/parts/editor/editor.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import { SyncActionDescriptor, MenuRegistry, MenuId } from 'vs/platform/actions/
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import {
CloseEditorsInGroupAction, CloseEditorsInOtherGroupsAction, CloseAllEditorsAction, MoveGroupLeftAction, MoveGroupRightAction, SplitEditorAction, JoinTwoGroupsAction, OpenToSideAction, RevertAndCloseEditorAction,
CloseEditorsInOtherGroupsAction, CloseAllEditorsAction, MoveGroupLeftAction, MoveGroupRightAction, SplitEditorAction, JoinTwoGroupsAction, OpenToSideAction, RevertAndCloseEditorAction,
NavigateBetweenGroupsAction, FocusActiveGroupAction, FocusFirstGroupAction, FocusSecondGroupAction, FocusThirdGroupAction, EvenGroupWidthsAction, MaximizeGroupAction, MinimizeOtherGroupsAction, FocusPreviousGroup, FocusNextGroup, ShowEditorsInGroupOneAction,
toEditorQuickOpenEntry, CloseLeftEditorsInGroupAction, CloseUnmodifiedEditorsInGroupAction, OpenNextEditor, OpenPreviousEditor, NavigateBackwardsAction, NavigateForwardAction, NavigateLastAction, ReopenClosedEditorAction, OpenPreviousRecentlyUsedEditorInGroupAction, NAVIGATE_IN_GROUP_ONE_PREFIX,
OpenPreviousEditorFromHistoryAction, ShowAllEditorsAction, NAVIGATE_ALL_EDITORS_GROUP_PREFIX, ClearEditorHistoryAction, ShowEditorsInGroupTwoAction, MoveEditorRightInGroupAction, OpenNextEditorInGroup, OpenPreviousEditorInGroup, OpenNextRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorAction,
NAVIGATE_IN_GROUP_TWO_PREFIX, ShowEditorsInGroupThreeAction, NAVIGATE_IN_GROUP_THREE_PREFIX, FocusLastEditorInStackAction, OpenNextRecentlyUsedEditorInGroupAction, MoveEditorToPreviousGroupAction, MoveEditorToNextGroupAction, MoveEditorToFirstGroupAction, MoveEditorToSecondGroupAction, MoveEditorToThirdGroupAction, MoveEditorLeftInGroupAction, ClearRecentFilesAction, OpenLastEditorInGroup
toEditorQuickOpenEntry, CloseLeftEditorsInGroupAction, OpenNextEditor, OpenPreviousEditor, NavigateBackwardsAction, NavigateForwardAction, NavigateLastAction, ReopenClosedEditorAction, OpenPreviousRecentlyUsedEditorInGroupAction,
OpenPreviousEditorFromHistoryAction, ShowAllEditorsAction, ClearEditorHistoryAction, ShowEditorsInGroupTwoAction, MoveEditorRightInGroupAction, OpenNextEditorInGroup, OpenPreviousEditorInGroup, OpenNextRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorAction,
ShowEditorsInGroupThreeAction, FocusLastEditorInStackAction, OpenNextRecentlyUsedEditorInGroupAction, MoveEditorToPreviousGroupAction, MoveEditorToNextGroupAction, MoveEditorToFirstGroupAction, MoveEditorToSecondGroupAction, MoveEditorToThirdGroupAction, MoveEditorLeftInGroupAction, ClearRecentFilesAction, OpenLastEditorInGroup
} from 'vs/workbench/browser/parts/editor/editorActions';
import * as editorCommands from 'vs/workbench/browser/parts/editor/editorCommands';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
Expand Down Expand Up @@ -265,21 +265,21 @@ Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpen
new QuickOpenHandlerDescriptor(
GroupOnePicker,
GroupOnePicker.ID,
NAVIGATE_IN_GROUP_ONE_PREFIX,
editorCommands.NAVIGATE_IN_GROUP_ONE_PREFIX,
editorPickerContextKey,
[
{
prefix: NAVIGATE_IN_GROUP_ONE_PREFIX,
prefix: editorCommands.NAVIGATE_IN_GROUP_ONE_PREFIX,
needsEditor: false,
description: nls.localize('groupOnePicker', "Show Editors in First Group")
},
{
prefix: NAVIGATE_IN_GROUP_TWO_PREFIX,
prefix: editorCommands.NAVIGATE_IN_GROUP_TWO_PREFIX,
needsEditor: false,
description: nls.localize('groupTwoPicker', "Show Editors in Second Group")
},
{
prefix: NAVIGATE_IN_GROUP_THREE_PREFIX,
prefix: editorCommands.NAVIGATE_IN_GROUP_THREE_PREFIX,
needsEditor: false,
description: nls.localize('groupThreePicker', "Show Editors in Third Group")
}
Expand All @@ -291,7 +291,7 @@ Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpen
new QuickOpenHandlerDescriptor(
GroupTwoPicker,
GroupTwoPicker.ID,
NAVIGATE_IN_GROUP_TWO_PREFIX,
editorCommands.NAVIGATE_IN_GROUP_TWO_PREFIX,
editorPickerContextKey,
[]
)
Expand All @@ -301,7 +301,7 @@ Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpen
new QuickOpenHandlerDescriptor(
GroupThreePicker,
GroupThreePicker.ID,
NAVIGATE_IN_GROUP_THREE_PREFIX,
editorCommands.NAVIGATE_IN_GROUP_THREE_PREFIX,
editorPickerContextKey,
[]
)
Expand All @@ -311,11 +311,11 @@ Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpen
new QuickOpenHandlerDescriptor(
AllEditorsPicker,
AllEditorsPicker.ID,
NAVIGATE_ALL_EDITORS_GROUP_PREFIX,
editorCommands.NAVIGATE_ALL_EDITORS_GROUP_PREFIX,
editorPickerContextKey,
[
{
prefix: NAVIGATE_ALL_EDITORS_GROUP_PREFIX,
prefix: editorCommands.NAVIGATE_ALL_EDITORS_GROUP_PREFIX,
needsEditor: false,
description: nls.localize('allEditorsPicker', "Show All Opened Editors")
}
Expand All @@ -340,8 +340,6 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(ReopenClosedEditorActi
registry.registerWorkbenchAction(new SyncActionDescriptor(ClearRecentFilesAction, ClearRecentFilesAction.ID, ClearRecentFilesAction.LABEL), 'File: Clear Recently Opened', nls.localize('file', "File"));
registry.registerWorkbenchAction(new SyncActionDescriptor(CloseAllEditorsAction, CloseAllEditorsAction.ID, CloseAllEditorsAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_W) }), 'View: Close All Editors', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(CloseLeftEditorsInGroupAction, CloseLeftEditorsInGroupAction.ID, CloseLeftEditorsInGroupAction.LABEL), 'View: Close Editors to the Left', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(CloseUnmodifiedEditorsInGroupAction, CloseUnmodifiedEditorsInGroupAction.ID, CloseUnmodifiedEditorsInGroupAction.LABEL), 'View: Close Unmodified Editors in Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(CloseEditorsInGroupAction, CloseEditorsInGroupAction.ID, CloseEditorsInGroupAction.LABEL), 'View: Close All Editors in Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(CloseEditorsInOtherGroupsAction, CloseEditorsInOtherGroupsAction.ID, CloseEditorsInOtherGroupsAction.LABEL), 'View: Close Editors in Other Groups', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(SplitEditorAction, SplitEditorAction.ID, SplitEditorAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.US_BACKSLASH }), 'View: Split Editor', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(JoinTwoGroupsAction, JoinTwoGroupsAction.ID, JoinTwoGroupsAction.LABEL), 'View: Join Editors of Two Groups', category);
Expand Down Expand Up @@ -423,7 +421,14 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: editorCo
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: editorCommands.CLOSE_EDITORS_IN_GROUP_COMMAND_ID, title: nls.localize('closeAll', "Close All") }, group: '1_close', order: 50 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: editorCommands.KEEP_EDITOR_COMMAND_ID, title: nls.localize('keepOpen', "Keep Open") }, group: '3_preview', order: 10, when: ContextKeyExpr.has('config.workbench.editor.enablePreview') });

// Editor Title Menu
MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { id: editorCommands.SHOW_EDITORS_IN_GROUP, title: nls.localize('showOpenedEditors', "Show Opened Editors") }, group: '3_open', order: 10, when: ContextKeyExpr.has('config.workbench.editor.showTabs') });
MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { id: editorCommands.CLOSE_EDITORS_IN_GROUP_COMMAND_ID, title: nls.localize('closeAll', "Close All") }, group: '4_close', order: 10, when: ContextKeyExpr.has('config.workbench.editor.showTabs') });
MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { id: editorCommands.CLOSE_UNMODIFIED_EDITORS_COMMAND_ID, title: nls.localize('closeAllUnmodified', "Close Unmodified") }, group: '4_close', order: 20, when: ContextKeyExpr.has('config.workbench.editor.showTabs') });

// Editor Commands for Command Palette
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: editorCommands.KEEP_EDITOR_COMMAND_ID, title: nls.localize('keepEditor', "Keep Editor"), category }, when: ContextKeyExpr.has('config.workbench.editor.enablePreview') });
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: editorCommands.CLOSE_EDITORS_IN_GROUP_COMMAND_ID, title: nls.localize('closeEditorsInGroup', "Close All Editors in Group"), category } });
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: editorCommands.CLOSE_UNMODIFIED_EDITORS_COMMAND_ID, title: nls.localize('closeUnmodifiedEditors', "Close Unmodified Editors in Group"), category } });
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: editorCommands.CLOSE_OTHER_EDITORS_IN_GROUP_COMMAND_ID, title: nls.localize('closeOtherEditors', "Close Other Editors"), category } });
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: editorCommands.CLOSE_EDITORS_TO_THE_RIGHT_COMMAND_ID, title: nls.localize('closeRightEditors', "Close Editors to the Right"), category } });
42 changes: 1 addition & 41 deletions src/vs/workbench/browser/parts/editor/editorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { IEditorGroupService, GroupArrangement } from 'vs/workbench/services/gro
import { ICommandService } from 'vs/platform/commands/common/commands';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IWindowsService } from 'vs/platform/windows/common/windows';
import { CLOSE_UNMODIFIED_EDITORS_COMMAND_ID, CLOSE_EDITORS_IN_GROUP_COMMAND_ID, CLOSE_EDITOR_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
import { CLOSE_UNMODIFIED_EDITORS_COMMAND_ID, CLOSE_EDITORS_IN_GROUP_COMMAND_ID, CLOSE_EDITOR_COMMAND_ID, NAVIGATE_IN_GROUP_ONE_PREFIX, NAVIGATE_ALL_EDITORS_GROUP_PREFIX, NAVIGATE_IN_GROUP_THREE_PREFIX, NAVIGATE_IN_GROUP_TWO_PREFIX } from 'vs/workbench/browser/parts/editor/editorCommands';

export class SplitEditorAction extends Action {

Expand Down Expand Up @@ -1058,8 +1058,6 @@ export class ClearRecentFilesAction extends Action {
}
}

export const NAVIGATE_IN_GROUP_ONE_PREFIX = 'edt one ';

export class ShowEditorsInGroupOneAction extends QuickOpenAction {

public static readonly ID = 'workbench.action.showEditorsInFirstGroup';
Expand All @@ -1076,8 +1074,6 @@ export class ShowEditorsInGroupOneAction extends QuickOpenAction {
}
}

export const NAVIGATE_IN_GROUP_TWO_PREFIX = 'edt two ';

export class ShowEditorsInGroupTwoAction extends QuickOpenAction {

public static readonly ID = 'workbench.action.showEditorsInSecondGroup';
Expand All @@ -1094,8 +1090,6 @@ export class ShowEditorsInGroupTwoAction extends QuickOpenAction {
}
}

export const NAVIGATE_IN_GROUP_THREE_PREFIX = 'edt three ';

export class ShowEditorsInGroupThreeAction extends QuickOpenAction {

public static readonly ID = 'workbench.action.showEditorsInThirdGroup';
Expand All @@ -1112,40 +1106,6 @@ export class ShowEditorsInGroupThreeAction extends QuickOpenAction {
}
}

export class ShowEditorsInGroupAction extends Action {

public static readonly ID = 'workbench.action.showEditorsInGroup';
public static readonly LABEL = nls.localize('showEditorsInGroup', "Show Editors in Group");

constructor(
id: string,
label: string,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IEditorGroupService private editorGroupService: IEditorGroupService
) {
super(id, label);
}

public run(context?: IEditorContext): TPromise<any> {
const stacks = this.editorGroupService.getStacksModel();
const groupCount = stacks.groups.length;
if (groupCount <= 1 || !context) {
return this.quickOpenService.show(NAVIGATE_ALL_EDITORS_GROUP_PREFIX);
}

switch (stacks.positionOfGroup(context.group)) {
case Position.TWO:
return this.quickOpenService.show(NAVIGATE_IN_GROUP_TWO_PREFIX);
case Position.THREE:
return this.quickOpenService.show(NAVIGATE_IN_GROUP_THREE_PREFIX);
}

return this.quickOpenService.show(NAVIGATE_IN_GROUP_ONE_PREFIX);
}
}

export const NAVIGATE_ALL_EDITORS_GROUP_PREFIX = 'edt ';

export class ShowAllEditorsAction extends QuickOpenAction {

public static readonly ID = 'workbench.action.showAllEditors';
Expand Down

0 comments on commit a88b6e1

Please sign in to comment.