From 7b8e6fa462db355a2a28f3aea67cb1c0a217ae4b Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 13 Mar 2014 19:42:18 +0400 Subject: [PATCH] Add kotlin templates for project create wizard #KT-4689 Fixed --- .../com/intellij/platform/annotations.xml | 15 ++ .../jetbrains/jet/plugin/icons/kotlin24.png | Bin 0 -> 758 bytes .../jet/plugin/icons/kotlin24@2x.png | Bin 0 -> 1723 bytes idea/src/META-INF/plugin.xml | 2 + .../org/jetbrains/jet/plugin/JetIcons.java | 3 +- .../plugin/framework/KotlinModuleBuilder.kt | 50 +++++++ .../framework/KotlinModuleSettingStep.java | 140 ++++++++++++++++++ .../framework/KotlinTemplatesFactory.kt | 40 +++++ 8 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 annotations/com/intellij/platform/annotations.xml create mode 100644 idea/resources/org/jetbrains/jet/plugin/icons/kotlin24.png create mode 100644 idea/resources/org/jetbrains/jet/plugin/icons/kotlin24@2x.png create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleBuilder.kt create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleSettingStep.java create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/KotlinTemplatesFactory.kt diff --git a/annotations/com/intellij/platform/annotations.xml b/annotations/com/intellij/platform/annotations.xml new file mode 100644 index 00000000000..4d50b6072ed --- /dev/null +++ b/annotations/com/intellij/platform/annotations.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/idea/resources/org/jetbrains/jet/plugin/icons/kotlin24.png b/idea/resources/org/jetbrains/jet/plugin/icons/kotlin24.png new file mode 100644 index 0000000000000000000000000000000000000000..57733d2a3795395596b08ee6e9ada07e04579b25 GIT binary patch literal 758 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qRNAp5A0007INkla}n0VkD2|=&V0-4t_}eHE2P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B2~GxJPP7T9!@$g91IWY_fJ&hHp%X zsBQdVC?4fhPP1#}1(%(@YNd=tv?@>I>dT|g?(4lP&V2qv(va8G=bdSaPWoA((*W$L zo#*qn{LsS%Y33op(Ul^hBps+nvc_Cp^R45SEc|U*lVXgy+Eb?^ZAa^j=|yIT3jepkot`u2QbgY{uz6jj1wJu3C=8A$wu{w<<<^c5ns zqjtY~6=}zt#7@TLMdGTtavt1?F*JVn>^ppDi)%wN4_RB0lN!UYe|LyAx;TN&(;cA% zJ3AX5P;)Bkkfu7{Z@AI4%o6lEf8-N5^!1oz*tD{DKF2tv+YKbx+wmQycTY{9{2r62 zo4EW-?i~W7K7H9$VA|OnOX#1Ofo7XSK-tNnzdo8r_(K0_(zbjWtjBsU@O?)>E|)5_ zGQ1VoURXRF>Q$CjpcZ{tV|MLIt1I#0_WpS7_<;n7cGJce4pWwW#2)Kk9TeKxCEr9A z0hcd6)eDNN5Tiluk#OsL{2| zq`4Pc1zd#vLn3_t+m_rWk9Xts|ocwC;YwL zk9G6d*WszIdP&R6mFdXe6;KvWVfC#7VhxyCqD(l@NEV#Bq@IfUsr!dX)69+)?T0;Q zVHBS^s)xcaERIl;xml82ZJ5DMGML&{Da>C5gW?_jKN0`S(Ch9(P;q2PxN^4u Nj$^RsW{-%R{{d%}JN^Iw literal 0 HcmV?d00001 diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index c73148b46bf..1b7b4d3732b 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -305,6 +305,8 @@ + + diff --git a/idea/src/org/jetbrains/jet/plugin/JetIcons.java b/idea/src/org/jetbrains/jet/plugin/JetIcons.java index 2ab18c3b3f8..b04ee650346 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetIcons.java +++ b/idea/src/org/jetbrains/jet/plugin/JetIcons.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import javax.swing.*; public interface JetIcons { Icon SMALL_LOGO = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin.png"); + Icon KOTLIN_LOGO_24 = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin24.png"); Icon SMALL_LOGO_13 = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin13.png"); diff --git a/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleBuilder.kt b/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleBuilder.kt new file mode 100644 index 00000000000..2e0a4ce1c3a --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleBuilder.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.framework + +import com.intellij.ide.util.projectWizard.JavaModuleBuilder +import com.intellij.ide.util.projectWizard.ModuleWizardStep +import com.intellij.ide.util.projectWizard.SettingsStep +import com.intellij.openapi.module.ModifiableModuleModel +import com.intellij.openapi.module.Module +import com.intellij.openapi.module.ModuleWithNameAlreadyExists +import com.intellij.openapi.options.ConfigurationException +import com.intellij.openapi.util.InvalidDataException +import org.jdom.JDOMException +import org.jetbrains.annotations.Nullable +import org.jetbrains.jet.plugin.JetIcons +import org.jetbrains.jet.plugin.project.TargetPlatform +import javax.swing.* +import java.io.IOException +import com.intellij.openapi.roots.ui.configuration.ModulesProvider +import com.intellij.ide.util.projectWizard.WizardContext + +public class KotlinModuleBuilder( + val targetPlatform: TargetPlatform, val builderName: String, val builderDescription: String) : JavaModuleBuilder() { + override fun getBuilderId() = "kotlin.module.builder" + override fun getName() = builderName + override fun getPresentableName() = builderName + override fun getDescription() = builderDescription + override fun getBigIcon() = JetIcons.KOTLIN_LOGO_24 + override fun getNodeIcon() = JetIcons.SMALL_LOGO + override fun getGroupName() = KotlinTemplatesFactory.KOTLIN_GROUP_NAME + override fun createWizardSteps(wizardContext: WizardContext, modulesProvider: ModulesProvider) = ModuleWizardStep.EMPTY_ARRAY + + override fun modifySettingsStep(settingsStep: SettingsStep): ModuleWizardStep { + return KotlinModuleSettingStep(targetPlatform, this, settingsStep) + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleSettingStep.java b/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleSettingStep.java new file mode 100644 index 00000000000..b71ed99c6c1 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleSettingStep.java @@ -0,0 +1,140 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.framework; + +import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings; +import com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel; +import com.intellij.framework.library.FrameworkLibraryVersionFilter; +import com.intellij.ide.util.projectWizard.ModuleBuilder; +import com.intellij.ide.util.projectWizard.ModuleWizardStep; +import com.intellij.ide.util.projectWizard.SettingsStep; +import com.intellij.openapi.module.JavaModuleType; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; +import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; +import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.io.FileUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.plugin.project.TargetPlatform; + +import javax.swing.*; +import java.util.ArrayList; + +public class KotlinModuleSettingStep extends ModuleWizardStep { + private final TargetPlatform targetPlatform; + + @Nullable + private final ModuleWizardStep myJavaStep; + + private final CustomLibraryDescription customLibraryDescription; + private final LibrariesContainer librariesContainer; + + private LibraryOptionsPanel libraryOptionsPanel; + private LibraryCompositionSettings libraryCompositionSettings; + + private final String basePath; + + public KotlinModuleSettingStep(TargetPlatform targetPlatform, ModuleBuilder moduleBuilder, @NotNull SettingsStep settingsStep) { + this.targetPlatform = targetPlatform; + + myJavaStep = JavaModuleType.getModuleType().modifySettingsStep(settingsStep, moduleBuilder); + + basePath = moduleBuilder.getContentEntryPath(); + librariesContainer = LibrariesContainerFactory.createContainer(settingsStep.getContext().getProject()); + + customLibraryDescription = getCustomLibraryDescription(settingsStep.getContext().getProject()); + + moduleBuilder.addModuleConfigurationUpdater(createModuleConfigurationUpdater()); + + settingsStep.addSettingsField(getLibraryLabelText(), getLibraryPanel().getSimplePanel()); + } + + protected ModuleBuilder.ModuleConfigurationUpdater createModuleConfigurationUpdater() { + return new ModuleBuilder.ModuleConfigurationUpdater() { + @Override + public void update(@NotNull Module module, @NotNull ModifiableRootModel rootModel) { + if (libraryCompositionSettings != null) { + libraryCompositionSettings.addLibraries(rootModel, new ArrayList(), librariesContainer); + + if (customLibraryDescription instanceof CustomLibraryDescriptorWithDefferConfig) { + ((CustomLibraryDescriptorWithDefferConfig) customLibraryDescription).finishLibConfiguration(module, rootModel); + } + } + } + }; + } + + @Override + public void disposeUIResources() { + if (libraryOptionsPanel != null) { + Disposer.dispose(libraryOptionsPanel); + } + } + + @Override + public JComponent getComponent() { + return getLibraryPanel().getMainPanel(); + } + + @NotNull + protected String getLibraryLabelText() { + if (targetPlatform == TargetPlatform.JVM) return "\u001BKotlin runtime:"; + if (targetPlatform == TargetPlatform.JS) return "\u001BKotlin JS library:"; + throw new IllegalStateException("Only JS and JVM target are supported"); + } + + @NotNull + protected CustomLibraryDescription getCustomLibraryDescription(@Nullable Project project) { + if (targetPlatform == TargetPlatform.JVM) return new JavaRuntimeLibraryDescription(project); + if (targetPlatform == TargetPlatform.JS) return new JSLibraryStdDescription(project); + throw new IllegalStateException("Only JS and JVM target are supported"); + } + + @Override + public void updateDataModel() { + libraryCompositionSettings = getLibraryPanel().apply(); + if (myJavaStep != null) { + myJavaStep.updateDataModel(); + } + } + + @Override + public boolean validate() throws ConfigurationException { + return super.validate() && (myJavaStep == null || myJavaStep.validate()); + } + + protected LibraryOptionsPanel getLibraryPanel() { + if (libraryOptionsPanel == null) { + String baseDirPath = basePath != null ? FileUtil.toSystemIndependentName(basePath) : ""; + + libraryOptionsPanel = new LibraryOptionsPanel( + customLibraryDescription, + baseDirPath, + FrameworkLibraryVersionFilter.ALL, + librariesContainer, + false); + } + + return libraryOptionsPanel; + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/framework/KotlinTemplatesFactory.kt b/idea/src/org/jetbrains/jet/plugin/framework/KotlinTemplatesFactory.kt new file mode 100644 index 00000000000..3bdcbfa73a4 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/KotlinTemplatesFactory.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.framework + +import com.intellij.ide.util.projectWizard.WizardContext +import com.intellij.platform.ProjectTemplate +import com.intellij.platform.ProjectTemplatesFactory +import com.intellij.platform.templates.BuilderBasedTemplate +import org.jetbrains.jet.plugin.JetIcons +import org.jetbrains.jet.plugin.project.TargetPlatform +import javax.swing.* + +public class KotlinTemplatesFactory : ProjectTemplatesFactory() { + class object { + public val KOTLIN_GROUP_NAME: String = "Kotlin" + } + + override fun getGroups() = array(KOTLIN_GROUP_NAME) + override fun getGroupIcon(group: String) = JetIcons.KOTLIN_LOGO_24 + + override fun createTemplates(group: String, context: WizardContext?) = + array( + BuilderBasedTemplate(KotlinModuleBuilder(TargetPlatform.JVM, "Kotlin - JVM", "Kotlin module for JVM target")), + BuilderBasedTemplate(KotlinModuleBuilder(TargetPlatform.JS, "Kotlin - JavaScript", "Kotlin module for JavaScript target")) + ) +}