This commit is contained in:
Alexey Kudravtsev
2017-03-30 18:44:16 +03:00
parent 19407dd636
commit 61528a9e14
2 changed files with 36 additions and 48 deletions
@@ -66,8 +66,6 @@ import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import java.awt.*;
@@ -142,12 +140,12 @@ public class IntentionHintComponent implements Disposable, ScrollAwareHint {
}
@NotNull
public static IntentionHintComponent showIntentionHint(@NotNull final Project project,
@NotNull PsiFile file,
@NotNull final Editor editor,
@NotNull ShowIntentionsPass.IntentionsInfo intentions,
boolean showExpanded,
@NotNull Point position) {
private static IntentionHintComponent showIntentionHint(@NotNull final Project project,
@NotNull PsiFile file,
@NotNull final Editor editor,
@NotNull ShowIntentionsPass.IntentionsInfo intentions,
boolean showExpanded,
@NotNull Point position) {
ApplicationManager.getApplication().assertIsDispatchThread();
final IntentionHintComponent component = new IntentionHintComponent(project, file, editor, intentions);
@@ -466,31 +464,28 @@ public class IntentionHintComponent implements Disposable, ScrollAwareHint {
myPopupShown = false;
}
});
myPopup.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(@NotNull ListSelectionEvent e) {
final Object source = e.getSource();
highlighter.dropHighlight();
injectionHighlighter.dropHighlight();
if (source instanceof DataProvider) {
final Object selectedItem = PlatformDataKeys.SELECTED_ITEM.getData((DataProvider)source);
if (selectedItem instanceof IntentionActionWithTextCaching) {
final IntentionAction action = ((IntentionActionWithTextCaching)selectedItem).getAction();
if (action instanceof SuppressIntentionActionFromFix) {
if (injectedFile != null && ((SuppressIntentionActionFromFix)action).isShouldBeAppliedToInjectionHost() == ThreeState.NO) {
final PsiElement at = injectedFile.findElementAt(injectedEditor.getCaretModel().getOffset());
final PsiElement container = ((SuppressIntentionActionFromFix)action).getContainer(at);
if (container != null) {
injectionHighlighter.highlight(container, Collections.singletonList(container));
}
myPopup.addListSelectionListener(e -> {
final Object source = e.getSource();
highlighter.dropHighlight();
injectionHighlighter.dropHighlight();
if (source instanceof DataProvider) {
final Object selectedItem = PlatformDataKeys.SELECTED_ITEM.getData((DataProvider)source);
if (selectedItem instanceof IntentionActionWithTextCaching) {
final IntentionAction action = ((IntentionActionWithTextCaching)selectedItem).getAction();
if (action instanceof SuppressIntentionActionFromFix) {
if (injectedFile != null && ((SuppressIntentionActionFromFix)action).isShouldBeAppliedToInjectionHost() == ThreeState.NO) {
final PsiElement at = injectedFile.findElementAt(injectedEditor.getCaretModel().getOffset());
final PsiElement container = ((SuppressIntentionActionFromFix)action).getContainer(at);
if (container != null) {
injectionHighlighter.highlight(container, Collections.singletonList(container));
}
else {
final PsiElement at = myFile.findElementAt(myEditor.getCaretModel().getOffset());
final PsiElement container = ((SuppressIntentionActionFromFix)action).getContainer(at);
if (container != null) {
highlighter.highlight(container, Collections.singletonList(container));
}
}
else {
final PsiElement at = myFile.findElementAt(myEditor.getCaretModel().getOffset());
final PsiElement container = ((SuppressIntentionActionFromFix)action).getContainer(at);
if (container != null) {
highlighter.highlight(container, Collections.singletonList(container));
}
}
}
@@ -515,12 +510,7 @@ public class IntentionHintComponent implements Disposable, ScrollAwareHint {
}
Disposer.register(this, myPopup);
Disposer.register(myPopup, new Disposable() {
@Override
public void dispose() {
ApplicationManager.getApplication().assertIsDispatchThread();
}
});
Disposer.register(myPopup, ApplicationManager.getApplication()::assertIsDispatchThread);
}
void canceled(@NotNull ListPopupStep intentionListStep) {
@@ -592,9 +582,7 @@ public class IntentionHintComponent implements Disposable, ScrollAwareHint {
@Override
@NotNull
public String getText() {
return mySettings.isEnabled(myAction) ?
CodeInsightBundle.message("disable.intention.action", myFamilyName) :
CodeInsightBundle.message("enable.intention.action", myFamilyName);
return CodeInsightBundle.message(mySettings.isEnabled(myAction) ? "disable.intention.action" : "enable.intention.action", myFamilyName);
}
@Override
@@ -100,12 +100,12 @@ public class IntentionListStep implements ListPopupStep<IntentionActionWithTextC
}
//true if something changed
boolean wrapAndUpdateActions(@NotNull ShowIntentionsPass.IntentionsInfo intentions, boolean callUpdate) {
boolean changed = wrapActionsTo(intentions.errorFixesToShow, myCachedErrorFixes, callUpdate);
changed |= wrapActionsTo(intentions.inspectionFixesToShow, myCachedInspectionFixes, callUpdate);
changed |= wrapActionsTo(intentions.intentionsToShow, myCachedIntentions, callUpdate);
changed |= wrapActionsTo(intentions.guttersToShow, myCachedGutters, callUpdate);
changed |= wrapActionsTo(intentions.notificationActionsToShow, myCachedNotifications, callUpdate);
boolean wrapAndUpdateActions(@NotNull ShowIntentionsPass.IntentionsInfo newInfo, boolean callUpdate) {
boolean changed = wrapActionsTo(newInfo.errorFixesToShow, myCachedErrorFixes, callUpdate);
changed |= wrapActionsTo(newInfo.inspectionFixesToShow, myCachedInspectionFixes, callUpdate);
changed |= wrapActionsTo(newInfo.intentionsToShow, myCachedIntentions, callUpdate);
changed |= wrapActionsTo(newInfo.guttersToShow, myCachedGutters, callUpdate);
changed |= wrapActionsTo(newInfo.notificationActionsToShow, myCachedNotifications, callUpdate);
return changed;
}
@@ -254,7 +254,7 @@ public class IntentionListStep implements ListPopupStep<IntentionActionWithTextC
return myFinalRunnable;
}
private void applyAction(final IntentionActionWithTextCaching cachedAction) {
private void applyAction(@NotNull IntentionActionWithTextCaching cachedAction) {
myFinalRunnable = () -> {
HintManager.getInstance().hideAllHints();
if (myProject.isDisposed() || myEditor != null && myEditor.isDisposed()) return;