Search in sources :

Example 21 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class HgVFSListener method executeDelete.

protected void executeDelete() {
    final List<FilePath> filesToDelete = new ArrayList<>(myDeletedWithoutConfirmFiles);
    final List<FilePath> filesToConfirmDeletion = new ArrayList<>(myDeletedFiles);
    myDeletedWithoutConfirmFiles.clear();
    myDeletedFiles.clear();
    // skip files which are not under Mercurial
    skipNotUnderHg(filesToDelete);
    skipNotUnderHg(filesToConfirmDeletion);
    filesToDelete.removeAll(processAndGetVcsIgnored(filesToDelete));
    filesToConfirmDeletion.removeAll(processAndGetVcsIgnored(filesToConfirmDeletion));
    // but without user confirmation.
    for (Iterator<FilePath> it = filesToConfirmDeletion.iterator(); it.hasNext(); ) {
        FilePath filePath = it.next();
        Change fileChange = ChangeListManager.getInstance(myProject).getChange(filePath);
        if (fileChange != null && fileChange.getFileStatus().equals(FileStatus.ADDED)) {
            filesToDelete.add(filePath);
            it.remove();
        }
    }
    new Task.ConditionalModal(myProject, HgVcsMessages.message("hg4idea.remove.progress"), false, VcsConfiguration.getInstance(myProject).getAddRemoveOption()) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            // confirm removal from the VCS if needed
            if (myRemoveOption.getValue() != VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY) {
                if (myRemoveOption.getValue() == VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY || filesToConfirmDeletion.isEmpty()) {
                    filesToDelete.addAll(filesToConfirmDeletion);
                } else {
                    final AtomicReference<Collection<FilePath>> filePaths = new AtomicReference<>();
                    ApplicationManager.getApplication().invokeAndWait(() -> filePaths.set(selectFilePathsToDelete(filesToConfirmDeletion)));
                    if (filePaths.get() != null) {
                        filesToDelete.addAll(filePaths.get());
                    }
                }
            }
            if (!filesToDelete.isEmpty()) {
                performDeletion(filesToDelete);
            }
        }
    }.queue();
}
Also used : VcsBackgroundTask(com.intellij.util.ui.VcsBackgroundTask) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicReference(java.util.concurrent.atomic.AtomicReference) Change(com.intellij.openapi.vcs.changes.Change)

Example 22 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class HgVFSListener method performAdding.

@Override
protected void performAdding(final Collection<VirtualFile> addedFiles, final Map<VirtualFile, VirtualFile> copyFromMap) {
    (new Task.ConditionalModal(myProject, HgVcsMessages.message("hg4idea.add.progress"), false, VcsConfiguration.getInstance(myProject).getAddRemoveOption()) {

        @Override
        public void run(@NotNull ProgressIndicator aProgressIndicator) {
            final ArrayList<VirtualFile> adds = new ArrayList<>();
            // from -> to
            final HashMap<VirtualFile, VirtualFile> copies = new HashMap<>();
            //delete unversioned and ignored files from copy source
            LOG.assertTrue(myProject != null, "Project is null");
            Collection<VirtualFile> unversionedAndIgnoredFiles = new ArrayList<>();
            final Map<VirtualFile, Collection<VirtualFile>> sortedSourceFilesByRepos = HgUtil.sortByHgRoots(myProject, copyFromMap.values());
            HgStatusCommand statusCommand = new HgStatusCommand.Builder(false).unknown(true).ignored(true).build(myProject);
            for (Map.Entry<VirtualFile, Collection<VirtualFile>> entry : sortedSourceFilesByRepos.entrySet()) {
                Set<HgChange> changes = statusCommand.executeInCurrentThread(entry.getKey(), ContainerUtil.map(entry.getValue(), new Function<VirtualFile, FilePath>() {

                    @Override
                    public FilePath fun(VirtualFile virtualFile) {
                        return VcsUtil.getFilePath(virtualFile);
                    }
                }));
                for (HgChange change : changes) {
                    unversionedAndIgnoredFiles.add(change.afterFile().toFilePath().getVirtualFile());
                }
            }
            copyFromMap.values().removeAll(unversionedAndIgnoredFiles);
            // separate adds from copies
            for (VirtualFile file : addedFiles) {
                if (file.isDirectory()) {
                    continue;
                }
                final VirtualFile copyFrom = copyFromMap.get(file);
                if (copyFrom != null) {
                    copies.put(copyFrom, file);
                } else {
                    adds.add(file);
                }
            }
            // add for all files at once
            if (!adds.isEmpty()) {
                new HgAddCommand(myProject).executeInCurrentThread(adds);
            }
            // copy needs to be run for each file separately
            if (!copies.isEmpty()) {
                for (Map.Entry<VirtualFile, VirtualFile> copy : copies.entrySet()) {
                    new HgCopyCommand(myProject).executeInCurrentThread(copy.getKey(), copy.getValue());
                }
            }
            for (VirtualFile file : addedFiles) {
                dirtyScopeManager.fileDirty(file);
            }
        }
    }).queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull) Function(com.intellij.util.Function) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 23 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class HgVFSListener method executeAdd.

