diff options
| author | Andrew Obuchowicz | 2019-07-26 14:18:01 +0000 |
|---|---|---|
| committer | Mickael Istria | 2019-11-07 15:02:01 +0000 |
| commit | c99196e067da13f2b0804992922853da5931400c (patch) | |
| tree | e3770c0df0b796c457e281ad5f9ef89956f91033 | |
| parent | ed5af127bc267f26479e6fe0c20e535e1e89ac27 (diff) | |
| download | eclipse.platform.ui-c99196e067da13f2b0804992922853da5931400c.tar.gz eclipse.platform.ui-c99196e067da13f2b0804992922853da5931400c.tar.xz eclipse.platform.ui-c99196e067da13f2b0804992922853da5931400c.zip | |
Bug 550560 - Rename dialog shown after inline editing
Perform inline resource rename when a rename refactor *only* affects the
resource being renamed.
Change-Id: If1da291582821954daebb25724bb35f1e0400012
Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
| -rw-r--r-- | bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/RenameResourceAction.java | 42 | ||||
| -rw-r--r-- | bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/actions/LTKLauncher.java | 70 |
2 files changed, 81 insertions, 31 deletions
diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/RenameResourceAction.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/RenameResourceAction.java index bad73dd666c..2ceaeefb580 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/RenameResourceAction.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/RenameResourceAction.java @@ -430,7 +430,12 @@ public class RenameResourceAction extends WorkspaceAction { textEditor.setBounds(2, inset, Math.min(textSize.x, parentSize.x - 4), parentSize.y - 2 * inset); textEditorParent.redraw(); - textEditor.selectAll(); + int startOfFileExtension = resource.getName().lastIndexOf('.'); // $NON-NLS-1$ + if (startOfFileExtension == -1) { + textEditor.selectAll(); + } else { + textEditor.setSelection(0, startOfFileExtension); + } textEditor.setFocus(); } @@ -440,21 +445,19 @@ public class RenameResourceAction extends WorkspaceAction { if (currentResource == null || !currentResource.exists()) { return; } - if (LTKLauncher.openRenameWizard(getStructuredSelection())) { - return; - } - if (this.navigatorTree == null) { - // Do a quick read only and null check - if (!checkReadOnlyAndNull(currentResource)) { - return; - } - String newName = queryNewResourceName(currentResource); - if (newName == null || newName.isEmpty()) { - return; + if (LTKLauncher.isCompositeRename(getStructuredSelection()) || this.navigatorTree == null) { + if (!LTKLauncher.openRenameWizard(getStructuredSelection())) { + // LTK Launcher couldn't rename the resource + if (!checkReadOnlyAndNull(currentResource)) { + return; + } + String newName = queryNewResourceName(currentResource); + if (newName == null || newName.isEmpty()) { + return; + } + newPath = currentResource.getFullPath().removeLastSegments(1).append(newName); + super.run(); } - newPath = currentResource.getFullPath().removeLastSegments(1) - .append(newName); - super.run(); } else { runWithInlineEditor(); } @@ -530,9 +533,11 @@ public class RenameResourceAction extends WorkspaceAction { if (!status.isOK()) { displayError(status.getMessage()); } else { - IPath newPath = inlinedResource.getFullPath() - .removeLastSegments(1).append(newName); - runWithNewPath(newPath, inlinedResource); + if (!LTKLauncher.renameResource(newName, getStructuredSelection())) { + // LTK Launcher couldn't rename the resource + IPath newPath = inlinedResource.getFullPath().removeLastSegments(1).append(newName); + runWithNewPath(newPath, inlinedResource); + } } } inlinedResource = null; @@ -649,6 +654,7 @@ public class RenameResourceAction extends WorkspaceAction { WorkspaceUndoUtil .getUIInfoAdapter(getShell())); } catch (ExecutionException e) { + IDEWorkbenchPlugin.log(e.toString()); if (e.getCause() instanceof CoreException) { errorStatus[0] = ((CoreException) e.getCause()) .getStatus(); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/actions/LTKLauncher.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/actions/LTKLauncher.java index 140350544b3..f968602d68f 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/actions/LTKLauncher.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/actions/LTKLauncher.java @@ -15,6 +15,11 @@ package org.eclipse.ui.internal.ide.actions; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.NotEnabledException; @@ -37,7 +42,8 @@ public class LTKLauncher { private static final String LTK_DELETE_ID = "org.eclipse.ltk.ui.refactoring.commands.deleteResources"; //$NON-NLS-1$ private static final String LTK_MOVE_ID = "org.eclipse.ltk.ui.refactoring.commands.moveResources"; //$NON-NLS-1$ private static final String LTK_RENAME_ID = "org.eclipse.ltk.ui.refactoring.commands.renameResource"; //$NON-NLS-1$ - + private static final String LTK_RENAME_COMMAND_NEWNAME_KEY = "org.eclipse.ltk.ui.refactoring.commands.renameResource.newName.parameter.key"; //$NON-NLS-1$ + private static final String LTK_CHECK_COMPOSITE_RENAME_PARAMETER_KEY = "org.eclipse.ltk.ui.refactoring.commands.checkCompositeRename.parameter.key"; //$NON-NLS-1$ /** * Open the LTK delete resources wizard if available. * @@ -48,7 +54,7 @@ public class LTKLauncher { */ public static boolean openDeleteWizard( IStructuredSelection structuredSelection) { - return runCommand(LTK_DELETE_ID, structuredSelection); + return runCommand(LTK_DELETE_ID, structuredSelection, Collections.emptyMap()); } /** @@ -61,24 +67,55 @@ public class LTKLauncher { */ public static boolean openMoveWizard( IStructuredSelection structuredSelection) { - return runCommand(LTK_MOVE_ID, structuredSelection); + return runCommand(LTK_MOVE_ID, structuredSelection, Collections.emptyMap()); } /** - * Open the LTK rename resource wizard if available. + * Performs a silent resource rename using the given new name. * - * @param structuredSelection - * The action current selection. + * @param newName The new name to give the resource * - * @return <code>true</code> if we can launch the wizard + * @param structuredSelection The action current selection. + * + * @return <code>true</code> if we can perform the rename */ - public static boolean openRenameWizard( + public static boolean renameResource(String newName, IStructuredSelection structuredSelection) { - return runCommand(LTK_RENAME_ID, structuredSelection); + Map<String, Object> commandParameters = new HashMap<>(); + commandParameters.put(LTK_RENAME_COMMAND_NEWNAME_KEY, newName); + return runCommand(LTK_RENAME_ID, structuredSelection, commandParameters); + } + + /** + * Open the LTK rename resource wizard if available. The resource's new name + * will be inputed in the wizard dialog. + * + * + * @param structuredSelection The action current selection. + * + * @return <code>true</code> if we can launch the wizard + */ + public static boolean openRenameWizard(IStructuredSelection structuredSelection) { + return runCommand(LTK_RENAME_ID, structuredSelection, Collections.emptyMap()); } - private static boolean runCommand(String commandId, - IStructuredSelection selection) { + /** + * Returns true if a rename would result in multiple files being affected + * (composite change), false if only the file being renamed is affected. + * + * @param structuredSelection The action current selection. + * @return <code>true</code> if a rename is composite change, <code>false</code> + * otherwise + */ + public static boolean isCompositeRename(IStructuredSelection structuredSelection) { + Map<String, Object> commandParameters = new HashMap<>(); + commandParameters.put(LTK_CHECK_COMPOSITE_RENAME_PARAMETER_KEY, true); + return runCommand(LTK_RENAME_ID, structuredSelection, commandParameters); + } + + private static boolean runCommand(String commandId, IStructuredSelection selection, + Map<String, Object> commandParameters) { + ICommandService commandService = PlatformUI .getWorkbench().getService(ICommandService.class); Command cmd = commandService.getCommand(commandId); @@ -93,13 +130,20 @@ public class LTKLauncher { c = new EvaluationContext(handlerService .createContextSnapshot(false), selection.toList()); c.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection); + for (Entry<String, Object> entry : commandParameters.entrySet()) { + c.addVariable(entry.getKey(), entry.getValue()); + } } try { + Object commandResult; if (c != null) { - handlerService.executeCommandInContext( + commandResult = handlerService.executeCommandInContext( new ParameterizedCommand(cmd, null), null, c); } else { - handlerService.executeCommand(commandId, null); + commandResult = handlerService.executeCommand(commandId, null); + } + if (commandResult instanceof Boolean) { + return (Boolean) commandResult; } return true; } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { |
