mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
collapse gutter intentions
This commit is contained in:
@@ -15,27 +15,39 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.ShowIntentionsPass;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class GutterIntentionsTest extends LightPlatformCodeInsightFixtureTestCase {
|
||||
public class GutterIntentionsTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testEmptyIntentions() throws Exception {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, "class Foo {\n" +
|
||||
" <caret> private String test() {\n" +
|
||||
" return null;\n" +
|
||||
" }");
|
||||
" }" +
|
||||
"}");
|
||||
myFixture.findAllGutters();
|
||||
List<IntentionAction> intentions = myFixture.getAvailableIntentions();
|
||||
assertEmpty(intentions);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isWriteActionRequired() {
|
||||
return false;
|
||||
public void testOptions() throws Exception {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, "public class Foo {\n" +
|
||||
" public static void <caret>main(String[] args) {}" +
|
||||
"}");
|
||||
assertEquals(1, myFixture.findGuttersAtCaret().size());
|
||||
|
||||
ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
|
||||
ShowIntentionsPass.getActionsToShow(getEditor(), getFile(), intentions, -1);
|
||||
assertEquals(1, intentions.guttersToShow.size());
|
||||
List<IntentionAction> options = intentions.guttersToShow.get(0).getOptions(myFixture.getElementAtCaret(), getEditor());
|
||||
assertNotNull(options);
|
||||
assertNotEmpty(options);
|
||||
}
|
||||
}
|
||||
|
||||
+35
-8
@@ -26,30 +26,36 @@ import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
class GutterIntentionAction extends AbstractIntentionAction implements Comparable<IntentionAction> {
|
||||
class GutterIntentionAction extends AbstractIntentionAction implements Comparable<IntentionAction>, Iconable {
|
||||
private final AnAction myAction;
|
||||
private final int myOrder;
|
||||
private final Icon myIcon;
|
||||
private String myText;
|
||||
|
||||
private GutterIntentionAction(AnAction action, int order) {
|
||||
private GutterIntentionAction(AnAction action, int order, Icon icon) {
|
||||
myAction = action;
|
||||
myOrder = order;
|
||||
myIcon = icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,10 +102,26 @@ class GutterIntentionAction extends AbstractIntentionAction implements Comparabl
|
||||
if (renderer == null || DumbService.isDumb(project) && !DumbService.isDumbAware(renderer)) {
|
||||
return;
|
||||
}
|
||||
addActions(project, editor, psiFile, renderer.getClickAction(), descriptors, renderer, 0);
|
||||
addActions(project, editor, psiFile, renderer.getMiddleButtonClickAction(), descriptors, renderer, 0);
|
||||
addActions(project, editor, psiFile, renderer.getRightButtonClickAction(), descriptors, renderer, 0);
|
||||
addActions(project, editor, psiFile, renderer.getPopupMenuActions(), descriptors, renderer, 0);
|
||||
List<HighlightInfo.IntentionActionDescriptor> list = new ArrayList<HighlightInfo.IntentionActionDescriptor>();
|
||||
addActions(project, editor, psiFile, renderer.getClickAction(), list, renderer, 0);
|
||||
addActions(project, editor, psiFile, renderer.getMiddleButtonClickAction(), list, renderer, 0);
|
||||
addActions(project, editor, psiFile, renderer.getRightButtonClickAction(), list, renderer, 0);
|
||||
addActions(project, editor, psiFile, renderer.getPopupMenuActions(), list, renderer, 0);
|
||||
if (list.isEmpty()) return;
|
||||
if (list.size() == 1) {
|
||||
descriptors.addAll(list);
|
||||
}
|
||||
else {
|
||||
HighlightInfo.IntentionActionDescriptor first = list.get(0);
|
||||
List<IntentionAction> options = ContainerUtil.map(list.subList(1, list.size()),
|
||||
new Function<HighlightInfo.IntentionActionDescriptor, IntentionAction>() {
|
||||
@Override
|
||||
public IntentionAction fun(HighlightInfo.IntentionActionDescriptor descriptor) {
|
||||
return descriptor.getAction();
|
||||
}
|
||||
});
|
||||
descriptors.add(new HighlightInfo.IntentionActionDescriptor(first.getAction(), options, first.getDisplayName(), first.getIcon()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void addActions(@NotNull Project project,
|
||||
@@ -119,11 +141,11 @@ class GutterIntentionAction extends AbstractIntentionAction implements Comparabl
|
||||
addActions(project, editor, psiFile, child, descriptors, renderer, i + order);
|
||||
}
|
||||
}
|
||||
final IntentionAction gutterAction = new GutterIntentionAction(action, order);
|
||||
if (!gutterAction.isAvailable(project, editor, psiFile)) return;
|
||||
Icon icon = action.getTemplatePresentation().getIcon();
|
||||
if (icon == null) icon = renderer.getIcon();
|
||||
if (icon.getIconWidth() < 16) icon = IconUtil.toSize(icon, 16, 16);
|
||||
final IntentionAction gutterAction = new GutterIntentionAction(action, order, icon);
|
||||
if (!gutterAction.isAvailable(project, editor, psiFile)) return;
|
||||
HighlightInfo.IntentionActionDescriptor descriptor =
|
||||
new HighlightInfo.IntentionActionDescriptor(gutterAction, Collections.<IntentionAction>emptyList(), null, icon) {
|
||||
@Nullable
|
||||
@@ -143,4 +165,9 @@ class GutterIntentionAction extends AbstractIntentionAction implements Comparabl
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(@IconFlags int flags) {
|
||||
return myIcon;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user