mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +08:00
[code] Project sdk sample
This commit is contained in:
parent
f1020ad145
commit
e4fdb48ae6
@ -29,6 +29,10 @@
|
||||
description="Illustrates how to get source roots">
|
||||
<add-to-group group-id="ToolsMenu" anchor="after"/>
|
||||
</action>
|
||||
<action id="ProjectModel.ProjectSdk" class="com.intellij.plugins.project.model.ProjectSdkAction" text="Show Sdk Info"
|
||||
description="Illustrates how to get source roots">
|
||||
<add-to-group group-id="ToolsMenu" anchor="after"/>
|
||||
</action>
|
||||
<action id="ProjectModel.ProjectFileIndex" class="com.intellij.plugins.project.model.ProjectFileIndexSampleAction" text="FileProjectIndex in Action"
|
||||
description="Illustrates how to get source roots">
|
||||
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
|
||||
|
@ -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.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
|
||||
/**
|
||||
* @author Anna Bulenkova
|
||||
*/
|
||||
public class ProjectSdkAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project != null) {
|
||||
String projectSDKName = ProjectRootManager.getInstance(project).getProjectSdkName();
|
||||
String newProjectSdkName = "New Sdk Name";
|
||||
ProjectRootManager.getInstance(project).setProjectSdkName(newProjectSdkName);
|
||||
Messages.showInfoMessage(projectSDKName + " has changed to " + newProjectSdkName, "Project Sdk Info");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(final AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project != null) {
|
||||
Sdk sdk = ProjectRootManager.getInstance(project).getProjectSdk();
|
||||
e.getPresentation().setEnabledAndVisible(sdk != null);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user