honor order when merging contributed menu items with legacy items, legacy items have order zero, #9153
This commit is contained in:
parent
0c2d41b39f
commit
c1b999fdb0
|
@ -18,19 +18,40 @@ import {Emitter} from 'vs/base/common/event';
|
|||
|
||||
|
||||
export function fillInActions(menu: IMenu, target: IAction[] | { primary: IAction[]; secondary: IAction[];}): void {
|
||||
const actions = menu.getActions();
|
||||
if (actions.length === 0) {
|
||||
const groups = menu.getActions();
|
||||
if (groups.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let tuple of actions) {
|
||||
for (let tuple of groups) {
|
||||
let [group, actions] = tuple;
|
||||
if (group === 'navigation') {
|
||||
if (Array.isArray<IAction>(target)) {
|
||||
target.unshift(...actions);
|
||||
} else {
|
||||
target.primary.unshift(...actions);
|
||||
|
||||
const head = Array.isArray<IAction>(target) ? target : target.primary;
|
||||
|
||||
// split contributed actions at the point where order
|
||||
// changes form lt zero to gte
|
||||
let pivot = 0;
|
||||
for (; pivot < actions.length; pivot++) {
|
||||
if ((<MenuItemAction>actions[pivot]).order >= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// prepend contributed actions with order lte zero
|
||||
head.unshift(...actions.slice(0, pivot));
|
||||
|
||||
// find the first separator which marks the end of the
|
||||
// navigation group - might be the whole array length
|
||||
let sep = 0;
|
||||
while (sep < head.length) {
|
||||
if (head[sep] instanceof Separator) {
|
||||
break;
|
||||
}
|
||||
sep++;
|
||||
}
|
||||
// append contributed actions with order gt zero
|
||||
head.splice(sep, 0, ...actions.slice(pivot));
|
||||
|
||||
} else {
|
||||
if (Array.isArray<IAction>(target)) {
|
||||
target.push(new Separator(), ...actions);
|
||||
|
|
|
@ -117,7 +117,7 @@ export class MenuItemAction extends Actions.Action {
|
|||
) {
|
||||
super(MenuItemAction._getMenuItemId(_item), _item.command.title);
|
||||
|
||||
this.order = 100000; //TODO@Ben order is menu item property, not an action property
|
||||
this.order = this._item.order; //TODO@Ben order is menu item property, not an action property
|
||||
}
|
||||
|
||||
set resource(value: URI) {
|
||||
|
|
Loading…
Reference in a new issue