Skip to content

Commit

Permalink
Custom module type for easier project creation; improved icon loading
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksZhelo committed Dec 10, 2019
1 parent 718d531 commit 21fb0e3
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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<EIScriptModuleBuilder> {

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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
<liveTemplateContext implementation="com.alekseyzhelo.evilislands.mobplugin.script.template.EITemplateContextType$FunctionArgumentAllowed" />
<liveTemplateContext implementation="com.alekseyzhelo.evilislands.mobplugin.script.template.EITemplateContextType$CoordinateArgumentsAllowed" />
<defaultLiveTemplatesProvider implementation="com.alekseyzhelo.evilislands.mobplugin.script.template.EILiveTemplatesProvider" />
<moduleType id="EI_MODULE_TYPE"
implementationClass="com.alekseyzhelo.evilislands.mobplugin.project.EIModuleType"/>
</extensions>

<application-components>
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/icons/eiscriptModule.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/main/resources/icons/eiscriptModule_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/main/resources/messages/EIMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 21fb0e3

Please sign in to comment.