From 3509f35d98117c90ca93032cb96810ad80456d8d Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Fri, 14 Jun 2019 14:24:01 -0700 Subject: [PATCH] separate inline and context actions for comment node --- .../contrib/comments/browser/commentMenus.ts | 2 +- .../contrib/comments/browser/commentNode.ts | 48 ++++++++++++++++--- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/contrib/comments/browser/commentMenus.ts b/src/vs/workbench/contrib/comments/browser/commentMenus.ts index e5ba3f06f5b..bdcf3118728 100644 --- a/src/vs/workbench/contrib/comments/browser/commentMenus.ts +++ b/src/vs/workbench/contrib/comments/browser/commentMenus.ts @@ -47,7 +47,7 @@ export class CommentMenus implements IDisposable { const secondary: IAction[] = []; const result = { primary, secondary }; - createAndFillInContextMenuActions(menu, { shouldForwardArgs: true }, result, this.contextMenuService, g => true); + createAndFillInContextMenuActions(menu, { shouldForwardArgs: true }, result, this.contextMenuService, g => /^inline/.test(g)); return menu; } diff --git a/src/vs/workbench/contrib/comments/browser/commentNode.ts b/src/vs/workbench/contrib/comments/browser/commentNode.ts index f86440c5efa..f4ac3fe8dd5 100644 --- a/src/vs/workbench/contrib/comments/browser/commentNode.ts +++ b/src/vs/workbench/contrib/comments/browser/commentNode.ts @@ -6,7 +6,7 @@ import * as nls from 'vs/nls'; import * as dom from 'vs/base/browser/dom'; import * as modes from 'vs/editor/common/modes'; -import { ActionsOrientation, ActionViewItem, ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; +import { ActionsOrientation, ActionViewItem, ActionBar, Separator } from 'vs/base/browser/ui/actionbar/actionbar'; import { Button } from 'vs/base/browser/ui/button/button'; import { Action, IActionRunner, IAction } from 'vs/base/common/actions'; import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; @@ -35,7 +35,7 @@ import { ToggleReactionsAction, ReactionAction, ReactionActionViewItem } from '. import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget'; -import { MenuItemAction } from 'vs/platform/actions/common/actions'; +import { MenuItemAction, SubmenuItemAction } from 'vs/platform/actions/common/actions'; import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; @@ -153,6 +153,7 @@ export class CommentNode extends Disposable { private createActionsToolbar() { const actions: IAction[] = []; + const secondaryActions: IAction[] = []; let hasReactionHandler = this.commentService.hasReactionHandler(this.owner); @@ -188,12 +189,22 @@ export class CommentNode extends Disposable { const menu = commentMenus.getCommentTitleActions(this.comment, this._contextKeyService); this._register(menu); this._register(menu.onDidChange(e => { - const contributedActions = menu.getActions({ shouldForwardArgs: true }).reduce((r, [, actions]) => [...r, ...actions], []); - this.toolbar.setActions(contributedActions); + const primary: IAction[] = []; + const secondary: IAction[] = []; + const result = { primary, secondary }; + fillInActions(contributedActions, result, false, g => /^inline/.test(g)); + this.toolbar.setActions(primary, secondary); })); - const contributedActions = menu.getActions({ shouldForwardArgs: true }).reduce((r, [, actions]) => [...r, ...actions], []); - actions.push(...contributedActions); + const contributedActions = menu.getActions({ shouldForwardArgs: true }); + { + const primary: IAction[] = []; + const secondary: IAction[] = []; + const result = { primary, secondary }; + fillInActions(contributedActions, result, false, g => /^inline/.test(g)); + actions.push(...primary); + secondaryActions.push(...secondary); + } if (actions.length) { this.toolbar = new ToolBar(this._actionsToolbarContainer, this.contextMenuService, { @@ -224,7 +235,7 @@ export class CommentNode extends Disposable { }; this.registerActionBarListeners(this._actionsToolbarContainer); - this.toolbar.setActions(actions, [])(); + this.toolbar.setActions(actions, secondaryActions)(); this._register(this.toolbar); } } @@ -727,4 +738,27 @@ export class CommentNode extends Disposable { }, 3000); } } +} + +function fillInActions(groups: [string, Array][], target: IAction[] | { primary: IAction[]; secondary: IAction[]; }, useAlternativeActions: boolean, isPrimaryGroup: (group: string) => boolean = group => group === 'navigation'): void { + for (let tuple of groups) { + let [group, actions] = tuple; + if (useAlternativeActions) { + actions = actions.map(a => (a instanceof MenuItemAction) && !!a.alt ? a.alt : a); + } + + if (isPrimaryGroup(group)) { + const to = Array.isArray(target) ? target : target.primary; + + to.unshift(...actions); + } else { + const to = Array.isArray(target) ? target : target.secondary; + + if (to.length > 0) { + to.push(new Separator()); + } + + to.push(...actions); + } + } } \ No newline at end of file -- GitLab