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.ReplaceEdit;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18 import dwtx.core.runtime.Assert;
|
|
19 import dwtx.jface.text.BadLocationException;
|
|
20 import dwtx.jface.text.IDocument;
|
|
21
|
|
22 /**
|
|
23 * Text edit to replace a range in a document with a different
|
|
24 * string.
|
|
25 *
|
|
26 * @since 3.0
|
|
27 */
|
|
28 public final class ReplaceEdit : TextEdit {
|
|
29
|
|
30 private String fText;
|
|
31
|
|
32 /**
|
|
33 * Constructs a new replace edit.
|
|
34 *
|
|
35 * @param offset the offset of the range to replace
|
|
36 * @param length the length of the range to replace
|
|
37 * @param text the new text
|
|
38 */
|
130
|
39 public this(int offset, int length, String text) {
|
129
|
40 super(offset, length);
|
|
41 Assert.isNotNull(text);
|
|
42 fText= text;
|
|
43 }
|
|
44
|
|
45 /*
|
|
46 * Copy constructor
|
|
47 *
|
|
48 * @param other the edit to copy from
|
|
49 */
|
130
|
50 private this(ReplaceEdit other) {
|
129
|
51 super(other);
|
|
52 fText= other.fText;
|
|
53 }
|
|
54
|
|
55 /**
|
|
56 * Returns the new text replacing the text denoted
|
|
57 * by the edit.
|
|
58 *
|
|
59 * @return the edit's text.
|
|
60 */
|
|
61 public String getText() {
|
|
62 return fText;
|
|
63 }
|
|
64
|
|
65 /*
|
|
66 * @see TextEdit#doCopy
|
|
67 */
|
|
68 protected TextEdit doCopy() {
|
|
69 return new ReplaceEdit(this);
|
|
70 }
|
|
71
|
|
72 /*
|
|
73 * @see TextEdit#accept0
|
|
74 */
|
|
75 protected void accept0(TextEditVisitor visitor) {
|
|
76 bool visitChildren= visitor.visit(this);
|
|
77 if (visitChildren) {
|
|
78 acceptChildren(visitor);
|
|
79 }
|
|
80 }
|
|
81
|
|
82 /*
|
|
83 * @see TextEdit#performDocumentUpdating
|
|
84 */
|
|
85 int performDocumentUpdating(IDocument document) throws BadLocationException {
|
|
86 document.replace(getOffset(), getLength(), fText);
|
|
87 fDelta= fText.length() - getLength();
|
|
88 return fDelta;
|
|
89 }
|
|
90
|
|
91 /*
|
|
92 * @see TextEdit#deleteChildren
|
|
93 */
|
|
94 bool deleteChildren() {
|
|
95 return true;
|
|
96 }
|
|
97
|
|
98 /*
|
|
99 * @see dwtx.text.edits.TextEdit#internalToString(java.lang.StringBuffer, int)
|
|
100 * @since 3.3
|
|
101 */
|
|
102 void internalToString(StringBuffer buffer, int indent) {
|
|
103 super.internalToString(buffer, indent);
|
|
104 buffer.append(" <<").append(fText); //$NON-NLS-1$
|
|
105 }
|
|
106 }
|