1.22 Chang PopupMenu And Add Copy ClassName.MethodName | 调整 右键菜单 并增加菜单项:复制 类名.方法名 Fixed #8
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package io.github.linwancen.plugin.show;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.actions.CopyReferenceAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CopyReferenceSimple extends CopyReferenceAction {
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
super.update(e);
|
||||
String tip = IdeBundle.message("copy.reference");
|
||||
if (tip != null && tip.replace("\u001B", "").equals(e.getPresentation().getText())) {
|
||||
e.getPresentation().setText("Copy ClassName.MethodName");
|
||||
}
|
||||
}
|
||||
|
||||
private static final Pattern QUALIFIED_PATTERN = Pattern.compile("[\\w.]+\\.");
|
||||
|
||||
protected String getQualifiedName(Editor editor, List<PsiElement> elements) {
|
||||
String qualifiedName = super.getQualifiedName(editor, elements);
|
||||
int i = qualifiedName.indexOf("(");
|
||||
if (i > 0) {
|
||||
return QUALIFIED_PATTERN.matcher(qualifiedName).replaceAll("").replace('#', '.');
|
||||
}
|
||||
i = qualifiedName.lastIndexOf(".");
|
||||
if (i > 0) {
|
||||
return qualifiedName.substring(i + 1).replace('#', '.');
|
||||
}
|
||||
return qualifiedName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user