-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom module type for easier project creation; improved icon loading
- Loading branch information
1 parent
718d531
commit 21fb0e3
Showing
7 changed files
with
124 additions
and
15 deletions.
There are no files selected for viewing
38 changes: 23 additions & 15 deletions
38
src/main/java/com/alekseyzhelo/evilislands/mobplugin/icon/Icons.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/alekseyzhelo/evilislands/mobplugin/project/EIModuleType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/alekseyzhelo/evilislands/mobplugin/project/EIScriptModuleBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters