Skip to content

Commit 62b6e95

Browse files
committed
add column text selection support #249
Signed-off-by: Andre Bossert <anb0s@anbos.de>
1 parent 72927ac commit 62b6e95

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

plugin/src/de/anbos/eclipse/easyshell/plugin/misc/ResourceUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.jface.viewers.StructuredSelection;
2929
import org.eclipse.swt.widgets.Event;
3030
import org.eclipse.jface.text.ITextSelection;
31+
import org.eclipse.jface.text.IBlockTextSelection;
3132
import org.eclipse.ui.IEditorInput;
3233
import org.eclipse.ui.IEditorPart;
3334
import org.eclipse.ui.IFileEditorInput;
@@ -60,11 +61,10 @@ static public ISelection getResourceSelection(Object obj) {
6061
}
6162
}
6263
if (editor != null) {
63-
ITextSelection sel = (ITextSelection)editor.getSelectionProvider().getSelection();
6464
//String text = sel.getText();
6565
//selection = getSelectionFromText(resource, text);
6666
if (resource != null) {
67-
resource.setTextSelection(sel);
67+
resource.setTextSelection(editor.getSelectionProvider().getSelection());
6868
}
6969
}
7070
} else if (obj instanceof IWorkbenchPart) {

plugin/src/de/anbos/eclipse/easyshell/plugin/types/Resource.java

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
import org.eclipse.core.resources.IResource;
2222
import org.eclipse.core.runtime.FileLocator;
23+
import org.eclipse.jface.text.IBlockTextSelection;
2324
import org.eclipse.jface.text.ITextSelection;
25+
import org.eclipse.jface.viewers.ISelection;
2426

2527
import de.anbos.eclipse.easyshell.plugin.Activator;
2628
import de.anbos.eclipse.easyshell.plugin.misc.ResourceUtils;
@@ -31,7 +33,7 @@ public class Resource {
3133
// internal
3234
private File file = null;
3335
private IResource resource = null;
34-
private ITextSelection textSelection = null;
36+
private ISelection textSelection = null;
3537

3638
// resolved
3739
private String projectName = Activator.getResourceString("easyshell.plugin.name");
@@ -42,7 +44,7 @@ public Resource(Resource myRes) {
4244
this.textSelection = myRes.getTextSelection();
4345
}
4446

45-
public Resource(File file, IResource resource, ITextSelection textSelection) {
47+
public Resource(File file, IResource resource, ISelection textSelection) {
4648
this.file = file;
4749
this.resource = resource;
4850
this.textSelection = textSelection;
@@ -56,6 +58,10 @@ public Resource(IResource resource) {
5658
this(resource.getLocation().toFile(), resource, null);
5759
}
5860

61+
public void setTextSelection(ISelection textSelection) {
62+
this.textSelection = textSelection;
63+
}
64+
5965
public File getFile() {
6066
return file;
6167
}
@@ -64,7 +70,7 @@ public IResource getResource() {
6470
return resource;
6571
}
6672

67-
public ITextSelection getTextSelection() {
73+
public ISelection getTextSelection() {
6874
return textSelection;
6975
}
7076

@@ -160,38 +166,46 @@ public String getResourcePath() {
160166
}
161167

162168
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 "";
167173
}
168174

169175
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 "";
174180
}
175181

176182
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 "";
181191
}
182192

183193
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 "";
188198
}
189199

190200
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 "";
195209
}
196210

197211
public String getProjectLocation() {
@@ -325,8 +339,4 @@ public String getScriptBash(String parameter) {
325339
return file != null && file.exists() ? file.getAbsolutePath() : "file does not exists";
326340
}
327341

328-
public void setTextSelection(ITextSelection sel) {
329-
textSelection = sel;
330-
}
331-
332342
}

0 commit comments

Comments
 (0)