|
15 | 15 | */ |
16 | 16 | package org.exbin.bined.intellij.diff.gui; |
17 | 17 |
|
| 18 | +import com.intellij.diff.contents.DiffContent; |
| 19 | +import com.intellij.diff.contents.DocumentContent; |
| 20 | +import com.intellij.diff.contents.FileContent; |
18 | 21 | import com.intellij.diff.requests.ContentDiffRequest; |
19 | 22 | import com.intellij.ide.util.PropertiesComponent; |
20 | 23 | import com.intellij.openapi.actionSystem.AnAction; |
21 | 24 | import com.intellij.openapi.actionSystem.AnActionEvent; |
| 25 | +import com.intellij.openapi.editor.Document; |
22 | 26 | import com.intellij.openapi.util.IconLoader; |
23 | 27 | import com.intellij.openapi.vfs.VirtualFile; |
24 | 28 | import com.intellij.ui.components.JBPanel; |
| 29 | +import org.exbin.auxiliary.paged_data.BinaryData; |
| 30 | +import org.exbin.auxiliary.paged_data.ByteArrayData; |
25 | 31 | import org.exbin.bined.CodeAreaCaretPosition; |
26 | 32 | import org.exbin.bined.CodeType; |
27 | | -import org.exbin.bined.EditMode; |
28 | 33 | import org.exbin.bined.EditOperation; |
29 | 34 | import org.exbin.bined.capability.CharsetCapable; |
30 | 35 | import org.exbin.bined.extended.layout.ExtendedCodeAreaLayoutProfile; |
|
66 | 71 | import org.exbin.framework.utils.handler.OptionsControlHandler; |
67 | 72 |
|
68 | 73 | import javax.annotation.Nonnull; |
| 74 | +import javax.annotation.Nullable; |
69 | 75 | import javax.annotation.ParametersAreNonnullByDefault; |
70 | 76 | import javax.swing.AbstractAction; |
71 | 77 | import javax.swing.Icon; |
72 | 78 | import javax.swing.JPanel; |
73 | 79 | import javax.swing.JPopupMenu; |
74 | | -import javax.swing.JViewport; |
75 | 80 | import java.awt.BorderLayout; |
76 | 81 | import java.awt.Component; |
77 | 82 | import java.awt.Dialog; |
|
82 | 87 | import java.awt.event.FocusEvent; |
83 | 88 | import java.awt.event.MouseEvent; |
84 | 89 | import java.nio.charset.Charset; |
| 90 | +import java.nio.charset.StandardCharsets; |
85 | 91 | import java.util.List; |
86 | 92 |
|
87 | 93 | /** |
@@ -199,29 +205,56 @@ public void setEncoding(String encodingName) { |
199 | 205 | } |
200 | 206 |
|
201 | 207 | public void setDiffContent(ContentDiffRequest request) { |
202 | | - List<VirtualFile> filesToRefresh = request.getFilesToRefresh(); |
203 | | - VirtualFile virtualFile = filesToRefresh.get(0); |
204 | | - diffPanel.setLeftContentData(new BinEdFileDataWrapper(virtualFile)); |
205 | | - ExtCodeArea leftCodeArea = diffPanel.getLeftCodeArea(); |
206 | | - leftCodeArea.setComponentPopupMenu(new JPopupMenu() { |
207 | | - @Override |
208 | | - public void show(Component invoker, int x, int y) { |
209 | | - JPopupMenu popupMenu = SearchAction.createCodeAreaPopupMenu(leftCodeArea, "left"); |
210 | | - popupMenu.show(invoker, x, y); |
| 208 | + List<DiffContent> contents = request.getContents(); |
| 209 | + if (!contents.isEmpty()) { |
| 210 | + BinaryData leftData = getDiffBinaryData(request, 0); |
| 211 | + if (leftData == null) { |
| 212 | + return; |
211 | 213 | } |
212 | | - }); |
213 | | - if (filesToRefresh.size() > 1) { |
214 | | - VirtualFile secondFile = filesToRefresh.get(1); |
215 | | - diffPanel.setRightContentData(new BinEdFileDataWrapper(secondFile)); |
| 214 | + diffPanel.setLeftContentData(leftData); |
| 215 | + ExtCodeArea leftCodeArea = diffPanel.getLeftCodeArea(); |
| 216 | + leftCodeArea.setComponentPopupMenu(new JPopupMenu() { |
| 217 | + @Override |
| 218 | + public void show(Component invoker, int x, int y) { |
| 219 | + JPopupMenu popupMenu = SearchAction.createCodeAreaPopupMenu(leftCodeArea, "left"); |
| 220 | + popupMenu.show(invoker, x, y); |
| 221 | + } |
| 222 | + }); |
| 223 | + BinaryData rightData = getDiffBinaryData(request, 1); |
| 224 | + if (rightData != null) { |
| 225 | + diffPanel.setRightContentData(rightData); |
| 226 | + } |
| 227 | + ExtCodeArea rightCodeArea = diffPanel.getRightCodeArea(); |
| 228 | + rightCodeArea.setComponentPopupMenu(new JPopupMenu() { |
| 229 | + @Override |
| 230 | + public void show(Component invoker, int x, int y) { |
| 231 | + JPopupMenu popupMenu = SearchAction.createCodeAreaPopupMenu(rightCodeArea, "right"); |
| 232 | + popupMenu.show(invoker, x, y); |
| 233 | + } |
| 234 | + }); |
216 | 235 | } |
217 | | - ExtCodeArea rightCodeArea = diffPanel.getRightCodeArea(); |
218 | | - rightCodeArea.setComponentPopupMenu(new JPopupMenu() { |
219 | | - @Override |
220 | | - public void show(Component invoker, int x, int y) { |
221 | | - JPopupMenu popupMenu = SearchAction.createCodeAreaPopupMenu(rightCodeArea, "right"); |
222 | | - popupMenu.show(invoker, x, y); |
| 236 | + } |
| 237 | + |
| 238 | + @Nullable |
| 239 | + private static BinaryData getDiffBinaryData(ContentDiffRequest request, int index) { |
| 240 | + List<VirtualFile> filesToRefresh = request.getFilesToRefresh(); |
| 241 | + if (filesToRefresh.size() > index) { |
| 242 | + return new BinEdFileDataWrapper(filesToRefresh.get(index)); |
| 243 | + } |
| 244 | + |
| 245 | + List<DiffContent> contents = request.getContents(); |
| 246 | + if (contents.size() > index) { |
| 247 | + DiffContent diffContent = contents.get(index); |
| 248 | + if (diffContent instanceof FileContent) { |
| 249 | + return new BinEdFileDataWrapper(((FileContent) diffContent).getFile()); |
223 | 250 | } |
224 | | - }); |
| 251 | + if (diffContent instanceof DocumentContent) { |
| 252 | + Document document = ((DocumentContent) diffContent).getDocument(); |
| 253 | + return new ByteArrayData(document.getText().getBytes(StandardCharsets.UTF_8)); |
| 254 | + } |
| 255 | + } |
| 256 | + |
| 257 | + return null; |
225 | 258 | } |
226 | 259 |
|
227 | 260 | public void registerBinaryStatus(BinaryStatusApi binaryStatusApi) { |
|
0 commit comments