102 lines
4.6 KiB
Kotlin
102 lines
4.6 KiB
Kotlin
package io.gitlab.jfronny.inceptum.gtk.window.settings.instance
|
|
|
|
import io.gitlab.jfronny.inceptum.common.Utils
|
|
import io.gitlab.jfronny.inceptum.gtk.GtkEnvBackend
|
|
import io.gitlab.jfronny.inceptum.gtk.control.settings.SettingsTab
|
|
import io.gitlab.jfronny.inceptum.gtk.schedule
|
|
import io.gitlab.jfronny.inceptum.gtk.util.I18n
|
|
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.gnome.gtk.*
|
|
import java.nio.file.Path
|
|
|
|
class ExportTab(private val instance: Instance, window: InstanceSettingsWindow?) : SettingsTab(window) {
|
|
init {
|
|
section(null) {
|
|
row("instance.settings.export.version", "instance.settings.export.version.subtitle") {
|
|
setEntry(instance.meta.instanceVersion) {
|
|
instance.meta.instanceVersion = it
|
|
instance.writeMeta()
|
|
}
|
|
}
|
|
for (exporter in Exporters.EXPORTERS) {
|
|
row("instance.settings.export.title", "instance.settings.export.subtitle", exporter.name, exporter.fileExtension) {
|
|
setButton("instance.settings.export") {
|
|
val dialog = FileChooserNative(
|
|
I18n["instance.settings.export.dialog.title", exporter.name],
|
|
window,
|
|
FileChooserAction.SAVE,
|
|
"_" + I18n["save"],
|
|
"_" + I18n["cancel"]
|
|
)
|
|
val filter = FileFilter()
|
|
filter.name = exporter.name + " Pack"
|
|
filter.addPattern("*." + exporter.fileExtension)
|
|
dialog.addFilter(filter)
|
|
dialog.currentName = exporter.getDefaultFileName(instance)
|
|
dialog.onResponse { responseId: Int ->
|
|
if (responseId == ResponseType.ACCEPT.value) {
|
|
val file = dialog.file!!.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@onResponse
|
|
}
|
|
export(exporter, Path.of(file))
|
|
}
|
|
}
|
|
dialog.show()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private fun export(exporter: Exporter<*>, path: Path) {
|
|
val state = ProcessState(Exporters.STEP_COUNT, "Initializing...")
|
|
ProcessStateWatcherDialog.show(
|
|
window,
|
|
I18n["instance.settings.export.dialog.title", exporter.name],
|
|
I18n["instance.settings.export.dialog.error", instance.name],
|
|
state
|
|
) {
|
|
exporter.generate(state, instance, path)
|
|
schedule {
|
|
val success = MessageDialog(
|
|
window,
|
|
DialogFlags.MODAL.or(DialogFlags.DESTROY_WITH_PARENT),
|
|
MessageType.INFO,
|
|
ButtonsType.NONE,
|
|
I18n["instance.settings.export.dialog.success", instance.name, path.toString()]
|
|
)
|
|
success.title = I18n["instance.settings.export.dialog.success.title"]
|
|
success.addButton(I18n["show"], ResponseType.OK.value)
|
|
success.addButton(I18n["ok"], ResponseType.CANCEL.value)
|
|
success.onResponse { responseId1: Int ->
|
|
when (ResponseType.of(responseId1)) {
|
|
ResponseType.OK -> {
|
|
success.close()
|
|
Utils.openFile(path.toFile())
|
|
}
|
|
|
|
ResponseType.CLOSE, ResponseType.CANCEL -> success.close()
|
|
ResponseType.DELETE_EVENT -> success.destroy()
|
|
else -> {}
|
|
}
|
|
}
|
|
success.show()
|
|
}
|
|
}
|
|
}
|
|
}
|