2022-01-23 18:53:16 +01:00
|
|
|
package io.gitlab.jfronny.inceptum.frontend.gui.window.edit;
|
|
|
|
|
|
|
|
import imgui.ImGui;
|
|
|
|
import imgui.type.ImBoolean;
|
|
|
|
import imgui.type.ImString;
|
2022-04-28 23:13:37 +02:00
|
|
|
import io.gitlab.jfronny.commons.OSUtils;
|
2022-01-23 18:53:16 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.Inceptum;
|
|
|
|
import io.gitlab.jfronny.inceptum.InceptumGui;
|
|
|
|
import io.gitlab.jfronny.inceptum.frontend.gui.control.InstanceManageControls;
|
|
|
|
import io.gitlab.jfronny.inceptum.frontend.gui.control.Tab;
|
|
|
|
import io.gitlab.jfronny.inceptum.frontend.gui.window.GuiUtil;
|
|
|
|
import io.gitlab.jfronny.inceptum.util.MetaHolder;
|
|
|
|
import io.gitlab.jfronny.inceptum.util.Utils;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
|
|
|
public class GeneralTab extends Tab {
|
|
|
|
private final InstanceManageControls imc;
|
|
|
|
private final InstanceEditWindow window;
|
|
|
|
private final ImBoolean customJava;
|
|
|
|
private final ImString customJavaPath = new ImString(GuiUtil.INPUT_FIELD_LENGTH);
|
|
|
|
|
|
|
|
public GeneralTab(InstanceEditWindow window) {
|
|
|
|
super("General");
|
|
|
|
this.window = window;
|
2022-06-11 13:10:47 +02:00
|
|
|
imc = new InstanceManageControls(window.instance, window.name);
|
2022-01-23 18:53:16 +01:00
|
|
|
customJava = new ImBoolean(window.instance.java != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void renderInner() {
|
|
|
|
if (ImGui.button("Open Directory")) {
|
|
|
|
Utils.openFile(window.path.toFile());
|
|
|
|
}
|
|
|
|
imc.nameBox("Rename", name -> {
|
|
|
|
try {
|
|
|
|
Path newPath = MetaHolder.INSTANCE_DIR.resolve(name);
|
|
|
|
Files.move(window.path, newPath);
|
|
|
|
InceptumGui.open(new InstanceEditWindow(newPath, window.instance));
|
|
|
|
window.close();
|
|
|
|
} catch (IOException e) {
|
2022-01-27 17:57:13 +01:00
|
|
|
Inceptum.showError("Could not rename", e);
|
2022-01-23 18:53:16 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
imc.snapshotsBox();
|
|
|
|
imc.versionBox(ver -> {
|
|
|
|
window.reDownload = true;
|
|
|
|
window.instance.version = ver;
|
|
|
|
window.save();
|
|
|
|
});
|
|
|
|
if (ImGui.button("Delete")) Inceptum.showOkCancel("This instance will be removed forever (a long time)", "Are you sure?", () -> {
|
|
|
|
try {
|
|
|
|
Utils.deleteRecursive(window.path);
|
|
|
|
} catch (IOException e) {
|
|
|
|
Inceptum.showError("Could not delete the instance", e);
|
|
|
|
}
|
|
|
|
window.close();
|
|
|
|
}, () -> {});
|
|
|
|
if (ImGui.checkbox("Custom Java", customJava)) {
|
|
|
|
if (customJava.get()) {
|
2022-04-28 23:13:37 +02:00
|
|
|
window.instance.java = OSUtils.getJvmBinary();
|
2022-01-23 18:53:16 +01:00
|
|
|
customJavaPath.set(window.instance.java);
|
|
|
|
} else {
|
|
|
|
window.instance.java = null;
|
|
|
|
}
|
|
|
|
window.save();
|
|
|
|
}
|
|
|
|
if (customJava.get() && ImGui.inputText("Path", customJavaPath)) {
|
|
|
|
window.instance.java = customJavaPath.get();
|
|
|
|
window.save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|