20
20
21
21
import org .eclipse .core .resources .IResource ;
22
22
import org .eclipse .core .runtime .FileLocator ;
23
+ import org .eclipse .jface .text .IBlockTextSelection ;
23
24
import org .eclipse .jface .text .ITextSelection ;
25
+ import org .eclipse .jface .viewers .ISelection ;
24
26
25
27
import de .anbos .eclipse .easyshell .plugin .Activator ;
26
28
import de .anbos .eclipse .easyshell .plugin .misc .ResourceUtils ;
@@ -31,7 +33,7 @@ public class Resource {
31
33
// internal
32
34
private File file = null ;
33
35
private IResource resource = null ;
34
- private ITextSelection textSelection = null ;
36
+ private ISelection textSelection = null ;
35
37
36
38
// resolved
37
39
private String projectName = Activator .getResourceString ("easyshell.plugin.name" );
@@ -42,7 +44,7 @@ public Resource(Resource myRes) {
42
44
this .textSelection = myRes .getTextSelection ();
43
45
}
44
46
45
- public Resource (File file , IResource resource , ITextSelection textSelection ) {
47
+ public Resource (File file , IResource resource , ISelection textSelection ) {
46
48
this .file = file ;
47
49
this .resource = resource ;
48
50
this .textSelection = textSelection ;
@@ -56,6 +58,10 @@ public Resource(IResource resource) {
56
58
this (resource .getLocation ().toFile (), resource , null );
57
59
}
58
60
61
+ public void setTextSelection (ISelection textSelection ) {
62
+ this .textSelection = textSelection ;
63
+ }
64
+
59
65
public File getFile () {
60
66
return file ;
61
67
}
@@ -64,7 +70,7 @@ public IResource getResource() {
64
70
return resource ;
65
71
}
66
72
67
- public ITextSelection getTextSelection () {
73
+ public ISelection getTextSelection () {
68
74
return textSelection ;
69
75
}
70
76
@@ -160,38 +166,46 @@ public String getResourcePath() {
160
166
}
161
167
162
168
public String getSelectedTextStartLine () {
163
- if (textSelection != null ) {
164
- return String .valueOf (textSelection .getStartLine ()+1 );
165
- }
166
- return "" ;
169
+ if (textSelection != null && textSelection instanceof ITextSelection ) {
170
+ return String .valueOf ((( ITextSelection ) textSelection ) .getStartLine ()+1 );
171
+ }
172
+ return "" ;
167
173
}
168
174
169
175
public String getSelectedTextEndLine () {
170
- if (textSelection != null ) {
171
- return String .valueOf (textSelection .getEndLine ()+1 );
172
- }
173
- return "" ;
176
+ if (textSelection != null && textSelection instanceof ITextSelection ) {
177
+ return String .valueOf ((( ITextSelection ) textSelection ) .getEndLine ()+1 );
178
+ }
179
+ return "" ;
174
180
}
175
181
176
182
public String getSelectedTextLength () {
177
- if (textSelection != null ) {
178
- return String .valueOf (textSelection .getLength ());
179
- }
180
- return "" ;
183
+ if (textSelection != null ) {
184
+ if (textSelection instanceof IBlockTextSelection ) {
185
+ return String .valueOf (((IBlockTextSelection )textSelection ).getText ().length ());
186
+ } else {
187
+ return String .valueOf (((ITextSelection )textSelection ).getLength ());
188
+ }
189
+ }
190
+ return "" ;
181
191
}
182
192
183
193
public String getSelectedTextOffset () {
184
- if (textSelection != null ) {
185
- return String .valueOf (textSelection .getOffset ());
186
- }
187
- return "" ;
194
+ if (textSelection != null && textSelection instanceof ITextSelection ) {
195
+ return String .valueOf ((( ITextSelection ) textSelection ) .getOffset ());
196
+ }
197
+ return "" ;
188
198
}
189
199
190
200
public String getSelectedText () {
191
- if (textSelection != null ) {
192
- return textSelection .getText ();
193
- }
194
- return "" ;
201
+ if (textSelection != null ) {
202
+ if (textSelection instanceof IBlockTextSelection ) {
203
+ return ((IBlockTextSelection )textSelection ).getText ();
204
+ } else {
205
+ return ((ITextSelection )textSelection ).getText ();
206
+ }
207
+ }
208
+ return "" ;
195
209
}
196
210
197
211
public String getProjectLocation () {
@@ -325,8 +339,4 @@ public String getScriptBash(String parameter) {
325
339
return file != null && file .exists () ? file .getAbsolutePath () : "file does not exists" ;
326
340
}
327
341
328
- public void setTextSelection (ITextSelection sel ) {
329
- textSelection = sel ;
330
- }
331
-
332
342
}
0 commit comments