Bug 579247 - Commands for multi-selection not available in multipage
editor
Change-Id: Ibcd40039339b3ba2c6e79820d3f840640abe95e5
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/191917
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Mickael Istria <mistria@redhat.com>
diff --git a/org.eclipse.ui.workbench.texteditor/plugin.xml b/org.eclipse.ui.workbench.texteditor/plugin.xml
index 70d47cf..9dea32d 100644
--- a/org.eclipse.ui.workbench.texteditor/plugin.xml
+++ b/org.eclipse.ui.workbench.texteditor/plugin.xml
@@ -1381,60 +1381,45 @@
class="org.eclipse.ui.internal.texteditor.ToMultiSelectionHandler"
commandId="org.eclipse.ui.edit.text.toMultiSelection">
<enabledWhen>
- <with
- variable="activeEditor">
- <instanceof
- value="org.eclipse.ui.texteditor.ITextEditor">
- </instanceof>
- </with>
+ <with variable="activeEditor">
+ <adapt type="org.eclipse.ui.texteditor.ITextEditor"/>
+ </with>
</enabledWhen>
</handler>
<handler
class="org.eclipse.ui.internal.texteditor.multiselection.AddAllMatchesToMultiSelectionHandler"
commandId="org.eclipse.ui.edit.text.select.addAllMatchesToMultiSelection">
<enabledWhen>
- <with
- variable="activeEditor">
- <instanceof
- value="org.eclipse.ui.texteditor.ITextEditor">
- </instanceof>
- </with>
+ <with variable="activeEditor">
+ <adapt type="org.eclipse.ui.texteditor.ITextEditor"/>
+ </with>
</enabledWhen>
</handler>
<handler
class="org.eclipse.ui.internal.texteditor.multiselection.MultiSelectionDownHandler"
commandId="org.eclipse.ui.edit.text.select.selectMultiSelectionDown">
<enabledWhen>
- <with
- variable="activeEditor">
- <instanceof
- value="org.eclipse.ui.texteditor.ITextEditor">
- </instanceof>
- </with>
+ <with variable="activeEditor">
+ <adapt type="org.eclipse.ui.texteditor.ITextEditor"/>
+ </with>
</enabledWhen>
</handler>
<handler
class="org.eclipse.ui.internal.texteditor.multiselection.MultiSelectionUpHandler"
commandId="org.eclipse.ui.edit.text.select.selectMultiSelectionUp">
<enabledWhen>
- <with
- variable="activeEditor">
- <instanceof
- value="org.eclipse.ui.texteditor.ITextEditor">
- </instanceof>
- </with>
+ <with variable="activeEditor">
+ <adapt type="org.eclipse.ui.texteditor.ITextEditor"/>
+ </with>
</enabledWhen>
</handler>
<handler
class="org.eclipse.ui.internal.texteditor.multiselection.StopMultiSelectionHandler"
commandId="org.eclipse.ui.edit.text.select.stopMultiSelection">
<enabledWhen>
- <with
- variable="activeEditor">
- <instanceof
- value="org.eclipse.ui.texteditor.ITextEditor">
- </instanceof>
- </with>
+ <with variable="activeEditor">
+ <adapt type="org.eclipse.ui.texteditor.ITextEditor"/>
+ </with>
</enabledWhen>
</handler>
</extension>
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/ToMultiSelectionHandler.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/ToMultiSelectionHandler.java
index 0fda409..ee9ebaf 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/ToMultiSelectionHandler.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/ToMultiSelectionHandler.java
@@ -14,6 +14,8 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.Adapters;
+
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.text.IBlockTextSelection;
@@ -33,10 +35,10 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
- if (!(editor instanceof ITextEditor)) {
+ ITextEditor textEditor = Adapters.adapt(editor, ITextEditor.class);
+ if (textEditor == null) {
return null;
}
- ITextEditor textEditor = (ITextEditor) editor;
ISelection selection = textEditor.getSelectionProvider().getSelection();
if (!(selection instanceof IBlockTextSelection)) {
return null;
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java
index ba42de9..f16c20b 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java
@@ -24,6 +24,8 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.Adapters;
+
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.text.BadLocationException;
@@ -320,7 +322,7 @@
private void initTextEditor() {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
- textEditor = editor instanceof ITextEditor ? (ITextEditor) editor : null;
+ textEditor = Adapters.adapt(editor, ITextEditor.class);
}
private IDocument getDocument() {