Mercurial > projects > dwt-addons
annotate dwtx/jface/text/templates/InclusivePositionUpdater.d @ 140:26688fec6d23
Following dsss compile errors
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 03:23:46 +0200 |
parents | 7d818bd32d63 |
children | 75302ef3f92f |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2005 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.templates.InclusivePositionUpdater; | |
14 | |
131 | 15 import dwtx.jface.text.templates.SimpleTemplateVariableResolver; // packageimport |
16 import dwtx.jface.text.templates.TemplateBuffer; // packageimport | |
17 import dwtx.jface.text.templates.TemplateContext; // packageimport | |
18 import dwtx.jface.text.templates.TemplateContextType; // packageimport | |
19 import dwtx.jface.text.templates.Template; // packageimport | |
20 import dwtx.jface.text.templates.TemplateVariable; // packageimport | |
21 import dwtx.jface.text.templates.PositionBasedCompletionProposal; // packageimport | |
22 import dwtx.jface.text.templates.TemplateException; // packageimport | |
23 import dwtx.jface.text.templates.TemplateTranslator; // packageimport | |
24 import dwtx.jface.text.templates.DocumentTemplateContext; // packageimport | |
25 import dwtx.jface.text.templates.GlobalTemplateVariables; // packageimport | |
26 import dwtx.jface.text.templates.TemplateProposal; // packageimport | |
27 import dwtx.jface.text.templates.ContextTypeRegistry; // packageimport | |
28 import dwtx.jface.text.templates.JFaceTextTemplateMessages; // packageimport | |
29 import dwtx.jface.text.templates.TemplateCompletionProcessor; // packageimport | |
30 import dwtx.jface.text.templates.TextTemplateMessages; // packageimport | |
31 import dwtx.jface.text.templates.TemplateVariableType; // packageimport | |
32 import dwtx.jface.text.templates.TemplateVariableResolver; // packageimport | |
33 | |
34 | |
129 | 35 import dwt.dwthelper.utils; |
36 | |
37 import dwtx.jface.text.BadPositionCategoryException; | |
38 import dwtx.jface.text.DocumentEvent; | |
39 import dwtx.jface.text.IPositionUpdater; | |
40 import dwtx.jface.text.Position; | |
41 | |
42 /** | |
43 * Position updater that takes any change in [position.offset, position.offset + position.length] as | |
44 * belonging to the position. | |
45 * | |
46 * @since 3.0 | |
47 */ | |
48 class InclusivePositionUpdater : IPositionUpdater { | |
49 | |
50 /** The position category. */ | |
51 private final String fCategory; | |
52 | |
53 /** | |
54 * Creates a new updater for the given <code>category</code>. | |
55 * | |
56 * @param category the new category. | |
57 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
58 public this(String category) { |
129 | 59 fCategory= category; |
60 } | |
61 | |
62 /* | |
63 * @see dwtx.jface.text.IPositionUpdater#update(dwtx.jface.text.DocumentEvent) | |
64 */ | |
65 public void update(DocumentEvent event) { | |
66 | |
67 int eventOffset= event.getOffset(); | |
68 int eventOldLength= event.getLength(); | |
69 int eventNewLength= event.getText() is null ? 0 : event.getText().length(); | |
70 int deltaLength= eventNewLength - eventOldLength; | |
71 | |
72 try { | |
73 Position[] positions= event.getDocument().getPositions(fCategory); | |
74 | |
75 for (int i= 0; i !is positions.length; i++) { | |
76 | |
77 Position position= positions[i]; | |
78 | |
79 if (position.isDeleted()) | |
80 continue; | |
81 | |
82 int offset= position.getOffset(); | |
83 int length= position.getLength(); | |
84 int end= offset + length; | |
85 | |
86 if (offset > eventOffset + eventOldLength) | |
87 // position comes way | |
88 // after change - shift | |
89 position.setOffset(offset + deltaLength); | |
90 else if (end < eventOffset) { | |
91 // position comes way before change - | |
92 // leave alone | |
93 } else if (offset <= eventOffset && end >= eventOffset + eventOldLength) { | |
94 // event completely internal to the position - adjust length | |
95 position.setLength(length + deltaLength); | |
96 } else if (offset < eventOffset) { | |
97 // event extends over end of position - adjust length | |
98 int newEnd= eventOffset + eventNewLength; | |
99 position.setLength(newEnd - offset); | |
100 } else if (end > eventOffset + eventOldLength) { | |
101 // event extends from before position into it - adjust offset | |
102 // and length | |
103 // offset becomes end of event, length adjusted accordingly | |
104 // we want to recycle the overlapping part | |
105 position.setOffset(eventOffset); | |
106 int deleted= eventOffset + eventOldLength - offset; | |
107 position.setLength(length - deleted + eventNewLength); | |
108 } else { | |
109 // event consumes the position - delete it | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
110 position.delete_(); |
129 | 111 } |
112 } | |
113 } catch (BadPositionCategoryException e) { | |
114 // ignore and return | |
115 } | |
116 } | |
117 | |
118 /** | |
119 * Returns the position category. | |
120 * | |
121 * @return the position category | |
122 */ | |
123 public String getCategory() { | |
124 return fCategory; | |
125 } | |
126 | |
127 } |