During the process of using Android Studio, I found that some of the plug-ins included could not meet the actual needs of the project, so I started to develop the corresponding plug-ins myself. Below is a record of my development plug-in process and will continue to share it with you.
Share 1: Create Project Right-click Menu
1. Follow the project wizard to create a demo project step by step, and I won’t introduce it anymore. You can refer to this article //www.VeVB.COM/article/135535.htm
2. Create Action, you will see in the plugin configuration file
<action id="FirstAction" text="FirstAction" description="right-click Action"> <add-to-group group-id="ProjectViewPopupMenu" anchor="after" relative-to-action="ReplaceInPath"/> </action>
3. After running, the IDE will open another IDE (wrapped by a container similar to Genymotion). It depends on whether the effect is very familiar. Yes, this is the commonly used Project right-click menu:
4. Dynamically control the hidden display of Action according to the triggered file type
@Override public void update(AnActionEvent event) {//Show hide this Action String extension = getFileExtension(event.getDataContext()); this.getTemplatePresentation().setEnabled(extension != null && "jar".equals(extension)); }Complete code:
import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vfs.VirtualFile; /** * Created by ABC on 16/8/17. */ public class FirstAction extends AnAction { private Project mProject; @Override public void actionPerformed(AnActionEvent event) { mProject = event.getData(PlatformDataKeys.PROJECT); DataContext dataContext = event.getDataContext(); if ("jar".equals(getFileExtension(dataContext)))) {//Defend the following processing based on the extension//Get the selected file VirtualFile file = DataKeys.VIRTUAL_FILE.getData(event.getDataContext()); if (file != null) { Messages.showMessageDialog(mProject, file.getName(), "select file", Messages.getInformationIcon()); } } } @Override public void update(AnActionEvent event) { //Before the Action is displayed, determine whether this Action is displayed based on the selected file extension. String extension = getFileExtension(event.getDataContext()); this.getTemplatePresentation().setEnabled(extension != null && "jar".equals(extension)); } public static String getFileExtension(DataContext dataContext) { VirtualFile file = DataKeys.VIRTUAL_FILE.getData(dataContext); return file == null ? null : file.getExtension(); } }The above is all the content of this article. I hope it will be helpful to everyone's learning. I also hope that everyone will support Wulin.com more