1.22 Chang PopupMenu And Add Copy ClassName.MethodName | 调整 右键菜单 并增加菜单项:复制 类名.方法名 Fixed #8

This commit is contained in:
林万程
2022-08-09 00:41:23 +08:00
parent 225c0a2ef7
commit 7fa464855a
4 changed files with 65 additions and 19 deletions

View File

@@ -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;
}
}

View File

@@ -8,7 +8,7 @@
<ul>
<li>Show javadoc comments at the Project view Tree structure
<li>Show javadoc comments at the end-of-line
<li>Show javadoc comments at "xx ClassNameOrSimpleName.json" and jump to field
<li>Show javadoc comments at "xx-ClassNameOrSimpleName.json" and jump to field
<li>Show comments from External Conf for folder, resources, COBOL etc.
<li>Config: settings -> Tools -> // Show Comment Global/Project
</ul>
@@ -31,7 +31,7 @@
<ul>
<li>在结构树显示 文档注释
<li>在行末尾显示 文档注释
<li>支持 "xx 类全名或简名.json" 文档注释与跳转到字段
<li>支持 "xx-类全名或简名.json" 文档注释与跳转到字段
<li>支持 从配置文件获取外部注释用于文件夹、资源、COBOL 等
<li>修改配置:设置 -> 工具 -> // Show Comment Global/Project
</ul>
@@ -106,13 +106,21 @@
id="io.github.linwancen.plugin.show.LineEndCopy"
class="io.github.linwancen.plugin.show.LineEndCopy"
text="// Copy With Line Comment">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
<add-to-group group-id="EditorPopupMenu" anchor="after"
relative-to-action="CopyReference"/>
</action>
<action
id="io.github.linwancen.plugin.show.CopyReferenceSimple"
class="io.github.linwancen.plugin.show.CopyReferenceSimple"
text="Copy ClassName.MethodName">
<add-to-group group-id="EditorPopupMenu" anchor="after"
relative-to-action="CopyReference"/>
</action>
<action
id="io.github.linwancen.plugin.show.LineEndAdd"
class="io.github.linwancen.plugin.show.LineEndAdd"
text="// Add Line Comment">
<add-to-group group-id="ProjectViewPopupMenu" anchor="first"/>
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
</action>
</actions>
</idea-plugin>