Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let index = ArrayExt.findFirstIndex(this._crumbs, node => node === target);
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);
});
}
let target = event.target as HTMLElement;
while (target && target.parentElement) {
if (target.classList.contains(DROP_TARGET_CLASS)) {
target.classList.remove(DROP_TARGET_CLASS);
break;
}
target = target.parentElement;
}
// Get the path based on the target node.
const index = ArrayExt.firstIndexOf(this._items, target);
const items = this._sortedItems;
let basePath = this._model.path;
if (items[index].type === 'directory') {
basePath = PathExt.join(basePath, items[index].name);
}
const manager = this._manager;
// Handle the items.
const promises: Promise[] = [];
const paths = event.mimeData.getData(CONTENTS_MIME) as string[];
for (let path of paths) {
let name = PathExt.basename(path);
let newPath = PathExt.join(basePath, name);
// Skip files that are not moving.
if (newPath === path) {
continue;
}
promises.push(renameFile(manager, path, newPath));
}
Promise.all(promises).catch(error => {
}
const manager = this._manager;
// Handle the items.
const promises: Promise[] = [];
const paths = event.mimeData.getData(CONTENTS_MIME) as string[];
if (event.ctrlKey && event.proposedAction === 'move') {
event.dropAction = 'copy';
} 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 => {
showErrorMessage('Error while copying/moving files', error);
});
}
}
const manager = this._manager;
// Handle the items.
const promises: Promise[] = [];
const paths = event.mimeData.getData(CONTENTS_MIME) as string[];
if (event.ctrlKey && event.proposedAction === 'move') {
event.dropAction = 'copy';
} 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 we can't find the document context, bail.
let texContext = manager.contextForWidget(widget);
if (!texContext) {
return;
}
// If there is already an active preview for this context,
// trigger a save then bail.
if (Private.previews.has(texContext.path)) {
texContext.save();
return;
}
// build pdfFilePath so that we know what to watch for
const dirName = PathExt.dirname(texContext.path);
const baseName = PathExt.basename(texContext.path, '.tex');
const pdfFilePath = PathExt.join(dirName, baseName + '.pdf');
let pdfContext: DocumentRegistry.IContext;
let errorPanel: ErrorPanel | null = null;
let pending = false;
const findOpenOrRevealPDF = () => {
let pdfWidget = manager.findWidget(pdfFilePath);
if (!pdfWidget) {
pdfWidget = manager.openOrReveal(pdfFilePath, 'PDFJS', undefined, {
mode: 'split-right'
});
}
if (!pdfWidget) {
return;
}
(pdfWidget as PDFJSDocumentWidget).content.positionRequested.connect(
each(this._clipboard, path => {
if (this._isCut) {
const parts = path.split('/');
const name = parts[parts.length - 1];
const newPath = PathExt.join(basePath, name);
promises.push(this._model.manager.rename(path, newPath));
} else {
promises.push(this._model.manager.copy(path, basePath));
}
});
}).then(result => {
if (result.accept) {
let basePath = PathExt.dirname(this._oldPath);
let newPath = PathExt.join(basePath, this.inputNode.value);
return renameFile(this._manager, this._oldPath, newPath);
}
});
}
each(this.selectedItems(), item => {
if (item.type !== 'directory') {
let oldPath = PathExt.join(basePath, item.name);
promises.push(this._model.manager.copy(oldPath, basePath));
}
});
return Promise.all(promises).catch(error => {
private _delete(names: string[]): Promise {
const promises: Promise[] = [];
const basePath = this._model.path;
for (let name of names) {
let newPath = PathExt.join(basePath, name);
let promise = this._model.manager.deleteFile(newPath).catch(err => {
showErrorMessage('Delete Failed', err);
});
promises.push(promise);
}
return Promise.all(promises).then(() => undefined);
}
map(selectedNames, name => {
return PathExt.join(basePath, name);
})
);