mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 06:39:38 +07:00
diff: move fragmented contents to api
This commit is contained in:
@@ -23,6 +23,7 @@ import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -77,6 +78,12 @@ public abstract class DiffContentFactory {
|
||||
@Nullable
|
||||
public abstract FileContent createFile(@Nullable Project project, @NotNull VirtualFile file);
|
||||
|
||||
@NotNull
|
||||
public abstract DocumentContent createFragment(@Nullable Project project, @NotNull Document document, @NotNull TextRange range);
|
||||
|
||||
@NotNull
|
||||
public abstract DocumentContent createFragment(@Nullable Project project, @NotNull DocumentContent content, @NotNull TextRange range);
|
||||
|
||||
@NotNull
|
||||
public abstract DiffContent createClipboardContent();
|
||||
|
||||
|
||||
@@ -15,17 +15,20 @@
|
||||
*/
|
||||
package com.intellij.diff;
|
||||
|
||||
import com.intellij.diff.actions.DocumentFragmentContent;
|
||||
import com.intellij.diff.contents.*;
|
||||
import com.intellij.ide.highlighter.ArchiveFileType;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileTypes.BinaryFileTypeDecompilers;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.ide.CopyPasteManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
@@ -143,6 +146,19 @@ public class DiffContentFactoryImpl extends DiffContentFactory {
|
||||
return (FileContent)create(project, file);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DocumentContent createFragment(@Nullable Project project, @NotNull Document document, @NotNull TextRange range) {
|
||||
DocumentContent content = create(project, document);
|
||||
return new DocumentFragmentContent(project, content, range);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DocumentContent createFragment(@Nullable Project project, @NotNull DocumentContent content, @NotNull TextRange range) {
|
||||
return new DocumentFragmentContent(project, content, range);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public DiffContent createClipboardContent() {
|
||||
@@ -225,10 +241,10 @@ public class DiffContentFactoryImpl extends DiffContentFactory {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static VirtualFile createTemporalFile(@Nullable Project project,
|
||||
@NotNull String prefix,
|
||||
@NotNull String suffix,
|
||||
@NotNull byte[] content) throws IOException {
|
||||
private static VirtualFile createTemporalFile(@Nullable Project project,
|
||||
@NotNull String prefix,
|
||||
@NotNull String suffix,
|
||||
@NotNull byte[] content) throws IOException {
|
||||
File tempFile = FileUtil.createTempFile(PathUtil.suggestFileName(prefix + "_", true, false),
|
||||
PathUtil.suggestFileName("_" + suffix, true, false), true);
|
||||
if (content.length != 0) {
|
||||
|
||||
@@ -106,7 +106,7 @@ public class CompareClipboardWithSelectionAction extends BaseShowDiffAction {
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
if (selectionModel.hasSelection()) {
|
||||
TextRange range = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
|
||||
content = new DocumentFragmentContent(project, content, range);
|
||||
content = DiffContentFactory.getInstance().createFragment(project, content, range);
|
||||
}
|
||||
|
||||
return content;
|
||||
|
||||
@@ -48,20 +48,29 @@ public class DocumentFragmentContent extends DiffContentBase implements Document
|
||||
private int myAssignments = 0;
|
||||
|
||||
public DocumentFragmentContent(@Nullable Project project, @NotNull DocumentContent original, @NotNull TextRange range) {
|
||||
this(project, original, createRangeMarker(original.getDocument(), range));
|
||||
}
|
||||
|
||||
public DocumentFragmentContent(@Nullable Project project, @NotNull DocumentContent original, @NotNull RangeMarker rangeMarker) {
|
||||
myOriginal = original;
|
||||
myRangeMarker = rangeMarker;
|
||||
|
||||
Document document1 = myOriginal.getDocument();
|
||||
|
||||
Document document2 = EditorFactory.getInstance().createDocument("");
|
||||
document2.putUserData(UndoManager.ORIGINAL_DOCUMENT, document1);
|
||||
|
||||
myRangeMarker = document1.createRangeMarker(range.getStartOffset(), range.getEndOffset(), true);
|
||||
myRangeMarker.setGreedyToLeft(true);
|
||||
myRangeMarker.setGreedyToRight(true);
|
||||
|
||||
mySynchronizer = new MyDocumentsSynchronizer(project, myRangeMarker, document1, document2);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static RangeMarker createRangeMarker(@NotNull Document document, @NotNull TextRange range) {
|
||||
RangeMarker rangeMarker = document.createRangeMarker(range.getStartOffset(), range.getEndOffset(), true);
|
||||
rangeMarker.setGreedyToLeft(true);
|
||||
rangeMarker.setGreedyToRight(true);
|
||||
return rangeMarker;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Document getDocument() {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.intellij.history.integration.ui.models;
|
||||
|
||||
import com.intellij.diff.DiffContentFactory;
|
||||
import com.intellij.diff.actions.DocumentFragmentContent;
|
||||
import com.intellij.diff.contents.DiffContent;
|
||||
import com.intellij.diff.contents.DocumentContent;
|
||||
import com.intellij.history.core.revisions.Revision;
|
||||
@@ -98,8 +97,7 @@ public class SelectionDifferenceModel extends FileDifferenceModel {
|
||||
int fromOffset = d.getLineStartOffset(myFrom);
|
||||
int toOffset = d.getLineEndOffset(myTo);
|
||||
|
||||
DocumentContent documentContent = DiffContentFactory.getInstance().create(myProject, d);
|
||||
return new DocumentFragmentContent(myProject, documentContent, new TextRange(fromOffset, toOffset));
|
||||
return DiffContentFactory.getInstance().createFragment(myProject, d, new TextRange(fromOffset, toOffset));
|
||||
}
|
||||
|
||||
private DocumentContent getDiffContent(Revision r, RevisionProcessingProgress p) {
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.intellij.openapi.vcs.ex;
|
||||
|
||||
import com.intellij.diff.DiffContentFactory;
|
||||
import com.intellij.diff.DiffManager;
|
||||
import com.intellij.diff.actions.DocumentFragmentContent;
|
||||
import com.intellij.diff.contents.DiffContent;
|
||||
import com.intellij.diff.contents.DocumentContent;
|
||||
import com.intellij.diff.requests.DiffRequest;
|
||||
@@ -70,7 +69,7 @@ public class ShowLineStatusRangeDiffAction extends BaseLineStatusRangeAction {
|
||||
private DiffContent createDiffContent(@NotNull Document document, @NotNull TextRange textRange, @Nullable VirtualFile file) {
|
||||
final Project project = myLineStatusTracker.getProject();
|
||||
DocumentContent content = DiffContentFactory.getInstance().create(project, document, file);
|
||||
return new DocumentFragmentContent(project, content, textRange);
|
||||
return DiffContentFactory.getInstance().createFragment(project, content, textRange);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.intellij.ide.commander;
|
||||
|
||||
import com.intellij.diff.DiffContentFactory;
|
||||
import com.intellij.diff.actions.DocumentFragmentContent;
|
||||
import com.intellij.diff.contents.DiffContent;
|
||||
import com.intellij.diff.contents.DocumentContent;
|
||||
import com.intellij.diff.requests.DiffRequest;
|
||||
@@ -42,21 +41,22 @@ public class PsiDiffContentFactory {
|
||||
|
||||
@Nullable
|
||||
private static DiffContent fromPsiElement(@NotNull PsiElement psiElement) {
|
||||
DiffContentFactory factory = DiffContentFactory.getInstance();
|
||||
if (psiElement instanceof PsiFile) {
|
||||
return DiffContentFactory.getInstance().create(psiElement.getProject(), ((PsiFile)psiElement).getVirtualFile());
|
||||
return factory.create(psiElement.getProject(), ((PsiFile)psiElement).getVirtualFile());
|
||||
}
|
||||
else if (psiElement instanceof PsiDirectory) {
|
||||
return DiffContentFactory.getInstance().create(psiElement.getProject(), ((PsiDirectory)psiElement).getVirtualFile());
|
||||
return factory.create(psiElement.getProject(), ((PsiDirectory)psiElement).getVirtualFile());
|
||||
}
|
||||
PsiFile containingFile = psiElement.getContainingFile();
|
||||
if (containingFile == null) {
|
||||
String text = psiElement.getText();
|
||||
if (text == null) return null;
|
||||
return DiffContentFactory.getInstance().create(text, psiElement.getLanguage().getAssociatedFileType(), false);
|
||||
return factory.create(text, psiElement.getLanguage().getAssociatedFileType(), false);
|
||||
}
|
||||
DocumentContent wholeFileContent = DiffContentFactory.getInstance().createDocument(psiElement.getProject(), containingFile.getVirtualFile());
|
||||
DocumentContent wholeFileContent = factory.createDocument(psiElement.getProject(), containingFile.getVirtualFile());
|
||||
if (wholeFileContent == null) return null;
|
||||
return new DocumentFragmentContent(psiElement.getProject(), wholeFileContent, psiElement.getTextRange());
|
||||
return factory.createFragment(psiElement.getProject(), wholeFileContent, psiElement.getTextRange());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user