SetUpJSModuleAction puts library jar under "lib" directory. Set up kotlin runtime notification suggests setting up JS module as well as JVM.
This commit is contained in:
@@ -27,6 +27,7 @@ import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.plugin.k2jsrun.K2JSRunnerUtils;
|
||||
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
@@ -42,7 +43,13 @@ import static org.jetbrains.jet.plugin.k2jsrun.K2JSRunnerUtils.copyFileToDir;
|
||||
public final class SetUpJsModuleAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent event) {
|
||||
Project project = event.getProject();
|
||||
if (event == null) {
|
||||
return;
|
||||
}
|
||||
doSetUpModule(event.getProject());
|
||||
}
|
||||
|
||||
public static void doSetUpModule(@Nullable Project project) {
|
||||
if (project == null) {
|
||||
notifyFailure("Internal error: Project not found.");
|
||||
return;
|
||||
@@ -74,12 +81,12 @@ public final class SetUpJsModuleAction extends AnAction {
|
||||
}
|
||||
|
||||
private static void refreshRootDir(@NotNull Project project) {
|
||||
getContentRoot(project).refresh(true, false);
|
||||
getContentRoot(project).refresh(false, false);
|
||||
}
|
||||
|
||||
private static void createIndicationFile(@NotNull File file) {
|
||||
try {
|
||||
FileUtil.writeToFile(file, PathUtil.JS_LIB_JAR_NAME);
|
||||
FileUtil.writeToFile(file, "lib/" + PathUtil.JS_LIB_JAR_NAME);
|
||||
}
|
||||
catch (IOException e) {
|
||||
notifyFailure("Failed to write file " + file.getName());
|
||||
@@ -88,7 +95,7 @@ public final class SetUpJsModuleAction extends AnAction {
|
||||
|
||||
private static boolean copyJsLib(@NotNull File jsLibPath, @NotNull File rootDir) {
|
||||
try {
|
||||
copyFileToDir(jsLibPath, rootDir);
|
||||
copyFileToDir(jsLibPath, new File(rootDir, "lib"));
|
||||
}
|
||||
catch (IOException e) {
|
||||
notifyFailure("Failed to copy file: " + e.getMessage());
|
||||
|
||||
+44
-25
@@ -50,14 +50,14 @@ import com.intellij.ui.EditorNotificationPanel;
|
||||
import com.intellij.ui.EditorNotifications;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
||||
import org.jetbrains.jet.plugin.actions.SetUpJsModuleAction;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.jetbrains.jet.plugin.project.JsModuleDetector.*;
|
||||
import static org.jetbrains.jet.plugin.project.JsModuleDetector.isJsProject;
|
||||
|
||||
public class ConfigureKotlinLibraryNotificationProvider implements EditorNotifications.Provider<EditorNotificationPanel> {
|
||||
private static final Key<EditorNotificationPanel> KEY = Key.create("configure.kotlin.library");
|
||||
@@ -155,36 +155,55 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific
|
||||
private EditorNotificationPanel createNotificationPanel(final Module module) {
|
||||
final EditorNotificationPanel answer = new EditorNotificationPanel();
|
||||
|
||||
answer.setText("Kotlin runtime library is not configured for module '" + module.getName() + "'");
|
||||
answer.createActionLabel("Setup Kotlin Runtime", new Runnable() {
|
||||
answer.setText("Kotlin is not configured for module '" + module.getName() + "'");
|
||||
answer.createActionLabel("Set Up module '" + module.getName() + "' as JVM Kotlin module", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setUpKotlinRuntime(module);
|
||||
}
|
||||
});
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Library library = findOrCreateRuntimeLibrary(module);
|
||||
if (library != null) {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
if (model.findLibraryOrderEntry(library) == null) {
|
||||
model.addLibraryEntry(library);
|
||||
model.commit();
|
||||
}
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EditorNotifications.getInstance(myProject).updateAllNotifications();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
answer.createActionLabel("Set Up module '" + module.getName() + "' as JavaScript Kotlin module", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setUpJSModule(module);
|
||||
}
|
||||
});
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
private void setUpJSModule(@NotNull Module module) {
|
||||
SetUpJsModuleAction.doSetUpModule(module.getProject());
|
||||
updateNotifications();
|
||||
}
|
||||
|
||||
private void setUpKotlinRuntime(@NotNull final Module module) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Library library = findOrCreateRuntimeLibrary(module);
|
||||
if (library != null) {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
if (model.findLibraryOrderEntry(library) == null) {
|
||||
model.addLibraryEntry(library);
|
||||
model.commit();
|
||||
}
|
||||
updateNotifications();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateNotifications() {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EditorNotifications.getInstance(myProject).updateAllNotifications();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isMavenModule(@NotNull Module module) {
|
||||
for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) {
|
||||
if (root.findChild("pom.xml") != null) return true;
|
||||
@@ -200,7 +219,7 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific
|
||||
protected ChoosePathDialog(Project project) {
|
||||
super(project);
|
||||
myProject = project;
|
||||
|
||||
|
||||
setTitle("Local Kotlin Runtime Path");
|
||||
init();
|
||||
}
|
||||
@@ -220,7 +239,7 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific
|
||||
|
||||
return myPathField;
|
||||
}
|
||||
|
||||
|
||||
public String getPath() {
|
||||
return myPathField.getText();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user