Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addMenu(menu: Menu, options: IMainMenu.IAddOptions = {}): void {
if (ArrayExt.firstIndexOf(this.menus, menu) > -1) {
return;
}
let rank = 'rank' in options ? options.rank : 100;
let rankItem = { menu, rank };
let index = ArrayExt.upperBound(this._items, rankItem, Private.itemCmp);
// Upon disposal, remove the menu and its rank reference.
menu.disposed.connect(this._onMenuDisposed, this);
ArrayExt.insert(this._items, index, rankItem);
/**
* Create a new menu.
*/
this.insertMenu(index, menu);
}
it('should take a rank as an option', () => {
const menu1 = new Menu({ commands });
const menu2 = new Menu({ commands });
mainMenu.addMenu(menu1, { rank: 300 });
mainMenu.addMenu(menu2, { rank: 200 });
expect(ArrayExt.firstIndexOf(mainMenu.menus, menu1)).to.equal(6);
expect(ArrayExt.firstIndexOf(mainMenu.menus, menu2)).to.equal(5);
});
});
it('should be reset when loading from disk', () => {
const model = new NotebookModel();
const cell = model.contentFactory.createCodeCell({});
model.cells.push(cell);
model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
expect(ArrayExt.firstIndexOf(toArray(model.cells), cell)).to.equal(-1);
expect(model.cells.length).to.equal(6);
});
it('should take a rank as an option', () => {
const menu1 = new Menu({ commands });
const menu2 = new Menu({ commands });
mainMenu.addMenu(menu1, { rank: 300 });
mainMenu.addMenu(menu2, { rank: 200 });
expect(ArrayExt.firstIndexOf(mainMenu.menus, menu1)).to.equal(6);
expect(ArrayExt.firstIndexOf(mainMenu.menus, menu2)).to.equal(5);
});
});
it('should be the second menu', () => {
expect(
ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.editMenu.menu)
).to.equal(1);
});
});
addWidgetExtension(
widgetName: string,
extension: DocumentRegistry.WidgetExtension
): IDisposable {
widgetName = widgetName.toLowerCase();
if (!(widgetName in this._extenders)) {
this._extenders[widgetName] = [];
}
let extenders = this._extenders[widgetName];
let index = ArrayExt.firstIndexOf(extenders, extension);
if (index !== -1) {
console.warn(`Duplicate registered extension for ${widgetName}`);
return new DisposableDelegate(Private.noOp);
}
this._extenders[widgetName].push(extension);
this._changed.emit({
type: 'widgetExtension',
name: widgetName,
change: 'added'
});
return new DisposableDelegate(() => {
ArrayExt.removeFirstOf(this._extenders[widgetName], extension);
this._changed.emit({
type: 'widgetExtension',
name: widgetName,
change: 'removed'