diff options
| author | Andrew Obuchowicz | 2019-07-26 14:34:27 +0000 |
|---|---|---|
| committer | Jeff Johnston | 2019-11-05 16:16:28 +0000 |
| commit | 7eddcb88ea104856c43dfbe9f280e3d5598eba99 (patch) | |
| tree | 92db86f064bcda2878155813b089b62821f56de3 | |
| parent | 20bbd487d77ff4bbc2582ef926d455de69559a4f (diff) | |
| download | eclipse.jdt.ui-7eddcb88ea104856c43dfbe9f280e3d5598eba99.tar.gz eclipse.jdt.ui-7eddcb88ea104856c43dfbe9f280e3d5598eba99.tar.xz eclipse.jdt.ui-7eddcb88ea104856c43dfbe9f280e3d5598eba99.zip | |
Bug 550560 - Rename dialog shown after inline editingI20191105-1800
Use inline rename for rename resource operations that only affect the
file being affected.
Keep rename dialog for composite renames & rename
resource operations which use a
refactoring processor other than RenameResourceProcessor.
Change-Id: I880dce086b031ed60a19522b10a57aca34e63ef0
Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
4 files changed, 73 insertions, 14 deletions
diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringUIMessages.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringUIMessages.java index e0387c65dc..1ef52953d8 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringUIMessages.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringUIMessages.java @@ -338,8 +338,6 @@ public final class RefactoringUIMessages extends NLS { public static String RefactoringWizardDialog2_buttons_preview_label; - public static String RenameResourceHandler_ERROR_EXPECTED_STRING; - public static String RenameResourceHandler_title; public static String RenameResourceWizard_name_field_label; diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringUIMessages.properties b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringUIMessages.properties index 9715ad907a..5b5ff6e14f 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringUIMessages.properties +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringUIMessages.properties @@ -191,7 +191,6 @@ RefactoringPropertyPage_confirm_delete_pattern_plural=Are you sure you want to d RefactoringDescriptorDeleteQuery_confirm_deletion_singular=Are you sure you want to delete the refactoring from the workspace refactoring history?\n\nNote: This may also affect refactoring histories of projects. RefactoringDescriptorDeleteQuery_confirm_deletion_plural=Are you sure you want to delete {0} refactorings from the workspace refactoring history?\n\nNote: This may also affect refactoring histories of projects. RefactoringPropertyPage_unsharing_refactoring_history=Unsharing refactoring history... -RenameResourceHandler_ERROR_EXPECTED_STRING=Rename refactoring command new name parameter, expected String but got a {0} RenameResourceHandler_title=Rename Resource RenameResourceWizard_name_field_label=New na&me: RenameResourceWizard_page_title=Rename Resource diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/actions/RenameResourceHandler.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/actions/RenameResourceHandler.java index 046f67165a..804b76ed76 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/actions/RenameResourceHandler.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/actions/RenameResourceHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,23 +10,35 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrew Obuchowicz <aobuchow@redhat.com> - Rename Resource should be inline ******************************************************************************/ package org.eclipse.ltk.internal.ui.refactoring.actions; -import org.eclipse.osgi.util.NLS; - import org.eclipse.swt.widgets.Shell; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; + import org.eclipse.core.resources.IResource; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; +import org.eclipse.ltk.core.refactoring.CompositeChange; +import org.eclipse.ltk.core.refactoring.CreateChangeOperation; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring; +import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor; +import org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor; +import org.eclipse.ltk.internal.ui.refactoring.InternalAPI; import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages; import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIPlugin; import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; @@ -34,36 +46,85 @@ import org.eclipse.ltk.ui.refactoring.resource.RenameResourceWizard; public class RenameResourceHandler extends AbstractResourcesHandler { private static final String LTK_RENAME_COMMAND_NEWNAME_PARAMETER_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$ @Override public Object execute(ExecutionEvent event) throws ExecutionException { + Object checkCompositeRename= HandlerUtil.getVariable(event, LTK_CHECK_COMPOSITE_RENAME_PARAMETER_KEY); + if (checkCompositeRename instanceof Boolean) { + return checkForCompositeRename(event); + } else { + performRename(event); + } + return null; + } + + private Object checkForCompositeRename(ExecutionEvent event) { + ISelection sel= HandlerUtil.getCurrentSelection(event); + if (sel instanceof IStructuredSelection) { + IResource resource= getCurrentResource((IStructuredSelection) sel); + if (resource != null) { + // A new name is required in order to compute whether the change is composite or not + String placeHolderNewName= resource.getName() + "a"; //$NON-NLS-1$ + RenameResourceWizard refactoringWizard= new RenameResourceWizard(resource, placeHolderNewName); + Change change= getChange(refactoringWizard); + return isCompositeChange(change); + } + } + return null; + } + + private void performRename(ExecutionEvent event) { Shell activeShell= HandlerUtil.getActiveShell(event); Object newNameValue= HandlerUtil.getVariable(event, LTK_RENAME_COMMAND_NEWNAME_PARAMETER_KEY); String newName= null; if (newNameValue instanceof String) { newName= (String) newNameValue; - } else if (newNameValue != null) { - RefactoringUIPlugin.logErrorMessage(NLS.bind(RefactoringUIMessages.RenameResourceHandler_ERROR_EXPECTED_STRING, newNameValue.getClass().getName())); } ISelection sel= HandlerUtil.getCurrentSelection(event); if (sel instanceof IStructuredSelection) { IResource resource= getCurrentResource((IStructuredSelection) sel); if (resource != null) { RenameResourceWizard refactoringWizard; + Change change= null; + RefactoringProcessor processor= null; if (newName != null) { refactoringWizard= new RenameResourceWizard(resource, newName); + processor= ((ProcessorBasedRefactoring) refactoringWizard.getRefactoring()).getProcessor(); + change= getChange(refactoringWizard); + //Reset the state of the wizard once we have the change it will perform + refactoringWizard= new RenameResourceWizard(resource, newName); } else { refactoringWizard= new RenameResourceWizard(resource); } - RefactoringWizardOpenOperation op= new RefactoringWizardOpenOperation(refactoringWizard); + try { - op.run(activeShell, RefactoringUIMessages.RenameResourceHandler_title); + // Let user see rename dialog with preview page for composite changes or if another RefactoringProcessor is used (which may offer rename options) + if (newName == null || change == null || isCompositeChange(change) || !(processor instanceof RenameResourceProcessor)) { + RefactoringWizardOpenOperation op= new RefactoringWizardOpenOperation(refactoringWizard); + op.run(activeShell, RefactoringUIMessages.RenameResourceHandler_title); + } else { + //Silently perform the rename without the dialog + change.perform(new NullProgressMonitor()); + } } catch (InterruptedException e) { // do nothing + } catch (CoreException e) { + RefactoringUIPlugin.log(e); } } } - return null; + } + + private Change getChange(RenameResourceWizard refactoringWizard) { + refactoringWizard.setChangeCreationCancelable(true); + refactoringWizard.setInitialComputationContext(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + return refactoringWizard.internalCreateChange(InternalAPI.INSTANCE, + new CreateChangeOperation(new CheckConditionsOperation(refactoringWizard.getRefactoring(), CheckConditionsOperation.FINAL_CONDITIONS), RefactoringStatus.FATAL), true); + } + + private boolean isCompositeChange(Change change) { + return (change instanceof CompositeChange && ((CompositeChange) change).getChildren().length > 1); } private IResource getCurrentResource(IStructuredSelection sel) { diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizard.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizard.java index e608728c2c..6d2530722c 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizard.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizard.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -617,7 +617,8 @@ public abstract class RefactoringWizard extends Wizard { */ public final Change internalCreateChange(InternalAPI api, CreateChangeOperation operation, boolean updateStatus) { Assert.isNotNull(api); - return createChange(operation, updateStatus, getContainer()); + IRunnableContext context= getContainer() != null ? getContainer() : fRunnableContext; + return createChange(operation, updateStatus, context); } /** @@ -660,7 +661,7 @@ public abstract class RefactoringWizard extends Wizard { private Change createChange(CreateChangeOperation operation, boolean updateStatus, IRunnableContext context){ InvocationTargetException exception= null; try { - context.run(true, fIsChangeCreationCancelable, new WorkbenchRunnableAdapter( + context.run((context != PlatformUI.getWorkbench().getActiveWorkbenchWindow()), fIsChangeCreationCancelable, new WorkbenchRunnableAdapter( operation, ResourcesPlugin.getWorkspace().getRoot())); } catch (InterruptedException e) { setConditionCheckingStatus(null); |
