protected void performMoveRename()

in src/org/jetbrains/tfsIntegration/core/TFSFileListener.java [346:451]


  protected void performMoveRename(@NotNull final List<MovedFileInfo> movedFiles) {
    final Map<FilePath, FilePath> movedPaths = new HashMap<>(movedFiles.size());
    for (MovedFileInfo movedFileInfo : movedFiles) {
      movedPaths.put(VcsUtil.getFilePath(movedFileInfo.myOldPath), VcsUtil.getFilePath(movedFileInfo.myNewPath));
    }
    final List<VcsException> errors = new ArrayList<>();
    final Map<FilePath, FilePath> scheduleMove = new HashMap<>();
    try {
      WorkstationHelper.processByWorkspaces(movedPaths.keySet(), false, myProject, new WorkstationHelper.VoidProcessDelegate() {

        @Override
        public void executeRequest(final WorkspaceInfo workspace, final List<ItemPath> paths) throws TfsException {
          // TODO simplify this
          StatusProvider.visitByStatus(workspace, paths, false, null, new StatusVisitor() {

            @Override
            public void unversioned(final @NotNull FilePath localPath,
                                    final boolean localItemExists,
                                    final @NotNull ServerStatus serverStatus) throws TfsException {
              // ignore
            }

            @Override
            public void checkedOutForEdit(final @NotNull FilePath localPath,
                                          final boolean localItemExists,
                                          final @NotNull ServerStatus serverStatus) {
              scheduleMove.put(localPath, movedPaths.get(localPath));
            }

            @Override
            public void scheduledForAddition(final @NotNull FilePath localPath,
                                             final boolean localItemExists,
                                             final @NotNull ServerStatus serverStatus) {
              scheduleMove.put(localPath, movedPaths.get(localPath));
            }

            @Override
            public void scheduledForDeletion(final @NotNull FilePath localPath,
                                             final boolean localItemExists,
                                             final @NotNull ServerStatus serverStatus) {
              TFSVcs.error("Cannot rename a file that does not exist on local machine: " + localPath.getPresentableUrl());
            }

            @Override
            public void outOfDate(final @NotNull FilePath localPath,
                                  final boolean localItemExists,
                                  final @NotNull ServerStatus serverStatus) throws TfsException {
              scheduleMove.put(localPath, movedPaths.get(localPath));
            }

            @Override
            public void deleted(final @NotNull FilePath localPath,
                                final boolean localItemExists,
                                final @NotNull ServerStatus serverStatus) {
              // ignore
            }

            @Override
            public void upToDate(final @NotNull FilePath localPath, final boolean localItemExists, final @NotNull ServerStatus serverStatus)
              throws TfsException {
              scheduleMove.put(localPath, movedPaths.get(localPath));
            }

            @Override
            public void renamed(final @NotNull FilePath localPath, final boolean localItemExists, final @NotNull ServerStatus serverStatus)
              throws TfsException {
              scheduleMove.put(localPath, movedPaths.get(localPath));
            }

            @Override
            public void renamedCheckedOut(final @NotNull FilePath localPath,
                                          final boolean localItemExists,
                                          final @NotNull ServerStatus serverStatus) throws TfsException {
              scheduleMove.put(localPath, movedPaths.get(localPath));
            }

            @Override
            public void undeleted(final @NotNull FilePath localPath,
                                  final boolean localItemExists,
                                  final @NotNull ServerStatus serverStatus) throws TfsException {
              scheduleMove.put(localPath, movedPaths.get(localPath));
            }
          }, myProject);

          final ResultWithFailures<GetOperation> renameResult =
            workspace.getServer().getVCS()
              .renameAndUpdateLocalVersion(workspace.getName(), workspace.getOwnerName(), scheduleMove, myProject,
                                           TFSBundle.message("renaming"));
          errors.addAll(TfsUtil.getVcsExceptions(renameResult.getFailures()));

          Collection<FilePath> invalidate = new ArrayList<>(renameResult.getResult().size());
          for (GetOperation getOperation : renameResult.getResult()) {
            invalidate.add(VersionControlPath.getFilePath(getOperation.getTlocal(), getOperation.getType() == ItemType.Folder));
            //invalidate.add(VcsUtil.getFilePath(getOperation.getSlocal()));
          }
          TfsFileUtil.markDirtyRecursively(myProject, invalidate);
        }
      });
    }
    catch (TfsException e) {
      errors.add(new VcsException(e));
    }
    if (!errors.isEmpty()) {
      AbstractVcsHelper.getInstance(myProject).showErrors(errors, TFSVcs.TFS_NAME);
    }
  }