Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Do nothing if already trusted.
const cells = toArray(notebook.model.cells);
const trusted = cells.every(cell => cell.trusted);
if (trusted) {
return showDialog({
body: 'Notebook is already trusted',
buttons: [Dialog.okButton()]
}).then(() => undefined);
}
return showDialog({
body: TRUST_MESSAGE,
title: 'Trust this notebook?',
buttons: [Dialog.cancelButton(), Dialog.warnButton()]
}).then(result => {
if (result.button.accept) {
cells.forEach(cell => {
cell.trusted = true;
});
}
});
}
}
return factory.readOnly === false;
})
);
let factory = Private.factoryProperty.get(widget);
if (!factory) {
return Promise.resolve(true);
}
let model = context.model;
if (!model.dirty || widgets.length > 1 || factory.readOnly) {
return Promise.resolve(true);
}
let fileName = widget.title.label;
return showDialog({
title: 'Close without saving?',
body: `File "${fileName}" has unsaved changes, close without saving?`,
buttons: [Dialog.cancelButton(), Dialog.warnButton()]
}).then(result => {
return result.button.accept;
});
}
closeAndCleanup: (current: NotebookPanel) => {
const fileName = current.title.label;
return showDialog({
title: 'Shutdown the notebook?',
body: `Are you sure you want to close "${fileName}"?`,
buttons: [Dialog.cancelButton(), Dialog.warnButton()]
}).then(result => {
if (result.button.accept) {
return current.context.session.shutdown().then(() => {
current.dispose();
});
}
});
}
} as IFileMenu.ICloseAndCleaner);
function recover(fn: () => void): void {
if (dialog) {
return;
}
dialog = new Dialog({
title: 'Loading...',
body: `The loading screen is taking a long time.
Would you like to clear the workspace or keep waiting?`,
buttons: [
Dialog.cancelButton({ label: 'Keep Waiting' }),
Dialog.warnButton({ label: 'Clear Workspace' })
]
});
dialog
.launch()
.then(result => {
if (result.button.accept) {
return fn();
}
dialog.dispose();
dialog = null;
debouncer = window.setTimeout(() => {
recover(fn);
}, SPLASH_RECOVER_TIMEOUT);
private async _shouldUploadLarge(file: File): Promise {
const { button } = await showDialog({
title: 'Large file size warning',
body: `The file size is ${Math.round(
file.size / (1024 * 1024)
)} MB. Do you still want to upload it?`,
buttons: [Dialog.cancelButton(), Dialog.warnButton({ label: 'UPLOAD' })]
});
return button.accept;
}
each(this._sortedItems, item => {
if (this._selection[item.name]) {
names.push(item.name);
}
});
let message = `Are you sure you want to permanently delete the ${
names.length
} files/folders selected?`;
if (names.length === 1) {
message = `Are you sure you want to permanently delete: ${names[0]}?`;
}
if (names.length) {
return showDialog({
title: 'Delete',
body: message,
buttons: [Dialog.cancelButton(), Dialog.warnButton({ label: 'DELETE' })]
}).then(result => {
if (!this.isDisposed && result.button.accept) {
return this._delete(names);
}
});
}
return Promise.resolve(void 0);
}
<h3>Results</h3>
<ul>{result}</ul>
)}
{training.status.message != null && training.status.message !== '' && (
<div>
<h3>Message state</h3>
<p>{training.status.message}</p>
</div>
)}
),
buttons: [
Dialog.okButton({ label: LOGS_LABEL }),
Dialog.warnButton({ label: REMOVE_TRAINING_LABEL }),
Dialog.cancelButton({ label: 'Close window' })
]
});
}
.then(() => {
return showDialog({
title: 'Build Complete',
body: 'Build successfully completed, reload page?',
buttons: [
Dialog.cancelButton(),
Dialog.warnButton({ label: 'RELOAD' })
]
});
})
.then(result => {
<div>
<h3>Results</h3>
<ul>{result}</ul>
</div>
)}
{mp.status.message != null && mp.status.message !== '' && (
<div>
<h3>Message state</h3>
<p>{mp.status.message}</p>
</div>
)}
),
buttons: [
Dialog.okButton({ label: LOGS_LABEL }),
Dialog.warnButton({ label: REMOVE_MODEL_PACKING_LABEL }),
Dialog.cancelButton({ label: 'Close window' })
]
});
}
private _maybeOverWrite(path: string): Promise {
let body = `"${path}" already exists. Do you want to replace it?`;
let overwriteBtn = Dialog.warnButton({ label: 'Overwrite' });
return showDialog({
title: 'File Overwrite?',
body,
buttons: [Dialog.cancelButton(), overwriteBtn]
}).then(result => {
if (this.isDisposed) {
return Promise.reject(new Error('Disposed'));
}
if (result.button.label === 'Overwrite') {
return this._manager.contents.delete(path).then(() => {
return this._finishSaveAs(path);
});
}
});
}