SHOW:
|
|
- or go back to the newest paste.
| 1 | import com.intellij.openapi.actionSystem.AnAction; | |
| 2 | import com.intellij.openapi.actionSystem.AnActionEvent; | |
| 3 | import com.intellij.openapi.actionSystem.CommonDataKeys; | |
| 4 | import com.intellij.openapi.compiler.CompilerManager; | |
| 5 | import com.intellij.openapi.module.Module; | |
| 6 | import com.intellij.openapi.module.ModuleManager; | |
| 7 | import com.intellij.openapi.project.Project; | |
| 8 | import com.intellij.openapi.roots.ProjectRootManager; | |
| 9 | import com.intellij.openapi.vfs.VirtualFile; | |
| 10 | import com.intellij.psi.PsiDocumentManager; | |
| 11 | import com.intellij.psi.PsiFile; | |
| 12 | ||
| 13 | public class CompileAction extends AnAction {
| |
| 14 | ||
| 15 | @Override | |
| 16 | public void update(AnActionEvent e) {
| |
| 17 | Project project = e.getProject(); | |
| 18 | e.getPresentation().setEnabledAndVisible(project != null); | |
| 19 | } | |
| 20 | ||
| 21 | @Override | |
| 22 | public void actionPerformed(AnActionEvent e) {
| |
| 23 | Project project = e.getProject(); | |
| 24 | ||
| 25 | - | CompilerManager compilerManager = CompilerManager.getInstance(e.getProject()); |
| 25 | + | |
| 26 | PsiFile psiFile = psiDocumentManager.getPsiFile(e.getData(CommonDataKeys.EDITOR).getDocument()); | |
| 27 | VirtualFile virtualFile = psiFile.getVirtualFile(); | |
| 28 | Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(virtualFile); | |
| 29 | ||
| 30 | CompilerManager compilerManager = CompilerManager.getInstance(project); | |
| 31 | compilerManager.compile(module, null); | |
| 32 | ||
| 33 | // Get the Base Dir and refresh with the following parameters | |
| 34 | // 'asynchronous' set to false and 'recursive' set to true | |
| 35 | // project.getBaseDir().refresh(false,true); | |
| 36 | - | project.getBaseDir().refresh(false,true); |
| 36 | + | |
| 37 | } | |
| 38 | - | } |
| 38 | + | |
| 39 | ||
| 40 | ||
| 41 | // ================== in plugin.xml: | |
| 42 | /* | |
| 43 | <actions> | |
| 44 | <!-- Add your actions here --> | |
| 45 | <action class="CompileAction" | |
| 46 | id="CompileActionID" | |
| 47 | text="Compile Module" | |
| 48 | description="Compiles all files in the module"> | |
| 49 | <add-to-group group-id="EditorPopupMenu" anchor="first"/> | |
| 50 | </action> | |
| 51 | </actions> | |
| 52 | */ |