mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +08:00
[code] Project roots illustration
This commit is contained in:
parent
920a40de1e
commit
2aea928ffa
@ -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>
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user