diff options
author | Pascal Rapicault | 2015-08-19 22:03:29 +0000 |
---|---|---|
committer | Pascal Rapicault | 2015-09-02 19:46:06 +0000 |
commit | e1ecbb6bdbe5d9d8d58d9eaaa16a79d609a6b30c (patch) | |
tree | 080b1ef452d76f2ae4745bb02e18db7c86b383f2 | |
parent | 7d572cec4c7ccc179d0c13ef44998a8d746148cb (diff) | |
download | eclipse.platform.team-e1ecbb6bdbe5d9d8d58d9eaaa16a79d609a6b30c.tar.gz eclipse.platform.team-e1ecbb6bdbe5d9d8d58d9eaaa16a79d609a6b30c.tar.xz eclipse.platform.team-e1ecbb6bdbe5d9d8d58d9eaaa16a79d609a6b30c.zip |
Bug 475427 - [compare] No syntax highlighting when IDocument is passed
in as input
Change-Id: If494d46cf5a4ff969976db649d85665e13d10d19
Signed-off-by: Pascal Rapicault <pascal@rapicorp.com>
2 files changed, 108 insertions, 0 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java index de96fc66b..6d0612521 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java @@ -684,6 +684,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { } else if (fElement instanceof IDocument) { newDocument= (IDocument) fElement; + setupDocument(newDocument); } else if (fElement instanceof IStreamContentAccessor) { newDocument= DocumentManager.get(fElement); diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java index 171d4ac68..6ef6b4277 100644 --- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java @@ -33,8 +33,12 @@ import org.eclipse.compare.structuremergeviewer.Differencer; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITypedRegion; import org.eclipse.jface.text.Region; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; @@ -461,4 +465,107 @@ public class TextMergeViewerTest extends TestCase { } }, cc); } + + + public void testDocumentAsTypedElement() throws Exception { + class DocumentAsTypedElement extends Document implements ITypedElement { + + public String getName() { + return "file"; + } + + public Image getImage() { + return null; + } + + public String getType() { + return ITypedElement.UNKNOWN_TYPE; + } + } + DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement()); + DocumentAsTypedElement leftDoc = new DocumentAsTypedElement(); + DocumentAsTypedElement rightDoc = new DocumentAsTypedElement(); + DiffNode testNode = new DiffNode(parentNode, Differencer.DELETION, null, leftDoc, rightDoc); + runInDialogWithPartioner(testNode, new Runnable() { + public void run() { + //Not needed + } + }, new CompareConfiguration()); + assertNotNull(leftDoc.getDocumentPartitioner()); + assertNotNull(rightDoc.getDocumentPartitioner()); + } + + + private void runInDialogWithPartioner(Object input, Runnable runnable, final CompareConfiguration cc) throws Exception { + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + Dialog dialog = new Dialog(shell) { + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + viewer = new TestMergeViewerWithPartitioner(composite, cc); + return composite; + } + }; + dialog.setBlockOnOpen(false); + dialog.open(); + viewer.setInput(input); + try { + runnable.run(); + } catch (WrappedException e) { + e.throwException(); + } + dialog.close(); + viewer = null; + } + + //This viewer is used to provide a dummy partitioner + public static class TestMergeViewerWithPartitioner extends TestMergeViewer { + public class DummyPartitioner implements IDocumentPartitioner { + public void connect(IDocument document) { + //Nothing to do + } + + public void disconnect() { + //Nothing to do + } + + public void documentAboutToBeChanged(DocumentEvent event) { + //Nothing to do + } + + public boolean documentChanged(DocumentEvent event) { + return false; + } + + public String[] getLegalContentTypes() { + return null; + } + + public String getContentType(int offset) { + return null; + } + + public ITypedRegion[] computePartitioning(int offset, int length) { + return null; + } + + public ITypedRegion getPartition(int offset) { + return null; + } + + } + public TestMergeViewerWithPartitioner(Composite parent) { + super(parent, new CompareConfiguration()); + } + + public TestMergeViewerWithPartitioner(Composite parent, CompareConfiguration cc) { + super(parent, cc); + } + + public void copy(boolean leftToRight) { + super.copy(leftToRight); + } + protected IDocumentPartitioner getDocumentPartitioner() { + return new DummyPartitioner(); + } + } } |