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;
}
function addSynctexCommands(
app: JupyterFrontEnd,
editorTracker: IEditorTracker,
pdfTracker: IPDFJSTracker,
serverSettings: ServerConnection.ISettings
): DisposableSet {
const disposables = new DisposableSet();
const hasPDFWidget = () => !!pdfTracker.currentWidget;
const hasEditorWidget = () => !!editorTracker.currentWidget;
// Add the command for the PDF-to-editor mapping.
disposables.add(
app.commands.addCommand(CommandIDs.synctexEdit, {
execute: () => {
// Get the pdf widget that had its contextMenu activated.
let widget = pdfTracker.currentWidget;
if (widget) {
// Get the page number.
const pos = widget.content.position;
// Request the synctex position for the PDF
return synctexEditRequest(
.then(([settings]) => {
let disposables = new DisposableSet();
const onSettingsUpdated = (settings: ISettingRegistry.ISettings) => {
// Get the new value of the synctex setting.
const val = settings.get('synctex').composite as boolean | null;
synctex = val === true || val === false ? val : true;
// Trash any existing synctex commands
disposables.dispose();
// If SyncTeX is enabled, add the commands.
if (synctex) {
disposables = addSynctexCommands(
app,
editorTracker,
pdfTracker,
serverSettings
);
}
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);
});
}