写在前面
本文看下如何在右键列表中增加菜单。
正戏
首先创建一个Action,要显示的menu选择ProjectViewPopupMenu
,如下:
- action
public class CAction extends AnAction {@Overridepublic void actionPerformed(AnActionEvent e) {
// Messages.showInfoMessage("右键点击了", "提示");ShowSettingsUtil.getInstance().editConfigurable(e.getProject(), new MyLeftMenuSettingsUI());}
}
- plugin.xml(注意是自动生成)
<action id="C" class="x.CAction" text="C" description="C"><add-to-group group-id="ProjectViewPopupMenu" anchor="first"/>
</action>
接着定义UI,注意要实现Configurable接口(这样才会有确定/取消按钮):
public class MyLeftMenuSettingsUI implements Configurable {private JPanel topPanel;@Overridepublic @Nls(capitalization = Nls.Capitalization.Title) String getDisplayName() {return "右键设置";}@Overridepublic @Nullable JComponent createComponent() {return topPanel;}@Overridepublic boolean isModified() {return true;}/*** 确定时调用* @throws ConfigurationException*/@Overridepublic void apply() throws ConfigurationException {}
}
然后运行测试: