101 lines
4.8 KiB
Java
101 lines
4.8 KiB
Java
package io.gitlab.jfronny.inceptum.gtk.window.edit;
|
|
|
|
import io.gitlab.jfronny.commons.ref.R;
|
|
import io.gitlab.jfronny.inceptum.common.Utils;
|
|
import io.gitlab.jfronny.inceptum.gtk.GtkEnvBackend;
|
|
import io.gitlab.jfronny.inceptum.gtk.GtkMain;
|
|
import io.gitlab.jfronny.inceptum.gtk.util.I18n;
|
|
import io.gitlab.jfronny.inceptum.gtk.window.InstanceSettingsWindow;
|
|
import io.gitlab.jfronny.inceptum.gtk.window.dialog.ProcessStateWatcherDialog;
|
|
import io.gitlab.jfronny.inceptum.launcher.system.exporter.Exporter;
|
|
import io.gitlab.jfronny.inceptum.launcher.system.exporter.Exporters;
|
|
import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance;
|
|
import io.gitlab.jfronny.inceptum.launcher.util.ProcessState;
|
|
import org.gtk.gtk.*;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
public class ExportTab extends SettingsTab {
|
|
public ExportTab(Instance instance, InstanceSettingsWindow window) {
|
|
super(instance, window);
|
|
section(null, section -> {
|
|
{
|
|
var row = section.row("instance.settings.export.version", "instance.settings.export.version.subtitle");
|
|
row.setEntry(instance.meta.instanceVersion, s -> {
|
|
instance.meta.instanceVersion = s;
|
|
instance.writeMeta();
|
|
});
|
|
}
|
|
for (Exporter<?> exporter : Exporters.EXPORTERS) {
|
|
var row = section.row("instance.settings.export.title", "instance.settings.export.subtitle", exporter.name, exporter.fileExtension);
|
|
row.setButton("instance.settings.export", () -> {
|
|
FileChooserNative dialog = new FileChooserNative(
|
|
I18n.get("instance.settings.export.dialog.title", exporter.name),
|
|
window,
|
|
FileChooserAction.SAVE,
|
|
"_" + I18n.get("save"),
|
|
"_" + I18n.get("cancel")
|
|
);
|
|
dialog.currentName = exporter.getDefaultFileName(instance);
|
|
dialog.onResponse(responseId -> {
|
|
if (responseId == ResponseType.ACCEPT.value) {
|
|
var file = dialog.getFile().path;
|
|
if (file == null) {
|
|
GtkEnvBackend.simpleDialog(
|
|
window,
|
|
"The path returned by the file dialog is null",
|
|
"Could not export",
|
|
MessageType.ERROR,
|
|
ButtonsType.CLOSE,
|
|
null,
|
|
null
|
|
);
|
|
return;
|
|
}
|
|
export(exporter, Path.of(file));
|
|
}
|
|
});
|
|
dialog.show();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
private void export(Exporter<?> exporter, Path path) {
|
|
ProcessState state = new ProcessState(Exporters.STEP_COUNT, "Initializing...");
|
|
ProcessStateWatcherDialog.show(
|
|
window,
|
|
I18n.get("instance.settings.export.dialog.title", exporter.name),
|
|
I18n.get("instance.settings.export.dialog.error", instance.name),
|
|
state,
|
|
cancel -> {
|
|
exporter.generate(state, instance, path);
|
|
GtkMain.schedule(() -> {
|
|
MessageDialog success = new MessageDialog(
|
|
window,
|
|
DialogFlags.MODAL.or(DialogFlags.DESTROY_WITH_PARENT),
|
|
MessageType.INFO,
|
|
ButtonsType.NONE,
|
|
I18n.get("instance.settings.export.dialog.success", instance.name, path.toString())
|
|
);
|
|
success.title = I18n.get("instance.settings.export.dialog.success.title");
|
|
success.addButton(I18n.get("show"), ResponseType.OK.value);
|
|
success.addButton(I18n.get("ok"), ResponseType.CANCEL.value);
|
|
success.onResponse(responseId1 -> {
|
|
switch (ResponseType.of(responseId1)) {
|
|
case OK -> {
|
|
success.close();
|
|
Utils.openFile(path.toFile());
|
|
}
|
|
case CLOSE, CANCEL -> success.close();
|
|
case DELETE_EVENT -> success.destroy();
|
|
}
|
|
});
|
|
success.show();
|
|
});
|
|
},
|
|
R::nop
|
|
);
|
|
}
|
|
}
|