Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// trailing, and duplicate separators.
if (this._includeSeparators) {
added.push(this.menu.insertItem(insertIndex++, { type: 'separator' }));
}
// Insert the group.
for (let item of items) {
added.push(this.menu.insertItem(insertIndex++, item));
}
// Insert a separator after the group.
if (this._includeSeparators) {
added.push(this.menu.insertItem(insertIndex++, { type: 'separator' }));
}
ArrayExt.insert(this._groups, groupIndex, rankGroup);
return new DisposableDelegate(() => {
added.forEach(i => this.menu.removeItem(i));
this._groups.splice(groupIndex, 1);
});
}
loc: TableLocation<s>,
slot: (source: Datastore, args: Table.Change<s>) => void,
thisArg?: any
): IDisposable {
// A wrapper change signal connection function.
const wrapper = (source: Datastore, args: Datastore.IChangedArgs) => {
// Ignore changes that don't match the requested record.
if (!args.change[loc.schema.id]) {
return;
}
// Otherwise, call the slot.
const tc = args.change[loc.schema.id]! as Table.Change<s>;
slot.bind(thisArg)(source, tc);
};
datastore.changed.connect(wrapper);
return new DisposableDelegate(() => {
datastore.changed.disconnect(wrapper);
});
}
</s></s></s>
}
} else if (align === 'right') {
let insertIndex = this._findInsertIndex(this._rightRankItems, rankItem);
if (insertIndex === -1) {
this._rightSide.addWidget(item);
this._rightRankItems.push(rankItem);
} else {
ArrayExt.insert(this._rightRankItems, insertIndex, rankItem);
this._rightSide.insertWidget(insertIndex, item);
}
} else {
this._middlePanel.addWidget(item);
}
this._refreshItem(id); // Initially refresh the status item.
const disposable = new DisposableDelegate(() => {
delete this._statusItems[id];
if (fullStatusItem.activeStateChanged) {
fullStatusItem.activeStateChanged.disconnect(onActiveStateChanged);
}
item.parent = null;
item.dispose();
});
this._disposables.add(disposable);
return disposable;
}
createNew(widget: Widget, context: DocumentRegistry.Context): IDisposable {
return new DisposableDelegate(() => undefined);
}
}
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'
});
});
}
addFileType(fileType: Partial): IDisposable {
let value: DocumentRegistry.IFileType = {
...DocumentRegistry.fileTypeDefaults,
...fileType
};
this._fileTypes.push(value);
this._changed.emit({
type: 'fileType',
name: value.name,
change: 'added'
});
return new DisposableDelegate(() => {
ArrayExt.removeFirstOf(this._fileTypes, value);
this._changed.emit({
type: 'fileType',
name: fileType.name,
change: 'removed'
});
});
}
addWidgetFactory(factory: DocumentRegistry.WidgetFactory): IDisposable {
let name = factory.name.toLowerCase();
if (!name || name === 'default') {
throw Error('Invalid factory name');
}
if (this._widgetFactories[name]) {
console.warn(`Duplicate registered factory ${name}`);
return new DisposableDelegate(Private.noOp);
}
this._widgetFactories[name] = factory;
for (let ft of factory.defaultFor || []) {
if (factory.fileTypes.indexOf(ft) === -1) {
continue;
}
if (ft === '*') {
this._defaultWidgetFactory = name;
} else {
this._defaultWidgetFactories[ft] = name;
}
}
for (let ft of factory.defaultRendered || []) {
if (factory.fileTypes.indexOf(ft) === -1) {
continue;
}
addKeydownHandler(handler: CodeEditor.KeydownHandler): IDisposable {
this._keydownHandlers.push(handler);
return new DisposableDelegate(() => {
ArrayExt.removeAllWhere(this._keydownHandlers, val => val === handler);
});
}
addItem(options: IPaletteItem): IDisposable {
let item = this._palette.addItem(options as CommandPalette.IItemOptions);
return new DisposableDelegate(() => {
this._palette.removeItem(item);
});
}
register(options: IRouter.IRegisterOptions): IDisposable {
const { command, pattern } = options;
const rank = options.rank ?? 100;
const rules = this._rules;
rules.set(pattern, { command, rank });
return new DisposableDelegate(() => {
rules.delete(pattern);
});
}