Skip to content

Commit

Permalink
Project Wizard using HahaSwing-1.0.2.jar
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Apr 12, 2024
1 parent ccd91ab commit 0a4737b
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 236 deletions.
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ repositories {
mavenCentral()
}

dependencies {
implementation(files("libs/HahaSwing-1.0.2.jar"))
}

// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
kotlin {
jvmToolchain(17)
Expand Down
Binary file added libs/HahaSwing-1.0.2.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import javax.swing.*;

public class MyIcons {
public static Icon BLOBLIB = IconLoader.getIcon("/icons/bloblib.png", MyIcons.class);
public static Icon BLOBLIB = IconLoader.getIcon("/icons/bloblibide.png", MyIcons.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.intellij.psi.PsiDirectory;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.InputStream;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -46,7 +45,7 @@ public void actionPerformed(@NotNull AnActionEvent event){
final String namingCode = codeInput.thanks();
String currentPackage = PsiDirectoryLib.getPackageNameOrEmpty(psiDirectory);
String content;
try (InputStream inputStream = this.getClass().getResourceAsStream("/templates/BlobPlugin.java")){
try (InputStream inputStream = this.getClass().getResourceAsStream("/templates/BlobStudio.java")){
content = FileContentReplacer.getContent(Objects.requireNonNull(inputStream));
content = content.replace("us.mytheria.blobstudio", currentPackage);
content = content.replace("Studio", namingCode);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.anjoismysign.bloblibide.actions;

import com.github.anjoismysign.bloblibide.entities.FileContentReplacer;
import com.github.anjoismysign.bloblibide.entities.Uber;
import com.github.anjoismysign.bloblibide.libraries.NamingConventions;
import com.github.anjoismysign.bloblibide.libraries.PanelLib;
Expand All @@ -8,11 +9,18 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.intellij.ui.JBColor;
import me.anjoismysign.anjo.swing.components.AnjoTextField;
import me.anjoismysign.anjo.swing.listeners.TextInputType;
import me.anjoismysign.hahaswing.BubbleFactory;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
import java.io.InputStream;
import java.util.Objects;
import java.util.Optional;

import static com.github.anjoismysign.bloblibide.actions.BlobPluginAction.content;
import java.util.Random;

public class SetupProjectAction extends AnAction {
@Override
Expand All @@ -25,29 +33,91 @@ public void actionPerformed(@NotNull AnActionEvent event) {
Optional<PsiDirectory> currentPackageOptional = PsiDirectoryLib.getSelectedPackage(event);
if (currentPackageOptional.isEmpty())
return;
final Project project = event.getProject();
final PsiDirectory currentPackage = currentPackageOptional.get();
final String currentPackateAddress = PsiDirectoryLib.getPackageNameOrEmpty(currentPackage);
Uber<String> classNameInput = new Uber<>("BlobPluginNotFound");
classNameInput.talk(PanelLib.requestString("BlobPlugin", "Enter BlobPlugin class name (without '.java')\n" +
"Note: will be converted to pascal case\n" +
"Example 1: 'BlobRP'", "Please provide a class name \n" +
"Recursion will be used until then.", project));
classNameInput.talk(NamingConventions.toPascalCase(classNameInput.thanks()));
final String className = classNameInput.thanks();
final String blobPluginImport = currentPackateAddress + "." + className;
Uber<String> codeInput = new Uber<>("NamingCodeNotFound");
codeInput.talk(PanelLib.requestString("Naming Code", "Enter naming code. Will be used for generating classes\n" +
"Note: will be converted to pascal case\n" +
"Example for 'RP' would be RPManager and RPManagerDirector", "Please provide a naming code.\n" +
"Recursion will be used until then.", project));
codeInput.talk(NamingConventions.toPascalCase(codeInput.thanks()));
final String namingCode = codeInput.thanks();
PsiDirectoryLib.generateClass(currentPackage, className, content(currentPackage, namingCode, className));
Optional<PsiDirectory> directorPackageOptional = PsiDirectoryLib.createPackage(currentPackage, "director");
if (directorPackageOptional.isEmpty())
return;
final PsiDirectory directorPackage = directorPackageOptional.get();
ManagerPackageSetupAction.setup(directorPackage, namingCode, className, blobPluginImport);
final PsiDirectory psiDirectory = currentPackageOptional.get();
AnjoTextField pluginField = AnjoTextField.build(" BlobPlugin");
AnjoTextField codeField = AnjoTextField.build(" Naming Code");
BubbleFactory.getInstance().controller(anjoPane -> {
},
"Project Wizard",
new ImageIcon(Objects.requireNonNull(SetupProjectAction.this.getClass().getResource("/icons/bloblibide.png")))
.getImage().getScaledInstance(256, 256, Image.SCALE_SMOOTH),
false,
null,
pluginField,codeField)
.onBlow(anjoPane -> {
if (!anjoPane.saidYes())
return;

final String className = pluginField.getText();
if (className.isBlank())
return;
final String namingCode = codeField.getText();
if (namingCode.isBlank())
return;
String currentPackageName = PsiDirectoryLib.getPackageNameOrEmpty(psiDirectory);
// BlobPlugin
String content;
String pluginName = className;
try (InputStream inputStream = this.getClass().getResourceAsStream("/templates/BlobStudio.java")){
content = FileContentReplacer.getContent(Objects.requireNonNull(inputStream));
content = content.replace("us.mytheria.blobstudio", currentPackageName);
content = content.replace("Studio", namingCode);
PsiDirectoryLib.generateClass(psiDirectory, pluginName,
content, true);
} catch (Throwable e) {
e.printStackTrace();
return;
}

Optional<PsiDirectory> directorPackageOptional = PsiDirectoryLib.createPackage(psiDirectory, "director");
if (directorPackageOptional.isEmpty())
return;
final PsiDirectory directorPackage = directorPackageOptional.get();
String directorPackageName = PsiDirectoryLib.getPackageNameOrEmpty(directorPackage);
Optional<PsiDirectory> managerPackageOptional = PsiDirectoryLib.createPackage(directorPackage, "manager");
if (managerPackageOptional.isEmpty())
return;
final PsiDirectory managerPackage = managerPackageOptional.get();
String managerPackageName = PsiDirectoryLib.getPackageNameOrEmpty(managerPackage);

// ManagerDirector
String managerDirectorName = namingCode + "ManagerDirector";
try (InputStream inputStream = this.getClass().getResourceAsStream("/templates/director/StudioManagerDirector.java")){
content = FileContentReplacer.getContent(Objects.requireNonNull(inputStream));
content = content.replace("us.mytheria.blobstudio", currentPackageName);
content = content.replace("Studio", namingCode);
PsiDirectoryLib.generateClass(directorPackage, managerDirectorName,
content, true);
} catch (Throwable e) {
e.printStackTrace();
return;
}

// Manager
String managerName = namingCode + "Manager";
try (InputStream inputStream = this.getClass().getResourceAsStream("/templates/director/StudioManager.java")){
content = FileContentReplacer.getContent(Objects.requireNonNull(inputStream));
content = content.replace("us.mytheria.blobstudio", currentPackageName);
content = content.replace("Studio", namingCode);
PsiDirectoryLib.generateClass(directorPackage, managerName,
content, true);
} catch (Throwable e) {
e.printStackTrace();
return;
}

// ConfigManager
String configManagerName = namingCode + "ConfigManager";
try (InputStream inputStream = this.getClass().getResourceAsStream("/templates/director/manager/StudioConfigManager.java")){
content = FileContentReplacer.getContent(Objects.requireNonNull(inputStream));
content = content.replace("us.mytheria.blobstudio", currentPackageName);
content = content.replace("Studio", namingCode);
PsiDirectoryLib.generateClass(managerPackage, configManagerName,
content, true);
} catch (Throwable e) {
e.printStackTrace();
return;
}
});
}
}
Loading

0 comments on commit 0a4737b

Please sign in to comment.