diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/refactoring')
5 files changed, 61 insertions, 11 deletions
diff --git a/platform/lang-impl/src/com/intellij/refactoring/actions/RefactoringQuickListPopupAction.java b/platform/lang-impl/src/com/intellij/refactoring/actions/RefactoringQuickListPopupAction.java index aea982678b9d..159279570cf2 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/actions/RefactoringQuickListPopupAction.java +++ b/platform/lang-impl/src/com/intellij/refactoring/actions/RefactoringQuickListPopupAction.java @@ -26,6 +26,10 @@ import org.jetbrains.annotations.Nullable; public class RefactoringQuickListPopupAction extends QuickSwitchSchemeAction { + public RefactoringQuickListPopupAction() { + setInjectedContext(true); + } + @Override protected void fillActions(@Nullable final Project project, @NotNull final DefaultActionGroup group, @@ -64,6 +68,7 @@ public class RefactoringQuickListPopupAction extends QuickSwitchSchemeAction { child instanceof CopyElementAction) { final Presentation presentation = new Presentation(); final AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, presentation, actionManager, 0); + event.setInjectedContext(child.isInInjectedContext()); child.update(event); if (presentation.isEnabled() && presentation.isVisible()) { destinationGroup.add(child); diff --git a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java index e761e9a3f2f3..81a2885c2022 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java @@ -45,6 +45,8 @@ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.RefactoringActionHandler; +import com.intellij.refactoring.listeners.RefactoringEventData; +import com.intellij.refactoring.listeners.RefactoringEventListener; import com.intellij.refactoring.rename.inplace.InplaceRefactoring; import com.intellij.ui.DottedBorder; import com.intellij.util.ui.PositionTracker; @@ -537,6 +539,13 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @Override public void run() { + final String refactoringId = getRefactoringId(); + if (refactoringId != null) { + final RefactoringEventData beforeData = new RefactoringEventData(); + beforeData.addElements(new PsiElement[] {getLocalVariable(), getExpr()}); + myProject.getMessageBus() + .syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(refactoringId, beforeData); + } performIntroduce(); } }, getCommandName(), getCommandName()); @@ -567,9 +576,20 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner } if (success) { performPostIntroduceTasks(); + final String refactoringId = getRefactoringId(); + if (refactoringId != null) { + final RefactoringEventData afterData = new RefactoringEventData(); + afterData.addElement(getVariable()); + myProject.getMessageBus() + .syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(refactoringId, afterData); + } } } + protected String getRefactoringId() { + return null; + } + @Override protected boolean startsOnTheSameElement(RefactoringActionHandler handler, PsiElement element) { return super.startsOnTheSameElement(handler, element) || getLocalVariable() == element; diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java index db30a105865a..aa4f696df179 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java @@ -773,32 +773,31 @@ public abstract class InplaceRefactoring { if (ApplicationManager.getApplication().isHeadlessEnvironment()) return; final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createDialogBalloonBuilder(component, null).setSmallVariant(true); myBalloon = balloonBuilder.createBalloon(); - final Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(myEditor); Disposer.register(myProject, myBalloon); Disposer.register(myBalloon, new Disposable() { @Override public void dispose() { releaseIfNotRestart(); - topLevelEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null); + myEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null); } }); - topLevelEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); + myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); final JBPopupFactory popupFactory = JBPopupFactory.getInstance(); - myBalloon.show(new PositionTracker<Balloon>(topLevelEditor.getContentComponent()) { + myBalloon.show(new PositionTracker<Balloon>(myEditor.getContentComponent()) { @Override public RelativePoint recalculateLocation(Balloon object) { - if (myTarget != null && !popupFactory.isBestPopupLocationVisible(topLevelEditor)) { + if (myTarget != null && !popupFactory.isBestPopupLocationVisible(myEditor)) { return myTarget; } if (myCaretRangeMarker != null && myCaretRangeMarker.isValid()) { - topLevelEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, - topLevelEditor.offsetToVisualPosition(myCaretRangeMarker.getStartOffset())); + myEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, + myEditor.offsetToVisualPosition(myCaretRangeMarker.getStartOffset())); } - final RelativePoint target = popupFactory.guessBestPopupLocation(topLevelEditor); + final RelativePoint target = popupFactory.guessBestPopupLocation(myEditor); final Point screenPoint = target.getScreenPoint(); int y = screenPoint.y; - if (target.getPoint().getY() > topLevelEditor.getLineHeight() + myBalloon.getPreferredSize().getHeight()) { - y -= topLevelEditor.getLineHeight(); + if (target.getPoint().getY() > myEditor.getLineHeight() + myBalloon.getPreferredSize().getHeight()) { + y -= myEditor.getLineHeight(); } myTarget = new RelativePoint(new Point(screenPoint.x, y)); return myTarget; diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java index bd3c52aac910..5e5907c83a07 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java @@ -177,6 +177,11 @@ public class MemberInplaceRenamer extends VariableInplaceRenamer { return false; } + @Override + protected String getRefactoringId() { + return null; + } + private void appendAdditionalElement(Collection<Pair<PsiElement, TextRange>> stringUsages, PsiNamedElement variable, PsiElement element) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java index 376561535a1e..6fa0ed27d8c8 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java @@ -38,6 +38,8 @@ import com.intellij.psi.util.PsiUtilCore; import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.listeners.RefactoringElementListener; +import com.intellij.refactoring.listeners.RefactoringEventData; +import com.intellij.refactoring.listeners.RefactoringEventListener; import com.intellij.refactoring.rename.*; import com.intellij.refactoring.rename.naming.AutomaticRenamer; import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory; @@ -137,6 +139,10 @@ public class VariableInplaceRenamer extends InplaceRefactoring { protected boolean shouldCreateSnapshot() { return true; } + + protected String getRefactoringId() { + return "refactoring.rename"; + } @Override protected void beforeTemplateStart() { @@ -204,11 +210,18 @@ public class VariableInplaceRenamer extends InplaceRefactoring { protected void performRefactoringRename(final String newName, final StartMarkAction markAction) { + final String refactoringId = getRefactoringId(); try { + PsiNamedElement elementToRename = getVariable(); + if (refactoringId != null) { + final RefactoringEventData beforeData = new RefactoringEventData(); + beforeData.addElement(elementToRename); + myProject.getMessageBus() + .syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(refactoringId, beforeData); + } if (!isIdentifier(newName, myLanguage)) { return; } - PsiNamedElement elementToRename = getVariable(); if (elementToRename != null) { new WriteCommandAction(myProject, getCommandName()) { @Override @@ -278,6 +291,14 @@ public class VariableInplaceRenamer extends InplaceRefactoring { } } finally { + + if (refactoringId != null) { + final RefactoringEventData afterData = new RefactoringEventData(); + afterData.addElement(getVariable()); + myProject.getMessageBus() + .syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(refactoringId, afterData); + } + try { ((EditorImpl)InjectedLanguageUtil.getTopLevelEditor(myEditor)).stopDumbLater(); } |