fix: wrap Entry.setText to prevent segfault for empty strings

This commit is contained in:
Johannes Frohnmeyer 2023-08-19 15:32:42 +02:00
parent ad033711f9
commit 3746e30ec7
Signed by: Johannes
GPG Key ID: E76429612C2929F4
7 changed files with 23 additions and 10 deletions

View File

@ -17,7 +17,7 @@ val jbAnnotationsVersion by extra("24.0.1")
val lwjglVersion by extra("3.3.2")
val imguiVersion by extra("1.86.10")
// launcher-gtk
val javagiVersion by extra("0.6.0")
val javagiVersion by extra("0.6.1")
val flavorProp: String by extra(prop("flavor", "custom"))
if (!setOf("custom", "maven", "fat", "windows", "linux", "macos").contains(flavorProp)) throw IllegalStateException("Unsupported flavor: $flavorProp")

View File

@ -20,6 +20,7 @@ repositories {
maven("https://jitpack.io") {
content {
includeGroup("com.github.jwharm.java-gi")
includeGroup("com.github.jwharm")
}
}
}

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.gtk.control
import io.gitlab.jfronny.inceptum.gtk.util.kText
import org.gnome.gtk.Entry
import java.util.function.Consumer
@ -7,7 +8,7 @@ class KEntry(value: String? = ""): Entry() {
private val onChange = ArrayList<Consumer<String>>()
init {
text = value ?: ""
kText = value ?: ""
onChanged { onChange.forEach { it.accept(text) } }
}

View File

@ -2,6 +2,8 @@ package io.gitlab.jfronny.inceptum.gtk.util
import io.gitlab.jfronny.inceptum.gtk.control.ILabel
import org.gnome.adw.ActionRow
import org.gnome.gtk.Entry
import org.gnome.gtk.EntryBuffer
import org.gnome.gtk.Label
import org.gnome.gtk.MessageDialog
import org.gnome.gtk.Widget
@ -31,4 +33,14 @@ var MessageDialog.markup: String
set(value) { setMarkup(value) }
get() = throw NotImplementedError()
fun ActionRow.fixSubtitle() = ILabel.theme(firstChild!!.lastChild!!.prevSibling!!.lastChild as Label, ILabel.Mode.SUBTITLE)
fun ActionRow.fixSubtitle() = ILabel.theme(firstChild!!.lastChild!!.prevSibling!!.lastChild as Label, ILabel.Mode.SUBTITLE)
// Work around a segfault with empty entries
var Entry.kText: String?
get() = text
set(value) {
if (value == "") buffer.clear()
else text = value
}
fun EntryBuffer.clear() = deleteText(0, length)

View File

@ -10,6 +10,7 @@ import io.gitlab.jfronny.inceptum.gtk.control.KEntry
import io.gitlab.jfronny.inceptum.gtk.control.assistant.KAssistant
import io.gitlab.jfronny.inceptum.gtk.schedule
import io.gitlab.jfronny.inceptum.gtk.util.I18n
import io.gitlab.jfronny.inceptum.gtk.util.kText
import io.gitlab.jfronny.inceptum.gtk.util.toTypedArray
import io.gitlab.jfronny.inceptum.gtk.window.dialog.ProcessStateWatcherDialog
import io.gitlab.jfronny.inceptum.launcher.api.FabricMetaApi
@ -103,7 +104,7 @@ class NewInstanceWindow(app: Application) : KAssistant(app) {
append(entry)
onOpen {
name = InstanceNameTool.getDefaultName(gameVersion!!.id, useFabric)
entry.text = name
entry.kText = name
}
setComplete(true)

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.gtk.window.dialog
import io.gitlab.jfronny.inceptum.gtk.util.kText
import org.gnome.gtk.*
class StringInputDialog(parent: Window?, flags: DialogFlags, type: MessageType, buttons: ButtonsType, message: String, value: String) : MessageDialog(parent, flags, type, buttons, message) {
@ -7,7 +8,7 @@ class StringInputDialog(parent: Window?, flags: DialogFlags, type: MessageType,
init {
(messageArea as Box).append(entry)
entry.text = value
entry.kText = value
}
val input: String get() = entry.text

View File

@ -8,10 +8,7 @@ import io.gitlab.jfronny.inceptum.common.MetaHolder
import io.gitlab.jfronny.inceptum.common.Utils
import io.gitlab.jfronny.inceptum.gtk.control.ILabel
import io.gitlab.jfronny.inceptum.gtk.control.settings.SectionedSettingsTab
import io.gitlab.jfronny.inceptum.gtk.util.I18n
import io.gitlab.jfronny.inceptum.gtk.util.Memory
import io.gitlab.jfronny.inceptum.gtk.util.markup
import io.gitlab.jfronny.inceptum.gtk.util.toTypedArray
import io.gitlab.jfronny.inceptum.gtk.util.*
import io.gitlab.jfronny.inceptum.launcher.api.FabricMetaApi
import io.gitlab.jfronny.inceptum.launcher.api.McApi
import io.gitlab.jfronny.inceptum.launcher.system.instance.InstanceList
@ -150,7 +147,7 @@ class GeneralTab(window: InstanceSettingsWindow) : SectionedSettingsTab<Instance
dialog.onResponse { responseId: Int ->
if (responseId == ResponseType.ACCEPT.value) {
val file = dialog.file!!.path
if (file != null) entry.text = file
if (file != null) entry.kText = file
}
}
dialog.show()