Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should be resilient to a slow initial fetch', async () => {
let delayedServiceManager = new ServiceManager();
(delayedServiceManager as any).contents = new DelayedContentsManager();
let manager = new DocumentManager({
registry,
opener,
manager: delayedServiceManager
});
model = new FileBrowserModel({ manager, state });
const paths: string[] = [];
// An initial refresh is called in the constructor.
// If it is too slow, it can come in after the directory change,
// causing a directory set by, e.g., the tree handler to be wrong.
// This checks to make sure we are handling that case correctly.
const refresh = model.refresh().then(() => paths.push(model.path));
const cd = model.cd('src').then(() => paths.push(model.path));
await Promise.all([refresh, cd]);
expect(model.path).to.equal('src');
expect(paths).to.eql(['', 'src']);
if (!widget.isAttached) {
shell.add(widget, 'main', options || {});
}
shell.activateById(widget.id);
// Handle dirty state for open documents.
let context = docManager.contextForWidget(widget);
if (!contexts.has(context)) {
handleContext(status, context);
contexts.add(context);
}
}
};
const registry = app.docRegistry;
const when = app.restored.then(() => void 0);
const docManager = new DocumentManager({
registry,
manager,
opener,
when,
setBusy: status.setBusy.bind(app)
});
// Register the file operations commands.
addCommands(
app,
docManager,
opener,
settingRegistry,
labShell,
palette,
mainMenu
document.addEventListener('keydown', event => {
commands.processKeydownEvent(event);
}, useCapture);
let rendermime = new RenderMime({
initialFactories: defaultRendererFactories
});
let opener = {
open: (widget: Widget) => {
// Do nothing for sibling widgets for now.
}
};
let docRegistry = new DocumentRegistry();
let docManager = new DocumentManager({
registry: docRegistry,
manager,
opener
});
let mFactory = new NotebookModelFactory({});
let editorFactory = editorServices.factoryService.newInlineEditor.bind(
editorServices.factoryService);
let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });
let wFactory = new NotebookWidgetFactory({
name: 'Notebook',
modelName: 'notebook',
fileExtensions: ['.ipynb'],
defaultFor: ['.ipynb'],
preferKernel: true,
canStartKernel: true,
let rendermime = new RenderMimeRegistry({
initialFactories: initialFactories,
latexTypesetter: new MathJaxTypesetter({
url: PageConfig.getOption('mathjaxUrl'),
config: PageConfig.getOption('mathjaxConfig')
})
});
let opener = {
open: (widget: Widget) => {
// Do nothing for sibling widgets for now.
}
};
let docRegistry = new DocumentRegistry();
let docManager = new DocumentManager({
registry: docRegistry,
manager,
opener
});
let mFactory = new NotebookModelFactory({});
let editorFactory = editorServices.factoryService.newInlineEditor;
let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });
let wFactory = new NotebookWidgetFactory({
name: 'Notebook',
modelName: 'notebook',
fileTypes: ['notebook'],
defaultFor: ['notebook'],
preferKernel: true,
canStartKernel: true,
rendermime,
if (!widget.isAttached) {
shell.add(widget, 'main', options || {});
}
shell.activateById(widget.id);
// Handle dirty state for open documents.
let context = docManager.contextForWidget(widget);
if (!contexts.has(context)) {
handleContext(status, context);
contexts.add(context);
}
}
};
const registry = app.docRegistry;
const when = app.restored.then(() => void 0);
const docManager = new DocumentManager({
registry,
manager,
opener,
when,
setBusy: status && (() => status.setBusy())
});
// Register the file operations commands.
addCommands(
app,
docManager,
opener,
settingRegistry,
labShell,
palette,
mainMenu
let rendermime = new RenderMimeRegistry({
initialFactories: initialFactories,
latexTypesetter: new MathJaxTypesetter({
url: PageConfig.getOption('mathjaxUrl'),
config: PageConfig.getOption('mathjaxConfig')
})
});
let opener = {
open: (widget: Widget) => {
// Do nothing for sibling widgets for now.
}
};
let docRegistry = new DocumentRegistry();
let docManager = new DocumentManager({
registry: docRegistry,
manager,
opener
});
let mFactory = new NotebookModelFactory({});
let editorFactory = editorServices.factoryService.newInlineEditor;
let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });
let wFactory = new NotebookWidgetFactory({
name: 'Notebook',
modelName: 'notebook',
fileTypes: ['notebook'],
defaultFor: ['notebook'],
preferKernel: true,
canStartKernel: true,
rendermime,
document.addEventListener(
'keydown',
event => {
this.commands.processKeydownEvent(event);
},
useCapture
);
let opener = {
open: (widget: Widget) => {
// Do nothing for sibling widgets for now.
}
};
let docRegistry = new DocumentRegistry();
let docManager = new DocumentManager({
registry: docRegistry,
manager: this.props.serviceManager,
opener
});
let mFactory = new NotebookModelFactory({});
let editorFactory = editorServices.factoryService.newInlineEditor;
let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });
let wFactory = new NotebookWidgetFactory({
name: 'Notebook',
modelName: 'notebook',
fileTypes: ['notebook'],
defaultFor: ['notebook'],
preferKernel: true,
canStartKernel: true,
rendermime: this.props.rendermime,
} else {
event.dropAction = event.proposedAction;
}
for (let path of paths) {
let localPath = manager.services.contents.localPath(path);
let name = PathExt.basename(localPath);
let newPath = PathExt.join(basePath, name);
// Skip files that are not moving.
if (newPath === path) {
continue;
}
if (event.dropAction === 'copy') {
promises.push(manager.copy(path, basePath));
} else {
promises.push(renameFile(manager, path, newPath));
}
}
Promise.all(promises).catch(error => {
void showErrorMessage('Error while copying/moving files', error);
});
}
if (index === -1) {
return;
}
const model = this._model;
const path = PathExt.resolve(model.path, BREAD_CRUMB_PATHS[index]);
const manager = model.manager;
// Move all of the items.
let promises: Promise[] = [];
let oldPaths = event.mimeData.getData(CONTENTS_MIME) as string[];
for (let oldPath of oldPaths) {
let localOldPath = manager.services.contents.localPath(oldPath);
let name = PathExt.basename(localOldPath);
let newPath = PathExt.join(path, name);
promises.push(renameFile(manager, oldPath, newPath));
}
void Promise.all(promises).catch(err => {
return showErrorMessage('Move Error', err);
});
}
`and cannot include "/", "\\", or ":"`
)
);
this._inRename = false;
return original;
}
if (this.isDisposed) {
this._inRename = false;
throw new Error('File browser is disposed.');
}
const manager = this._manager;
const oldPath = PathExt.join(this._model.path, original);
const newPath = PathExt.join(this._model.path, newName);
const promise = renameFile(manager, oldPath, newPath);
return promise
.catch(error => {
if (error !== 'File not renamed') {
showErrorMessage('Rename Error', error);
}
this._inRename = false;
return original;
})
.then(() => {
if (this.isDisposed) {
this._inRename = false;
throw new Error('File browser is disposed.');
}
if (this._inRename) {
// No need to catch because `newName` will always exit.
this.selectItemByName(newName);