perform refactoring from preview: do not check writable twice; correct writable usages set (IDEA-97458)

This commit is contained in:
anna
2012-12-19 13:38:04 +01:00
parent cb279e7b3f
commit 0f5072ee16
3 changed files with 29 additions and 9 deletions
@@ -397,8 +397,9 @@ public abstract class BaseRefactoringProcessor {
@Override
public void run() {
Set<UsageInfo> 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<UsageInfo> getUsageInfosToRefactor(final UsageView usageView) {
@@ -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
@@ -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");