From 21fb0e376afe6fd4bf59a975d896086283367c0a Mon Sep 17 00:00:00 2001 From: Aleksey Zhelo Date: Tue, 10 Dec 2019 17:03:57 +0200 Subject: [PATCH] Custom module type for easier project creation; improved icon loading --- .../evilislands/mobplugin/icon/Icons.java | 38 ++++++++------ .../mobplugin/project/EIModuleType.java | 49 +++++++++++++++++++ .../project/EIScriptModuleBuilder.java | 35 +++++++++++++ src/main/resources/META-INF/plugin.xml | 2 + src/main/resources/icons/eiscriptModule.svg | 6 +++ .../resources/icons/eiscriptModule_dark.svg | 6 +++ .../resources/messages/EIMessages.properties | 3 ++ 7 files changed, 124 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/alekseyzhelo/evilislands/mobplugin/project/EIModuleType.java create mode 100644 src/main/java/com/alekseyzhelo/evilislands/mobplugin/project/EIScriptModuleBuilder.java create mode 100644 src/main/resources/icons/eiscriptModule.svg create mode 100644 src/main/resources/icons/eiscriptModule_dark.svg diff --git a/src/main/java/com/alekseyzhelo/evilislands/mobplugin/icon/Icons.java b/src/main/java/com/alekseyzhelo/evilislands/mobplugin/icon/Icons.java index eddbf99..58e9aa9 100644 --- a/src/main/java/com/alekseyzhelo/evilislands/mobplugin/icon/Icons.java +++ b/src/main/java/com/alekseyzhelo/evilislands/mobplugin/icon/Icons.java @@ -1,26 +1,34 @@ package com.alekseyzhelo.evilislands.mobplugin.icon; import com.intellij.openapi.util.IconLoader; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import javax.swing.*; public class Icons { - public static final Icon MOB_FILE = IconLoader.getIcon("/icons/mobFile.svg"); - public static final Icon SCRIPT_FILE = IconLoader.getIcon("/icons/scriptFile.svg"); - public static final Icon FUNCTION = IconLoader.getIcon("/icons/function.svg"); - public static final Icon SCRIPT_IMPL = IconLoader.getIcon("/icons/scriptImpl.svg"); - public static final Icon GLOBAL_VAR = IconLoader.getIcon("/icons/globalVar.svg"); - public static final Icon GS_VAR = IconLoader.getIcon("/icons/gsVar.svg"); - public static final Icon AREA = IconLoader.getIcon("/icons/area.svg"); + + private static Icon load(@NonNls @NotNull final String path) { + return IconLoader.findIcon(path, Icons.class); + } + + public static final Icon MODULE = load("/icons/eiscriptModule.svg"); + public static final Icon MOB_FILE = load("/icons/mobFile.svg"); + public static final Icon SCRIPT_FILE = load("/icons/scriptFile.svg"); + public static final Icon FUNCTION = load("/icons/function.svg"); + public static final Icon SCRIPT_IMPL = load("/icons/scriptImpl.svg"); + public static final Icon GLOBAL_VAR = load("/icons/globalVar.svg"); + public static final Icon GS_VAR = load("/icons/gsVar.svg"); + public static final Icon AREA = load("/icons/area.svg"); public static class Objects { - public static final Icon FLAME = IconLoader.getIcon("/icons/objects/mobFlame.svg"); - public static final Icon LEVER = IconLoader.getIcon("/icons/objects/mobLever.svg"); - public static final Icon LIGHT = IconLoader.getIcon("/icons/objects/mobLight.svg"); - public static final Icon OBJECT = IconLoader.getIcon("/icons/objects/mobObject.svg"); - public static final Icon PARTICLE = IconLoader.getIcon("/icons/objects/mobParticle.svg"); - public static final Icon SOUND = IconLoader.getIcon("/icons/objects/mobSound.svg"); - public static final Icon TRAP = IconLoader.getIcon("/icons/objects/mobTrap.svg"); - public static final Icon UNIT = IconLoader.getIcon("/icons/objects/mobUnit.svg"); + public static final Icon FLAME = load("/icons/objects/mobFlame.svg"); + public static final Icon LEVER = load("/icons/objects/mobLever.svg"); + public static final Icon LIGHT = load("/icons/objects/mobLight.svg"); + public static final Icon OBJECT = load("/icons/objects/mobObject.svg"); + public static final Icon PARTICLE = load("/icons/objects/mobParticle.svg"); + public static final Icon SOUND = load("/icons/objects/mobSound.svg"); + public static final Icon TRAP = load("/icons/objects/mobTrap.svg"); + public static final Icon UNIT = load("/icons/objects/mobUnit.svg"); } } \ No newline at end of file diff --git a/src/main/java/com/alekseyzhelo/evilislands/mobplugin/project/EIModuleType.java b/src/main/java/com/alekseyzhelo/evilislands/mobplugin/project/EIModuleType.java new file mode 100644 index 0000000..da4c819 --- /dev/null +++ b/src/main/java/com/alekseyzhelo/evilislands/mobplugin/project/EIModuleType.java @@ -0,0 +1,49 @@ +package com.alekseyzhelo.evilislands.mobplugin.project; + +import com.alekseyzhelo.evilislands.mobplugin.EIMessages; +import com.alekseyzhelo.evilislands.mobplugin.icon.Icons; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.module.ModuleTypeManager; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +public class EIModuleType extends ModuleType { + + private static final String ID = "EI_MODULE_TYPE"; + + public EIModuleType() { + super(ID); + } + + public static EIModuleType getInstance() { + return (EIModuleType) ModuleTypeManager.getInstance().findByID(ID); + } + + @NotNull + @Override + public EIScriptModuleBuilder createModuleBuilder() { + return new EIScriptModuleBuilder(); + } + + @Nls(capitalization = Nls.Capitalization.Title) + @NotNull + @Override + public String getName() { + return EIMessages.message("ei.module.name"); + } + + @Nls(capitalization = Nls.Capitalization.Sentence) + @NotNull + @Override + public String getDescription() { + return ""; + } + + @NotNull + @Override + public Icon getNodeIcon(boolean isOpened) { + return Icons.MODULE; + } +} \ No newline at end of file diff --git a/src/main/java/com/alekseyzhelo/evilislands/mobplugin/project/EIScriptModuleBuilder.java b/src/main/java/com/alekseyzhelo/evilislands/mobplugin/project/EIScriptModuleBuilder.java new file mode 100644 index 0000000..fcc0f4c --- /dev/null +++ b/src/main/java/com/alekseyzhelo/evilislands/mobplugin/project/EIScriptModuleBuilder.java @@ -0,0 +1,35 @@ + +package com.alekseyzhelo.evilislands.mobplugin.project; + +import com.intellij.ide.util.projectWizard.ModuleBuilder; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.roots.ContentEntry; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.SystemIndependent; + +import java.util.Objects; + +public class EIScriptModuleBuilder extends ModuleBuilder { + + @Override + public void setupRootModel(@NotNull ModifiableRootModel modifiableRootModel) { + @SystemIndependent final String basePath = Objects.requireNonNull(modifiableRootModel.getProject().getBasePath()); + final VirtualFile root = LocalFileSystem.getInstance().findFileByPath(basePath); + assert root != null; + ContentEntry entry = modifiableRootModel.addContentEntry(root); + entry.addSourceFolder(root, false); + } + + @Override + public boolean canCreateModule() { + return true; + } + + @Override + public ModuleType getModuleType() { + return EIModuleType.getInstance(); + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 4ffafbe..ee707af 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -72,6 +72,8 @@ + diff --git a/src/main/resources/icons/eiscriptModule.svg b/src/main/resources/icons/eiscriptModule.svg new file mode 100644 index 0000000..6282dc8 --- /dev/null +++ b/src/main/resources/icons/eiscriptModule.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/main/resources/icons/eiscriptModule_dark.svg b/src/main/resources/icons/eiscriptModule_dark.svg new file mode 100644 index 0000000..c32e759 --- /dev/null +++ b/src/main/resources/icons/eiscriptModule_dark.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/main/resources/messages/EIMessages.properties b/src/main/resources/messages/EIMessages.properties index 81ae1ea..2460803 100644 --- a/src/main/resources/messages/EIMessages.properties +++ b/src/main/resources/messages/EIMessages.properties @@ -145,3 +145,6 @@ templates.context.script.block.allowed=Script block allowed templates.context.script.expression.allowed=Script expression allowed templates.context.function.argument.allowed=Function argument allowed templates.context.coordinate.arguments.allowed=Coordinate arguments allowed + +# Module +ei.module.name=Empty EIScript Project