diff: add annotate action to diff viewers
[idea/community.git] / platform / diff-impl / src / com / intellij / diff / DiffManagerImpl.java
1 /*
2  * Copyright 2000-2015 JetBrains s.r.o.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.intellij.diff;
17
18 import com.intellij.diff.chains.DiffRequestChain;
19 import com.intellij.diff.chains.SimpleDiffRequestChain;
20 import com.intellij.diff.impl.DiffRequestPanelImpl;
21 import com.intellij.diff.impl.DiffWindow;
22 import com.intellij.diff.merge.*;
23 import com.intellij.diff.requests.DiffRequest;
24 import com.intellij.diff.tools.binary.BinaryDiffTool;
25 import com.intellij.diff.tools.dir.DirDiffTool;
26 import com.intellij.diff.tools.external.ExternalDiffTool;
27 import com.intellij.diff.tools.external.ExternalMergeTool;
28 import com.intellij.diff.tools.fragmented.UnifiedDiffTool;
29 import com.intellij.diff.tools.simple.SimpleDiffTool;
30 import com.intellij.openapi.Disposable;
31 import com.intellij.openapi.project.Project;
32 import com.intellij.openapi.util.Disposer;
33 import org.jetbrains.annotations.CalledInAwt;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
36
37 import java.awt.*;
38 import java.util.ArrayList;
39 import java.util.Collections;
40 import java.util.List;
41
42 public class DiffManagerImpl extends DiffManagerEx {
43   @Override
44   public void showDiff(@Nullable Project project, @NotNull DiffRequest request) {
45     showDiff(project, request, DiffDialogHints.DEFAULT);
46   }
47
48   @Override
49   public void showDiff(@Nullable Project project, @NotNull DiffRequest request, @NotNull DiffDialogHints hints) {
50     DiffRequestChain requestChain = new SimpleDiffRequestChain(request);
51     showDiff(project, requestChain, hints);
52   }
53
54   @Override
55   public void showDiff(@Nullable Project project, @NotNull DiffRequestChain requests, @NotNull DiffDialogHints hints) {
56     if (ExternalDiffTool.isDefault()) {
57       ExternalDiffTool.show(project, requests, hints);
58       return;
59     }
60
61     showDiffBuiltin(project, requests, hints);
62   }
63
64   @Override
65   public void showDiffBuiltin(@Nullable Project project, @NotNull DiffRequest request) {
66     showDiffBuiltin(project, request, DiffDialogHints.DEFAULT);
67   }
68
69   @Override
70   public void showDiffBuiltin(@Nullable Project project, @NotNull DiffRequest request, @NotNull DiffDialogHints hints) {
71     DiffRequestChain requestChain = new SimpleDiffRequestChain(request);
72     showDiffBuiltin(project, requestChain, hints);
73   }
74
75   @Override
76   public void showDiffBuiltin(@Nullable Project project, @NotNull DiffRequestChain requests, @NotNull DiffDialogHints hints) {
77     new DiffWindow(project, requests, hints).show();
78   }
79
80   @NotNull
81   @Override
82   public DiffRequestPanel createRequestPanel(@Nullable Project project, @NotNull Disposable parent, @Nullable Window window) {
83     DiffRequestPanelImpl panel = new DiffRequestPanelImpl(project, window);
84     Disposer.register(parent, panel);
85     return panel;
86   }
87
88   @NotNull
89   @Override
90   public List<DiffTool> getDiffTools() {
91     List<DiffTool> result = new ArrayList<DiffTool>();
92     Collections.addAll(result, DiffTool.EP_NAME.getExtensions());
93     result.add(SimpleDiffTool.INSTANCE);
94     result.add(UnifiedDiffTool.INSTANCE);
95     result.add(BinaryDiffTool.INSTANCE);
96     result.add(DirDiffTool.INSTANCE);
97     return result;
98   }
99
100   @NotNull
101   @Override
102   public List<MergeTool> getMergeTools() {
103     List<MergeTool> result = new ArrayList<MergeTool>();
104     Collections.addAll(result, MergeTool.EP_NAME.getExtensions());
105     result.add(TextMergeTool.INSTANCE);
106     result.add(BinaryMergeTool.INSTANCE);
107     return result;
108   }
109
110   @CalledInAwt
111   public void showMerge(@Nullable Project project, @NotNull MergeRequest request) {
112     if (ExternalMergeTool.isDefault()) {
113       ExternalMergeTool.show(project, request);
114       return;
115     }
116
117     showMergeBuiltin(project, request);
118   }
119
120   @CalledInAwt
121   public void showMergeBuiltin(@Nullable Project project, @NotNull MergeRequest request) {
122     new MergeWindow(project, request).show();
123   }
124 }