通知
1、通知消息

import com.intellij.notification.Notification;import com.intellij.notification.NotificationDisplayType;import com.intellij.notification.NotificationGroup;import com.intellij.notification.Notifications;import com.intellij.openapi.actionSystem.AnAction;import com.intellij.openapi.actionSystem.AnActionEvent;import com.intellij.openapi.actionSystem.PlatformDataKeys;import com.intellij.openapi.project.Project;import com.intellij.openapi.ui.MessageType;import com.intellij.openapi.ui.Messages;public class TestAction extends AnAction {@Overridepublic void actionPerformed(AnActionEvent event) {NotificationGroup notificationGroup = new NotificationGroup("testid", NotificationDisplayType.BALLOON, false);/*** content : 通知内容* type :通知的类型,warning,info,error*/Notification notification = notificationGroup.createNotification("测试通知", MessageType.INFO);Notifications.Bus.notify(notification);}}
2、弹框通知

import com.intellij.notification.Notification;import com.intellij.notification.NotificationDisplayType;import com.intellij.notification.NotificationGroup;import com.intellij.notification.Notifications;import com.intellij.openapi.actionSystem.AnAction;import com.intellij.openapi.actionSystem.AnActionEvent;import com.intellij.openapi.actionSystem.PlatformDataKeys;import com.intellij.openapi.project.Project;import com.intellij.openapi.ui.MessageType;import com.intellij.openapi.ui.Messages;public class TestAction extends AnAction {@Overridepublic void actionPerformed(AnActionEvent event) {// 弹窗显示消息Messages.showMessageDialog("Hello world", "ShuoGG Say", Messages.getInformationIcon());}}
右键菜单事件
得到选中的文字

import com.intellij.openapi.actionSystem.AnAction;import com.intellij.openapi.actionSystem.AnActionEvent;import com.intellij.openapi.actionSystem.CommonDataKeys;import com.intellij.openapi.editor.Editor;import com.intellij.openapi.editor.SelectionModel;public class TestAction extends AnAction {@Overridepublic void actionPerformed(AnActionEvent event) {// TODO: insert action logic hereEditor editor = event.getRequiredData(CommonDataKeys.EDITOR);SelectionModel model = editor.getSelectionModel();String text = model.getSelectedText();System.out.println(text);}}
注意:添加的组有变化EditorPopupMenu
<!-- 编写插件动作 --><actions><!-- Add your actions here --><action id="test_id" class="com.kakaluote.action.TestAction" text="通知" description="测试通知的功能"><add-to-group group-id="EditorPopupMenu" anchor="first"/></action></actions>
