129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.projection.ChildDocument;
|
|
14
|
131
|
15 import dwtx.jface.text.projection.ProjectionMapping; // packageimport
|
|
16 import dwtx.jface.text.projection.ChildDocumentManager; // packageimport
|
|
17 import dwtx.jface.text.projection.SegmentUpdater; // packageimport
|
|
18 import dwtx.jface.text.projection.Segment; // packageimport
|
|
19 import dwtx.jface.text.projection.ProjectionDocument; // packageimport
|
|
20 import dwtx.jface.text.projection.FragmentUpdater; // packageimport
|
|
21 import dwtx.jface.text.projection.ProjectionDocumentEvent; // packageimport
|
|
22 import dwtx.jface.text.projection.IMinimalMapping; // packageimport
|
|
23 import dwtx.jface.text.projection.Fragment; // packageimport
|
|
24 import dwtx.jface.text.projection.ProjectionTextStore; // packageimport
|
|
25 import dwtx.jface.text.projection.ProjectionDocumentManager; // packageimport
|
|
26
|
|
27
|
129
|
28 import dwt.dwthelper.utils;
|
|
29
|
|
30 import dwtx.jface.text.BadLocationException;
|
|
31 import dwtx.jface.text.IDocument;
|
|
32 import dwtx.jface.text.IRegion;
|
|
33 import dwtx.jface.text.Position;
|
|
34
|
|
35 /**
|
|
36 * Implementation of a child document based on
|
|
37 * {@link dwtx.jface.text.projection.ProjectionDocument}. This class
|
|
38 * exists for compatibility reasons.
|
|
39 * <p>
|
|
40 * Internal class. This class is not intended to be used by clients.</p>
|
|
41 *
|
|
42 * @since 3.0
|
|
43 * @noinstantiate This class is not intended to be instantiated by clients.
|
|
44 * @noextend This class is not intended to be subclassed by clients.
|
|
45 */
|
|
46 public class ChildDocument : ProjectionDocument {
|
|
47
|
|
48 /**
|
|
49 * Position reflecting a visible region. The exclusive end offset of the position
|
|
50 * is considered being overlapping with the visible region.
|
|
51 */
|
|
52 static private class VisibleRegion : Position {
|
|
53
|
|
54 /**
|
|
55 * Creates a new visible region.
|
|
56 *
|
|
57 * @param regionOffset the offset of the region
|
|
58 * @param regionLength the length of the region
|
|
59 */
|
|
60 public VisibleRegion(int regionOffset, int regionLength) {
|
|
61 super(regionOffset, regionLength);
|
|
62 }
|
|
63
|
|
64 /**
|
|
65 * If <code>regionOffset</code> is the end of the visible region and the <code>regionLength is 0</code>,
|
|
66 * the <code>regionOffset</code> is considered overlapping with the visible region.
|
|
67 *
|
|
68 * @see dwtx.jface.text.Position#overlapsWith(int, int)
|
|
69 */
|
|
70 public bool overlapsWith(int regionOffset, int regionLength) {
|
|
71 bool appending= (regionOffset is offset + length) && regionLength is 0;
|
|
72 return appending || super.overlapsWith(regionOffset, regionLength);
|
|
73 }
|
|
74 }
|
|
75
|
|
76 /**
|
|
77 * Creates a new child document.
|
|
78 *
|
|
79 * @param masterDocument @inheritDoc
|
|
80 */
|
|
81 public ChildDocument(IDocument masterDocument) {
|
|
82 super(masterDocument);
|
|
83 }
|
|
84
|
|
85 /**
|
|
86 * Returns the parent document of this child document.
|
|
87 *
|
|
88 * @return the parent document of this child document
|
|
89 * @see ProjectionDocument#getMasterDocument()
|
|
90 */
|
|
91 public IDocument getParentDocument() {
|
|
92 return getMasterDocument();
|
|
93 }
|
|
94
|
|
95 /**
|
|
96 * Sets the parent document range covered by this child document to the
|
|
97 * given range.
|
|
98 *
|
|
99 * @param offset the offset of the range
|
|
100 * @param length the length of the range
|
|
101 * @throws BadLocationException if the given range is not valid
|
|
102 */
|
|
103 public void setParentDocumentRange(int offset, int length) throws BadLocationException {
|
|
104 replaceMasterDocumentRanges(offset, length);
|
|
105 }
|
|
106
|
|
107 /**
|
|
108 * Returns the parent document range of this child document.
|
|
109 *
|
|
110 * @return the parent document range of this child document
|
|
111 */
|
|
112 public Position getParentDocumentRange() {
|
|
113 IRegion coverage= getDocumentInformationMapping().getCoverage();
|
|
114 return new VisibleRegion(coverage.getOffset(), coverage.getLength());
|
|
115 }
|
|
116 }
|