From 0f5072ee162ebcb1ade73875afb5b448d15dd628 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 19 Dec 2012 12:39:37 +0100 Subject: [PATCH] perform refactoring from preview: do not check writable twice; correct writable usages set (IDEA-97458) --- .../refactoring/BaseRefactoringProcessor.java | 7 ++--- .../src/com/intellij/usages/UsageView.java | 5 ++++ .../intellij/usages/impl/UsageViewImpl.java | 26 ++++++++++++++----- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java index 08d6922855fb..8c5004be416e 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java @@ -397,8 +397,9 @@ public abstract class BaseRefactoringProcessor { @Override public void run() { Set usagesToRefactor = getUsageInfosToRefactor(usageView); - if (ensureElementsWritable(usagesToRefactor.toArray(new UsageInfo[usagesToRefactor.size()]), viewDescriptor)) { - doRefactoring(usagesToRefactor); + final UsageInfo[] infos = usagesToRefactor.toArray(new UsageInfo[usagesToRefactor.size()]); + if (ensureElementsWritable(infos, viewDescriptor)) { + execute(infos); } } }; @@ -410,7 +411,7 @@ public abstract class BaseRefactoringProcessor { protected void addDoRefactoringAction(UsageView usageView, Runnable refactoringRunnable, String canNotMakeString) { usageView.addPerformOperationAction(refactoringRunnable, getCommandName(), canNotMakeString, - RefactoringBundle.message("usageView.doAction")); + RefactoringBundle.message("usageView.doAction"), false); } private static Set getUsageInfosToRefactor(final UsageView usageView) { diff --git a/platform/usageView/src/com/intellij/usages/UsageView.java b/platform/usageView/src/com/intellij/usages/UsageView.java index c673859b63d3..71bea5672888 100644 --- a/platform/usageView/src/com/intellij/usages/UsageView.java +++ b/platform/usageView/src/com/intellij/usages/UsageView.java @@ -65,6 +65,11 @@ public interface UsageView extends Disposable { void addPerformOperationAction(@NotNull Runnable processRunnable, String commandName, String cannotMakeString, @NotNull String shortDescription); + /** + * @param checkReadOnlyStatus if false, check is performed inside processRunnable + */ + void addPerformOperationAction(@NotNull Runnable processRunnable, String commandName, String cannotMakeString, @NotNull String shortDescription, boolean checkReadOnlyStatus); + UsageViewPresentation getPresentation(); @NotNull diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java index 040321c01694..12f71aeafa16 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java @@ -1024,13 +1024,22 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra final String commandName, final String cannotMakeString, @NotNull String shortDescription) { - addButtonToLowerPane(newPerformOperationRunnable(processRunnable, commandName, cannotMakeString), shortDescription); + addPerformOperationAction(processRunnable, commandName, cannotMakeString, shortDescription, true); + } + + @Override + public void addPerformOperationAction(@NotNull Runnable processRunnable, + String commandName, + String cannotMakeString, + @NotNull String shortDescription, + boolean checkReadOnlyStatus) { + addButtonToLowerPane(newPerformOperationRunnable(processRunnable, commandName, cannotMakeString, checkReadOnlyStatus), shortDescription); } public MyPerformOperationRunnable newPerformOperationRunnable(Runnable processRunnable, - String commandName, - String cannotMakeString) { - return new MyPerformOperationRunnable(cannotMakeString, processRunnable, commandName); + String commandName, + String cannotMakeString, boolean checkReadOnlyStatus) { + return new MyPerformOperationRunnable(cannotMakeString, processRunnable, commandName, checkReadOnlyStatus); } private boolean allTargetsAreValid() { @@ -1452,16 +1461,21 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra private final String myCannotMakeString; private final Runnable myProcessRunnable; private final String myCommandName; + private final boolean myCheckReadOnlyStatus; - private MyPerformOperationRunnable(final String cannotMakeString, final Runnable processRunnable, final String commandName) { + private MyPerformOperationRunnable(final String cannotMakeString, + final Runnable processRunnable, + final String commandName, + boolean checkReadOnlyStatus) { myCannotMakeString = cannotMakeString; myProcessRunnable = processRunnable; myCommandName = commandName; + myCheckReadOnlyStatus = checkReadOnlyStatus; } @Override public void run() { - if (!checkReadonlyUsages()) return; + if (myCheckReadOnlyStatus && !checkReadonlyUsages()) return; PsiDocumentManager.getInstance(myProject).commitAllDocuments(); if (myCannotMakeString != null && myChangesDetected) { String title = UsageViewBundle.message("changes.detected.error.title");