Bug 560027 - Copy/Paste during inline-rename in Project Explorer doesn't
work
Reintegrate TextActionHandler in the standard rename action to ensure
common actions like copy/paste are redirected to the text control while
inline rename is active.
Change-Id: I9456b1eff0a15f22d3da332fe0233e8a03d2b5e5
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
diff --git a/bundles/org.eclipse.ui.ide/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.ide/META-INF/MANIFEST.MF
index c871087..06a056d 100644
--- a/bundles/org.eclipse.ui.ide/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.ui.ide/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.ui.ide; singleton:=true
-Bundle-Version: 3.17.300.qualifier
+Bundle-Version: 3.18.0.qualifier
Bundle-ClassPath: .
Bundle-Activator: org.eclipse.ui.internal.ide.IDEWorkbenchPlugin
Bundle-ActivationPolicy: lazy
diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/TextActionHandler.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/TextActionHandler.java
index 0627ae0..090e6ee 100644
--- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/TextActionHandler.java
+++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/TextActionHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Paul Pazderski - Add automated delegate mode to fix bug 560027
*******************************************************************************/
package org.eclipse.ui.actions;
@@ -96,6 +97,18 @@
private IActionBars actionBars;
+ /**
+ * If <code>true</code> the actions (copy, past, ...) are populated from the
+ * currently active actionBars global action handles every time a text control
+ * is activated.
+ * <p>
+ * This way a user of TextActionHandler no longer has to provide the actions
+ * which should be applied when the inline text control is inactive but
+ * TextActionHandler will automatically use what is already registered as
+ * respective action.
+ */
+ private boolean autoMode = false;
+
private MouseAdapter mouseAdapter = new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
@@ -117,6 +130,7 @@
case SWT.Activate:
activeTextControl = (Text) event.widget;
updateActionsEnableState();
+ injectTextActionHandles();
break;
case SWT.Deactivate:
activeTextControl = null;
@@ -371,9 +385,31 @@
* and Select All
*/
public TextActionHandler(IActionBars actionBar) {
+ this(actionBar, false);
+ }
+
+ /**
+ * Creates a <code>Text</code> control action handler for the global Cut, Copy,
+ * Paste, Delete, and Select All of the action bar.
+ *
+ * @param actionBar the action bar to register global action handlers for Cut,
+ * Copy, Paste, Delete, and Select All
+ * @param autoMode If <code>true</code> the actions (copy, past, ...) to use
+ * while no text widget is active are automatically populated
+ * from the actionBars global action handles which are active
+ * at the time an inline text control is activated.
+ * <p>
+ * The set<em>Xxx</em>Action methods have no use if
+ * <em>autoMode</em> is <code>true</code>.
+ * @since 3.18
+ */
+ public TextActionHandler(IActionBars actionBar, boolean autoMode) {
super();
- actionBars = actionBar;
- updateActionBars();
+ this.actionBars = actionBar;
+ this.autoMode = autoMode;
+ if (!autoMode) {
+ updateActionBars();
+ }
}
/**
@@ -412,13 +448,14 @@
// We really want a selection listener but it is not supported so we
// use a key listener and a mouse listener to know when selection changes
- // may have occured
+ // may have occurred
textControl.addKeyListener(keyAdapter);
textControl.addMouseListener(mouseAdapter);
if (textControl.isFocusControl()) {
activeTextControl = textControl;
updateActionsEnableState();
+ injectTextActionHandles();
}
}
@@ -597,4 +634,39 @@
textSelectAllAction.updateEnabledState();
textDeleteAction.updateEnabledState();
}
+
+ /**
+ * Replace the currently active copy, paste, etc. actions with our redirecting
+ * text handling actions and set the redirection target to the previous active
+ * action.
+ * <p>
+ * Has no function if <em>autoMode</em> is <code>false</code> because the
+ * actions are explicit set then.
+ */
+ private void injectTextActionHandles() {
+ if (autoMode) {
+ IAction action = actionBars.getGlobalActionHandler(ActionFactory.CUT.getId());
+ if (action != textCutAction) {
+ setCutAction(action);
+ }
+ action = actionBars.getGlobalActionHandler(ActionFactory.COPY.getId());
+ if (action != textCopyAction) {
+ setCopyAction(action);
+ }
+ action = actionBars.getGlobalActionHandler(ActionFactory.PASTE.getId());
+ if (action != textPasteAction) {
+ setPasteAction(action);
+ }
+ action = actionBars.getGlobalActionHandler(ActionFactory.SELECT_ALL.getId());
+ if (action != textSelectAllAction) {
+ setSelectAllAction(action);
+ }
+ action = actionBars.getGlobalActionHandler(ActionFactory.DELETE.getId());
+ if (action != textDeleteAction) {
+ setDeleteAction(action);
+ }
+
+ updateActionBars();
+ }
+ }
}
diff --git a/bundles/org.eclipse.ui.ide/pom.xml b/bundles/org.eclipse.ui.ide/pom.xml
index 32db257..feab8e1 100644
--- a/bundles/org.eclipse.ui.ide/pom.xml
+++ b/bundles/org.eclipse.ui.ide/pom.xml
@@ -20,7 +20,7 @@
</parent>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui.ide</artifactId>
- <version>3.17.300-SNAPSHOT</version>
+ <version>3.18.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
diff --git a/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/RefactorActionGroup.java b/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/RefactorActionGroup.java
index 29dbde1..78b1a6c 100644
--- a/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/RefactorActionGroup.java
+++ b/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/RefactorActionGroup.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -28,12 +28,12 @@
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.actions.MoveResourceAction;
import org.eclipse.ui.actions.RenameResourceAction;
+import org.eclipse.ui.actions.TextActionHandler;
import org.eclipse.ui.ide.ResourceSelectionUtil;
import org.eclipse.ui.navigator.ICommonMenuConstants;
/**
- * This is the action group for refactor actions, including global action
- * handlers for copy, paste and delete.
+ * This is the action group for refactor actions.
*
* @since 2.0
*/
@@ -47,6 +47,8 @@
private Tree tree;
+ private TextActionHandler textActionHandler;
+
/**
*
* @param aShell
@@ -75,8 +77,12 @@
@Override
public void fillActionBars(IActionBars actionBars) {
+ if (textActionHandler != null) {
+ textActionHandler.dispose();
+ }
+ textActionHandler = new TextActionHandler(actionBars, true);
+ renameAction.setTextActionHandler(textActionHandler);
- // renameAction.setTextActionHandler(textActionHandler);
updateActionBars();
actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), moveAction);
@@ -119,4 +125,12 @@
renameAction.selectionChanged(selection);
}
+ @Override
+ public void dispose() {
+ if (textActionHandler != null) {
+ textActionHandler.dispose();
+ }
+ textActionHandler = null;
+ super.dispose();
+ }
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/TextHandlerTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/TextHandlerTest.java
index 4380fa6..c0e289e 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/TextHandlerTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/TextHandlerTest.java
@@ -22,14 +22,16 @@
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.URLTransfer;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.actions.TextActionHandler;
import org.eclipse.ui.tests.harness.util.UITestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
- * @since 3.5
+ * Test for {@link TextActionHandler}.
*
+ * @since 3.5
*/
@RunWith(JUnit4.class)
public class TextHandlerTest extends UITestCase {