GutterIconNavigationHandler Right Click not work

已回答

I am trying to create RelatedItemLineMarkerInfo instance with its constructor, using custom MyGutterIconHandler like belows:

static class MyGutterIconHandler implements GutterIconNavigationHandler<PsiElement> {
    @Override
    public void navigate(MouseEvent mouseEvent, PsiElement element) {
        System.out.println(mouseEvent.getButton());
        if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
           // do something... 
        } else if (mouseEvent.getButton() == MouseEvent.BUTTON2) {
           // do something...                      
        } else if (mouseEvent.getButton() == MouseEvent.BUTTON3) {
           // do something...                      
        }
    }
}

when i click the mouse with the primary button, it works fine, but when i right clicked, failed. it seems that when i right click the mouse, the navigate method is not called.

 

this is my intellij platform sdk version in build.gradle.kts

plugins {
   java  // jdk8
    kotlin("jvm") version "1.4.32"
    id("org.jetbrains.intellij") version "0.7.2"
}

thanks for your help.

0

i find a way to meet my needs. here is an example:

public class MapperLineMarkerInfo extends LineMarkerInfo<PsiElement> {

    @Override
    public GutterIconRenderer createGutterRenderer() {
        return new MyGutterIconRenderer();
    }


	...
}

 

public class MyGutterIconRenderer extends LineMarkerInfo.LineMarkerGutterIconRenderer<PsiElement> {

	// left click trigger
	@Override
    public @Nullable AnAction getClickAction() {
    	return new AnAction() {
    	        @Override
                public void actionPerformed(@NotNull AnActionEvent event) {
                	// do something
                }
    	}
    }
    
    // right click trigger
    @Override
    public @Nullable AnAction getRightButtonClickAction() {
    	return new AnAction() {
    	        @Override
                public void actionPerformed(@NotNull AnActionEvent event) {
                	// do something
                }
    	}
    }
}

 

1

请先登录再写评论。