2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package git4idea.actions;
18 import com.intellij.openapi.actionSystem.AnActionEvent;
19 import com.intellij.openapi.project.Project;
20 import com.intellij.openapi.vcs.AbstractVcsHelper;
21 import com.intellij.openapi.vcs.FileStatus;
22 import com.intellij.openapi.vcs.changes.Change;
23 import com.intellij.openapi.vcs.changes.ChangeListManager;
24 import com.intellij.openapi.vcs.changes.ContentRevision;
25 import com.intellij.openapi.vfs.VirtualFile;
26 import git4idea.GitVcs;
27 import org.jetbrains.annotations.NotNull;
32 * Git merge tool for resolving conflicts. Use IDEA built-in 3-way merge tool.
34 public class GitResolveConflictsAction extends GitAction {
37 public void actionPerformed(@NotNull AnActionEvent event) {
38 final Project project = event.getProject();
40 final Set<VirtualFile> conflictedFiles = new TreeSet<VirtualFile>(new Comparator<VirtualFile>() {
42 public int compare(@NotNull VirtualFile f1, @NotNull VirtualFile f2) {
43 return f1.getPresentableUrl().compareTo(f2.getPresentableUrl());
46 for (Change change : ChangeListManager.getInstance(project).getAllChanges()) {
47 final ContentRevision before = change.getBeforeRevision();
48 final ContentRevision after = change.getAfterRevision();
50 final VirtualFile file = before.getFile().getVirtualFile();
52 conflictedFiles.add(file);
56 final VirtualFile file = after.getFile().getVirtualFile();
58 conflictedFiles.add(file);
63 AbstractVcsHelper.getInstance(project).showMergeDialog(new ArrayList<VirtualFile>(conflictedFiles), GitVcs.getInstance(project).getMergeProvider());
67 protected boolean isEnabled(@NotNull AnActionEvent event) {
68 final Collection<Change> changes = ChangeListManager.getInstance(event.getProject()).getAllChanges();
69 if (changes.size() > 1000) {
72 for (Change change : changes) {
73 if (change.getFileStatus() == FileStatus.MERGED_WITH_CONFLICTS) {