How to use the @jupyterlab/docmanager.renameFile function in @jupyterlab/docmanager

To help you get started, we’ve selected a few @jupyterlab/docmanager examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / packages / filebrowser / src / listing.ts View on Github external
} 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);
    });
  }
github jupyterlab / jupyterlab / packages / filebrowser / src / crumbs.ts View on Github external
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);
    });
  }
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / filebrowser / src / listing.ts View on Github external
`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);
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / filebrowser / src / listing.ts View on Github external
} 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);
    });
  }
github yuvipanda / simplest-notebook / packages / filebrowser / src / listing.ts View on Github external
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 => {
      utils.showErrorMessage('Move Error', error);
    });
  }
github jupyterlab / jupyterlab / packages / filebrowser / src / listing.ts View on Github external
`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') {
            void 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.
            void this.selectItemByName(newName);
github yuvipanda / simplest-notebook / packages / filebrowser / src / listing.ts View on Github external
return Private.doRename(nameNode, this._editNode).then(newName => {
      if (newName === original) {
        this._inRename = false;
        return original;
      }
      if (this.isDisposed) {
        this._inRename = false;
        return;
      }

      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 => {
        utils.showErrorMessage('Rename Error', error);
        this._inRename = false;
        return original;
      }).then(() => {
        if (this.isDisposed) {
          this._inRename = false;
          return;
        }
        this.selectItemByName(newName);
        this._inRename = false;
        return newName;
      });
    });
  }