Search in sources :

Example 6 with ChangeList

use of com.intellij.openapi.vcs.changes.ChangeList in project intellij-community by JetBrains.

the class RevertCommittedStuffAbstractAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    final VirtualFile baseDir = project.getBaseDir();
    assert baseDir != null;
    final Change[] changes = myForPerformConvertor.convert(e);
    if (changes == null || changes.length == 0)
        return;
    final List<Change> changesList = new ArrayList<>();
    Collections.addAll(changesList, changes);
    FileDocumentManager.getInstance().saveAllDocuments();
    String defaultName = null;
    final ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS);
    if (changeLists != null && changeLists.length > 0) {
        defaultName = VcsBundle.message("revert.changes.default.name", changeLists[0].getName());
    }
    final ChangeListChooser chooser = new ChangeListChooser(project, ChangeListManager.getInstance(project).getChangeListsCopy(), null, "Select Target Changelist", defaultName);
    if (!chooser.showAndGet()) {
        return;
    }
    final List<FilePatch> patches = new ArrayList<>();
    ProgressManager.getInstance().run(new Task.Backgroundable(project, VcsBundle.message("revert.changes.title"), true) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            try {
                final List<Change> preprocessed = ChangesPreprocess.preprocessChangesRemoveDeletedForDuplicateMoved(changesList);
                patches.addAll(IdeaTextPatchBuilder.buildPatch(project, preprocessed, baseDir.getPresentableUrl(), true));
            } catch (final VcsException ex) {
                WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {

                    @Override
                    public void run() {
                        Messages.showErrorDialog(project, "Failed to revert changes: " + ex.getMessage(), VcsBundle.message("revert.changes.title"));
                    }
                }, null, myProject);
                indicator.cancel();
            }
        }

        @Override
        public void onSuccess() {
            new PatchApplier<BinaryFilePatch>(project, baseDir, patches, chooser.getSelectedList(), null, null).execute();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) ChangeListChooser(com.intellij.openapi.vcs.changes.ui.ChangeListChooser) ArrayList(java.util.ArrayList) Change(com.intellij.openapi.vcs.changes.Change) BinaryFilePatch(com.intellij.openapi.diff.impl.patch.BinaryFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) Project(com.intellij.openapi.project.Project) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) PatchApplier(com.intellij.openapi.diff.impl.patch.formove.PatchApplier) ArrayList(java.util.ArrayList) List(java.util.List) ChangeList(com.intellij.openapi.vcs.changes.ChangeList)

Example 7 with ChangeList

use of com.intellij.openapi.vcs.changes.ChangeList in project intellij-community by JetBrains.

the class GetCommittedChangelistAction method actionPerformed.

@Override
protected void actionPerformed(@NotNull final VcsContext context) {
    Collection<FilePath> filePaths = getFilePaths(context);
    final List<ChangeList> selectedChangeLists = new ArrayList<>();
    final ChangeList[] selectionFromContext = context.getSelectedChangeLists();
    if (selectionFromContext != null) {
        Collections.addAll(selectedChangeLists, selectionFromContext);
    }
    final List<CommittedChangeList> incomingChanges = CommittedChangesCache.getInstance(context.getProject()).getCachedIncomingChanges();
    final List<CommittedChangeList> intersectingChanges = new ArrayList<>();
    if (incomingChanges != null) {
        for (CommittedChangeList changeList : incomingChanges) {
            if (!selectedChangeLists.contains(changeList)) {
                for (Change change : changeList.getChanges()) {
                    if (filePaths.contains(ChangesUtil.getFilePath(change))) {
                        intersectingChanges.add(changeList);
                        break;
                    }
                }
            }
        }
    }
    if (intersectingChanges.size() > 0) {
        int rc = Messages.showOkCancelDialog(context.getProject(), VcsBundle.message("get.committed.changes.intersecting.prompt", intersectingChanges.size(), selectedChangeLists.size()), VcsBundle.message("get.committed.changes.title"), Messages.getQuestionIcon());
        if (rc != Messages.OK)
            return;
    }
    super.actionPerformed(context);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) Change(com.intellij.openapi.vcs.changes.Change)

Example 8 with ChangeList

use of com.intellij.openapi.vcs.changes.ChangeList in project intellij-community by JetBrains.

the class GetCommittedChangelistAction method getFilePaths.

private static Collection<FilePath> getFilePaths(final VcsContext context) {
    final Set<FilePath> files = new HashSet<>();
    final ChangeList[] selectedChangeLists = context.getSelectedChangeLists();
    if (selectedChangeLists != null) {
        for (ChangeList changelist : selectedChangeLists) {
            for (Change change : changelist.getChanges()) {
                files.add(ChangesUtil.getFilePath(change));
            }
        }
    }
    return files;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) Change(com.intellij.openapi.vcs.changes.Change)

Example 9 with ChangeList

