Some improvements in configurators
This commit is contained in:
+43
-23
@@ -89,32 +89,49 @@ public class ConfigureKotlinInProjectUtils {
|
||||
}
|
||||
|
||||
private static void showConfigureKotlinNotification(final Project project) {
|
||||
Collection<KotlinProjectConfigurator> configurators = getApplicableConfigurators(project);
|
||||
|
||||
String links = StringUtil.join(configurators, new Function<KotlinProjectConfigurator, String>() {
|
||||
@Override
|
||||
public String fun(KotlinProjectConfigurator configurator) {
|
||||
return getLink(configurator);
|
||||
}
|
||||
}, " ");
|
||||
|
||||
Notifications.Bus.notify(
|
||||
new Notification("Configure Kotlin",
|
||||
"Kotlin file(s) found in your project.",
|
||||
"Configure Kotlin:\n" + links,
|
||||
NotificationType.ERROR, new NotificationListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
|
||||
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
||||
KotlinProjectConfigurator configurator = getConfiguratorByName(event.getDescription());
|
||||
if (configurator == null) {
|
||||
throw new AssertionError("Missed action: " + event.getDescription());
|
||||
getNotificationString(project),
|
||||
NotificationType.WARNING, new NotificationListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
|
||||
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
||||
KotlinProjectConfigurator configurator = getConfiguratorByName(event.getDescription());
|
||||
if (configurator == null) {
|
||||
throw new AssertionError("Missed action: " + event.getDescription());
|
||||
}
|
||||
configurator.configure(project);
|
||||
notification.expire();
|
||||
}
|
||||
}
|
||||
configurator.configure(project);
|
||||
notification.expire();
|
||||
}
|
||||
}), project);
|
||||
}
|
||||
|
||||
private static String getNotificationString(Project project) {
|
||||
StringBuilder builder = new StringBuilder("Configure ");
|
||||
|
||||
Collection<Module> modules = getModulesWithKotlinFiles(project);
|
||||
final boolean isOnlyOneModule = modules.size() == 1;
|
||||
if (isOnlyOneModule) {
|
||||
builder.append("'").append(modules.iterator().next().getName()).append("' module");
|
||||
}
|
||||
else {
|
||||
builder.append("modules");
|
||||
}
|
||||
|
||||
builder.append(" in '").append(project.getName()).append("' project");
|
||||
builder.append("\n");
|
||||
|
||||
String links = StringUtil.join(getApplicableConfigurators(project), new Function<KotlinProjectConfigurator, String>() {
|
||||
@Override
|
||||
public String fun(KotlinProjectConfigurator configurator) {
|
||||
return getLink(configurator, isOnlyOneModule);
|
||||
}
|
||||
}), project);
|
||||
}, " ");
|
||||
builder.append(links);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -162,8 +179,11 @@ public class ConfigureKotlinInProjectUtils {
|
||||
return result;
|
||||
}
|
||||
@NotNull
|
||||
public static String getLink(@NotNull KotlinProjectConfigurator configurator) {
|
||||
return StringUtil.join("<a href=\"", configurator.getName(), "\">", configurator.getPresentableText(), "</a>");
|
||||
public static String getLink(@NotNull KotlinProjectConfigurator configurator, boolean isOnlyOneModule) {
|
||||
return StringUtil.join("<a href=\"", configurator.getName(), "\">as Kotlin (",
|
||||
configurator.getPresentableText(),
|
||||
isOnlyOneModule ? ") module" : ") modules",
|
||||
"</a>");
|
||||
}
|
||||
|
||||
private ConfigureKotlinInProjectUtils() {
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ public class KotlinAndroidGradleModuleConfigurator extends KotlinWithGradleConfi
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return "As Android project with Gradle";
|
||||
return "Android with Gradle";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,7 @@ public class KotlinGradleModuleConfigurator extends KotlinWithGradleConfigurator
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return "As Gradle project";
|
||||
return "Gradle";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,7 @@ public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return "As Java project";
|
||||
return "Java";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -29,7 +29,7 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return "As JavaScript project";
|
||||
return "JavaScript";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.plugin.configuration;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtilCore;
|
||||
import com.intellij.ide.actions.OpenFileAction;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
@@ -84,6 +85,7 @@ public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
||||
PsiFile file = findModulePomFile(module);
|
||||
if (file != null && canConfigureFile(file)) {
|
||||
changePomFile(module, file, dialog.getKotlinVersion());
|
||||
OpenFileAction.openFile(file.getVirtualFile(), project);
|
||||
}
|
||||
else {
|
||||
showErrorMessage(project, "Cannot find pom.xml for module " + module.getName());
|
||||
@@ -254,7 +256,7 @@ public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return "As Maven project";
|
||||
return "Maven";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.plugin.configuration;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtilCore;
|
||||
import com.intellij.ide.actions.OpenFileAction;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -90,6 +91,7 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
||||
GroovyFile file = getBuildGradleFile(project, gradleFilePath);
|
||||
if (file != null && canConfigureFile(file)) {
|
||||
changeGradleFile(file, dialog.getKotlinVersion());
|
||||
OpenFileAction.openFile(gradleFilePath, project);
|
||||
}
|
||||
else {
|
||||
showErrorMessage(project, "Cannot find build.gradle file for module " + module.getName());
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="All modules with kt files: "/>
|
||||
<text value="All modules containing Kotlin files: "/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e348f" class="javax.swing.JRadioButton" binding="singleModuleRadioButton" default-binding="true">
|
||||
|
||||
Reference in New Issue
Block a user