[code] Project roots illustration

This commit is contained in:
Anna Bulenkova 2014-12-15 12:55:26 +01:00
parent 920a40de1e
commit 2aea928ffa
2 changed files with 37 additions and 1 deletions

View File

@ -25,6 +25,9 @@
</project-components>
<actions>
<!--Add your actions here-->
<action id="ProjectModel.SourceRoots" class="com.intellij.plugins.project.model.ShowSourceRootsActions" text="Show Source Roots"
description="Illustrates how to get source roots">
<add-to-group group-id="ToolsMenu" anchor="after"/>
</action>
</actions>
</idea-plugin>

View File

@ -0,0 +1,33 @@
package com.intellij.plugins.project.model;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
/**
* @author Anna Bulenkova
*/
public class ShowSourceRootsActions extends AnAction {
@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
Project project = anActionEvent.getProject();
if (project == null) return;
String projectName = project.getName();
StringBuilder sourceRootsList = new StringBuilder();
VirtualFile[] vFiles = ProjectRootManager.getInstance(project).getContentSourceRoots();
for (VirtualFile file : vFiles) {
sourceRootsList.append(file.getUrl()).append("\n");
}
Messages.showInfoMessage("Source roots for the " + projectName + " plugin:\n" + sourceRootsList, "Project Properties");
}
@Override
public void update(final AnActionEvent e) {
boolean visibility = e.getProject() != null;
e.getPresentation().setEnabled(visibility);
e.getPresentation().setVisible(visibility);
}
}