Mercurial > projects > dwt-addons
annotate dwtx/text/edits/TextEditGroup.d @ 159:7926b636c282
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 01:57:58 +0200 |
parents | a9566845f1cb |
children |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2006 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.text.edits.TextEditGroup; | |
14 | |
131 | 15 import dwtx.text.edits.MultiTextEdit; // packageimport |
16 import dwtx.text.edits.CopySourceEdit; // packageimport | |
17 import dwtx.text.edits.MoveSourceEdit; // packageimport | |
18 import dwtx.text.edits.CopyingRangeMarker; // packageimport | |
19 import dwtx.text.edits.ReplaceEdit; // packageimport | |
20 import dwtx.text.edits.EditDocument; // packageimport | |
21 import dwtx.text.edits.UndoCollector; // packageimport | |
22 import dwtx.text.edits.DeleteEdit; // packageimport | |
23 import dwtx.text.edits.MoveTargetEdit; // packageimport | |
24 import dwtx.text.edits.CopyTargetEdit; // packageimport | |
25 import dwtx.text.edits.TextEditCopier; // packageimport | |
26 import dwtx.text.edits.ISourceModifier; // packageimport | |
27 import dwtx.text.edits.TextEditMessages; // packageimport | |
28 import dwtx.text.edits.TextEditProcessor; // packageimport | |
29 import dwtx.text.edits.MalformedTreeException; // packageimport | |
30 import dwtx.text.edits.TreeIterationInfo; // packageimport | |
31 import dwtx.text.edits.TextEditVisitor; // packageimport | |
32 import dwtx.text.edits.TextEdit; // packageimport | |
33 import dwtx.text.edits.RangeMarker; // packageimport | |
34 import dwtx.text.edits.UndoEdit; // packageimport | |
35 import dwtx.text.edits.InsertEdit; // packageimport | |
36 | |
37 | |
129 | 38 import dwt.dwthelper.utils; |
39 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
40 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
41 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
42 |
129 | 43 |
44 import dwtx.core.runtime.Assert; | |
45 import dwtx.jface.text.IRegion; | |
46 | |
47 | |
48 /** | |
49 * A text edit group combines a list of {@link TextEdit}s | |
50 * and a name into a single object. The name must be a human | |
51 * readable string use to present the text edit group in the | |
52 * user interface. | |
53 * <p> | |
54 * Clients may extend this class to add extra information to | |
55 * a text edit group. | |
56 * </p> | |
57 * | |
58 * @since 3.0 | |
59 */ | |
60 public class TextEditGroup { | |
61 | |
62 private String fDescription; | |
63 private List fEdits; | |
64 | |
65 /** | |
66 * Creates a new text edit group with the given name. | |
67 * | |
68 * @param name the name of the text edit group. Must be | |
69 * a human readable string | |
70 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
71 public this(String name) { |
159 | 72 // super(); |
129 | 73 Assert.isNotNull(name); |
74 fDescription= name; | |
75 fEdits= new ArrayList(3); | |
76 } | |
77 | |
78 /** | |
79 * Creates a new text edit group with a name and a single | |
80 * {@link TextEdit}. | |
81 * | |
82 * @param name the name of the text edit group. Must be | |
83 * a human readable string | |
84 * @param edit the edit to manage | |
85 */ | |
130 | 86 public this(String name, TextEdit edit) { |
129 | 87 Assert.isNotNull(name); |
88 Assert.isNotNull(edit); | |
89 fDescription= name; | |
90 fEdits= new ArrayList(1); | |
91 fEdits.add(edit); | |
92 } | |
93 | |
94 /** | |
95 * Creates a new text edit group with the given name and | |
96 * array of edits. | |
97 * | |
98 * @param name the name of the text edit group. Must be | |
99 * a human readable string | |
100 * @param edits the array of edits | |
101 */ | |
130 | 102 public this(String name, TextEdit[] edits) { |
159 | 103 // super(); |
129 | 104 Assert.isNotNull(name); |
159 | 105 Assert.isTrue(edits !is null); |
129 | 106 fDescription= name; |
107 fEdits= new ArrayList(Arrays.asList(edits)); | |
108 } | |
109 | |
110 /** | |
111 * Returns the edit group's name. | |
112 * | |
113 * @return the edit group's name | |
114 */ | |
115 public String getName() { | |
116 return fDescription; | |
117 } | |
118 | |
119 /** | |
120 * Adds the given {@link TextEdit} to this group. | |
121 * | |
122 * @param edit the edit to add | |
123 */ | |
124 public void addTextEdit(TextEdit edit) { | |
125 fEdits.add(edit); | |
126 } | |
130 | 127 |
129 | 128 /** |
129 * Removes the given {@link TextEdit} from this group. | |
130 * | |
131 * @param edit the edit to remove | |
132 * @return <code>true</code> if this group contained the specified edit. | |
133 * @since 3.3 | |
134 */ | |
135 public bool removeTextEdit(TextEdit edit) { | |
136 return fEdits.remove(edit); | |
137 } | |
138 | |
139 /** | |
140 * Removes all text edits from this group. | |
141 * | |
142 * @since 3.3 | |
143 */ | |
144 public void clearTextEdits() { | |
145 fEdits.clear(); | |
146 } | |
147 | |
130 | 148 |
129 | 149 |
150 /** | |
151 * Returns <code>true</code> if the list of managed | |
152 * {@link TextEdit}s is empty; otherwise <code>false | |
153 * </code> is returned. | |
154 * | |
155 * @return whether the list of managed text edits is | |
156 * empty or not | |
157 */ | |
158 public bool isEmpty() { | |
159 return fEdits.isEmpty(); | |
160 } | |
161 | |
162 /** | |
163 * Returns an array of {@link TextEdit}s containing | |
164 * the edits managed by this group. | |
165 * | |
166 * @return the managed text edits | |
167 */ | |
168 public TextEdit[] getTextEdits() { | |
156 | 169 return arraycast!(TextEdit)( fEdits.toArray()); |
129 | 170 } |
171 | |
172 /** | |
173 * Returns the text region covered by the edits managed via this | |
174 * edit group. If the group doesn't manage any edits <code>null | |
175 * </code> is returned. | |
176 * | |
177 * @return the text region covered by this edit group or <code> | |
178 * null</code> if no edits are managed | |
179 */ | |
180 public IRegion getRegion() { | |
181 int size= fEdits.size(); | |
182 if (size is 0) { | |
183 return null; | |
184 } else if (size is 1) { | |
134 | 185 return (cast(TextEdit)fEdits.get(0)).getRegion(); |
129 | 186 } else { |
156 | 187 return TextEdit.getCoverage(arraycast!(TextEdit)(fEdits.toArray())); |
129 | 188 } |
189 } | |
190 } |