@Override
protected void executeAdd(final List<VirtualFile> addedFiles, final Map<VirtualFile, VirtualFile> copyFromMap) {
    // Thus here we remove such files from the copyFromMap.
    for (Iterator<Map.Entry<VirtualFile, VirtualFile>> it = copyFromMap.entrySet().iterator(); it.hasNext(); ) {
        final Map.Entry<VirtualFile, VirtualFile> entry = it.next();
        final VirtualFile rootFrom = HgUtil.getHgRootOrNull(myProject, entry.getKey());
        final VirtualFile rootTo = HgUtil.getHgRootOrNull(myProject, entry.getValue());
        if (rootTo == null || !rootTo.equals(rootFrom)) {
            it.remove();
        }
    }
    // exclude files which are added to a directory which is not version controlled
    for (Iterator<VirtualFile> it = addedFiles.iterator(); it.hasNext(); ) {
        if (HgUtil.getHgRootOrNull(myProject, it.next()) == null) {
            it.remove();
        }
    }
    // exclude files which are ignored in .hgignore in background and execute adding after that
    final Map<VirtualFile, Collection<VirtualFile>> sortedFiles = HgUtil.sortByHgRoots(myProject, addedFiles);
    final HashSet<VirtualFile> untrackedFiles = new HashSet<>();
    new Task.Backgroundable(myProject, HgVcsMessages.message("hg4idea.progress.checking.ignored"), false) {

        @Override
        public void run(@NotNull ProgressIndicator pi) {
            for (Map.Entry<VirtualFile, Collection<VirtualFile>> e : sortedFiles.entrySet()) {
                VirtualFile repo = e.getKey();
                final Collection<VirtualFile> files = e.getValue();
                pi.setText(repo.getPresentableUrl());
                try {
                    Collection<VirtualFile> untrackedForRepo = new HgStatusCommand.Builder(false).unknown(true).removed(true).build(myProject).getFiles(repo, new ArrayList<>(files));
                    untrackedFiles.addAll(untrackedForRepo);
                    List<VirtualFile> ignoredForRepo = files.stream().filter(file -> !untrackedForRepo.contains(file)).collect(Collectors.toList());
                    getIgnoreRepoHolder(repo).addFiles(ignoredForRepo);
                } catch (final VcsException ex) {
                    UIUtil.invokeLaterIfNeeded(new Runnable() {

                        public void run() {
                            ((HgVcs) myVcs).showMessageInConsole(ex.getMessage(), ConsoleViewContentType.ERROR_OUTPUT);
                        }
                    });
                }
            }
            addedFiles.retainAll(untrackedFiles);
            // select files to add if there is something to select
            if (!addedFiles.isEmpty() || !copyFromMap.isEmpty()) {
                AppUIUtil.invokeLaterIfProjectAlive(myProject, new Runnable() {

                    @Override
                    public void run() {
                        originalExecuteAdd(addedFiles, copyFromMap);
                    }
                });
            }
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsBackgroundTask(com.intellij.util.ui.VcsBackgroundTask) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 24 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class HgCreateNewBranchFromLogAction method actionPerformed.

@Override
protected void actionPerformed(@NotNull final HgRepository repository, @NotNull final Hash commit) {
    final Project project = repository.getProject();
    FileDocumentManager.getInstance().saveAllDocuments();
    String shortHash = commit.toShortString();
    final String name = getNewBranchNameFromUser(repository, "Create New Branch From " + shortHash);
    if (name != null) {
        new Task.Backgroundable(project, HgVcsMessages.message("hg4idea.progress.updatingTo", shortHash)) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                if (HgUpdateCommand.updateRepoToInCurrentThread(project, repository.getRoot(), commit.asString(), false)) {
                    new HgBranchPopupActions.HgNewBranchAction(project, Collections.singletonList(repository), repository).createNewBranchInCurrentThread(name);
                }
            }
        }.queue();
    }
}
Also used : Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 25 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class HgQGotoFromLogAction method actionPerformed.

protected void actionPerformed(@NotNull final HgRepository repository, @NotNull final VcsFullCommitDetails commit) {
    final Project project = repository.getProject();
    List<Hash> parents = commit.getParents();
    final Hash parentHash = parents.isEmpty() ? null : parents.get(0);
    final HgNameWithHashInfo parentPatchName = ContainerUtil.find(repository.getMQAppliedPatches(), new Condition<HgNameWithHashInfo>() {

        @Override
        public boolean value(HgNameWithHashInfo info) {
            return info.getHash().equals(parentHash);
        }
    });
    new Task.Backgroundable(repository.getProject(), parentPatchName != null ? HgVcsMessages.message("hg4idea.mq.progress.goto", parentPatchName) : HgVcsMessages.message("hg4idea.mq.progress.pop")) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            if (parentPatchName != null) {
                new HgQGotoCommand(repository).executeInCurrentThread(parentPatchName.getName());
            } else {
                new HgQPopCommand(repository).executeInCurrentThread();
            }
        }

        @Override
        public void onSuccess() {
            HgShowUnAppliedPatchesAction.showUnAppliedPatches(project, repository);
        }
    }.queue();
}
Also used : HgQGotoCommand(org.zmlx.hg4idea.command.mq.HgQGotoCommand) Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Hash(com.intellij.vcs.log.Hash) HgNameWithHashInfo(org.zmlx.hg4idea.HgNameWithHashInfo) HgQPopCommand(org.zmlx.hg4idea.command.mq.HgQPopCommand)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)400 Task (com.intellij.openapi.progress.Task)151 VirtualFile (com.intellij.openapi.vfs.VirtualFile)106 NotNull (org.jetbrains.annotations.NotNull)101 Project (com.intellij.openapi.project.Project)88 File (java.io.File)59 IOException (java.io.IOException)58 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)47 Nullable (org.jetbrains.annotations.Nullable)46 ProgressManager (com.intellij.openapi.progress.ProgressManager)39 List (java.util.List)36 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)31 Ref (com.intellij.openapi.util.Ref)27 Module (com.intellij.openapi.module.Module)26 VcsException (com.intellij.openapi.vcs.VcsException)26 ArrayList (java.util.ArrayList)26 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 Logger (com.intellij.openapi.diagnostic.Logger)23 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)22 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)22