use of com.intellij.openapi.vcs.changes.ChangeList in project intellij-community by JetBrains.

the class BaseAnalysisActionDialog method getScope.

@NotNull
public AnalysisScope getScope(@NotNull AnalysisUIOptions uiOptions, @NotNull AnalysisScope defaultScope, @NotNull Project project, Module module) {
    AnalysisScope scope;
    if (isProjectScopeSelected()) {
        scope = new AnalysisScope(project);
        uiOptions.SCOPE_TYPE = AnalysisScope.PROJECT;
    } else {
        final SearchScope customScope = getCustomScope();
        if (customScope != null) {
            scope = new AnalysisScope(customScope, project);
            uiOptions.SCOPE_TYPE = AnalysisScope.CUSTOM;
            uiOptions.CUSTOM_SCOPE_NAME = customScope.getDisplayName();
        } else if (isModuleScopeSelected()) {
            scope = new AnalysisScope(module);
            uiOptions.SCOPE_TYPE = AnalysisScope.MODULE;
        } else if (isUncommitedFilesSelected()) {
            final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
            List<VirtualFile> files;
            if (myChangeLists.getSelectedItem() == ALL) {
                files = changeListManager.getAffectedFiles();
            } else {
                files = new ArrayList<>();
                for (ChangeList list : changeListManager.getChangeListsCopy()) {
                    if (!Comparing.strEqual(list.getName(), (String) myChangeLists.getSelectedItem()))
                        continue;
                    final Collection<Change> changes = list.getChanges();
                    for (Change change : changes) {
                        final ContentRevision afterRevision = change.getAfterRevision();
                        if (afterRevision != null) {
                            final VirtualFile vFile = afterRevision.getFile().getVirtualFile();
                            if (vFile != null) {
                                files.add(vFile);
                            }
                        }
                    }
                }
            }
            scope = new AnalysisScope(project, new HashSet<>(files));
            uiOptions.SCOPE_TYPE = AnalysisScope.UNCOMMITTED_FILES;
        } else {
            scope = defaultScope;
            //just not project scope
            uiOptions.SCOPE_TYPE = defaultScope.getScopeType();
        }
    }
    uiOptions.ANALYZE_TEST_SOURCES = isInspectTestSources();
    scope.setIncludeTestSource(isInspectTestSources());
    FindSettings.getInstance().setDefaultScopeName(scope.getDisplayName());
    return scope;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) SearchScope(com.intellij.psi.search.SearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with ChangeList

use of com.intellij.openapi.vcs.changes.ChangeList in project intellij-community by JetBrains.

the class ChangelistConflictAccessProvider method requestWriting.

@NotNull
@Override
public Collection<VirtualFile> requestWriting(VirtualFile... files) {
    ChangelistConflictTracker.Options options = myManager.getConflictTracker().getOptions();
    if (!options.TRACKING_ENABLED || !options.SHOW_DIALOG) {
        return Collections.emptyList();
    }
    ArrayList<VirtualFile> denied = new ArrayList<>();
    for (VirtualFile file : files) {
        if (file != null && !myManager.getConflictTracker().isWritingAllowed(file)) {
            denied.add(file);
        }
    }
    if (!denied.isEmpty()) {
        HashSet<ChangeList> changeLists = new HashSet<>();
        ArrayList<Change> changes = new ArrayList<>();
        for (VirtualFile file : denied) {
            changeLists.add(myManager.getChangeList(file));
            changes.add(myManager.getChange(file));
        }
        ChangelistConflictDialog dialog;
        final int savedEventCount = IdeEventQueue.getInstance().getEventCount();
        do {
            dialog = new ChangelistConflictDialog(myProject, new ArrayList<>(changeLists), denied);
            dialog.show();
        } while (dialog.isOK() && !dialog.getResolution().resolveConflict(myProject, changes, null));
        IdeEventQueue.getInstance().setEventCount(savedEventCount);
        if (dialog.isOK()) {
            options.LAST_RESOLUTION = dialog.getResolution();
            return Collections.emptyList();
        }
    }
    return denied;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) ArrayList(java.util.ArrayList) Change(com.intellij.openapi.vcs.changes.Change) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ChangeList (com.intellij.openapi.vcs.changes.ChangeList)19 Project (com.intellij.openapi.project.Project)11 CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)7 Change (com.intellij.openapi.vcs.changes.Change)6 LocalChangeList (com.intellij.openapi.vcs.changes.LocalChangeList)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 SvnChangeList (org.jetbrains.idea.svn.history.SvnChangeList)3 DataContext (com.intellij.openapi.actionSystem.DataContext)2 FilePath (com.intellij.openapi.vcs.FilePath)2 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)2 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)2 TaskManager (com.intellij.tasks.TaskManager)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 CamelHumpMatcher (com.intellij.codeInsight.completion.impl.CamelHumpMatcher)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1