refactor(core, desktop): Fehlertexte präzisiert und Verzeichnisauswahl für JFileChooser optimiert

Signed-off-by: Stefan Mogeritsch <stefan.mo.co@gmail.com>
This commit is contained in:
2026-05-08 12:25:55 +02:00
parent 3aaf5cc59c
commit 04a435df1d
@@ -33,11 +33,21 @@ actual fun MsFilePicker(
else {
val f = File(currentValue)
if (directoryOnly) {
val ok = f.exists() && f.isDirectory && f.canWrite()
(!ok) to if (!ok) "Ordner existiert nicht oder ist nicht beschreibbar" else null
when {
!f.exists() -> true to "Ordner existiert nicht"
!f.isDirectory -> true to "Pfad ist kein Ordner"
!f.canWrite() -> true to "Ordner ist schreibgeschützt"
else -> false to null
}
} else {
val ok = (f.exists() && f.isFile && f.canWrite()) || (f.parentFile?.canWrite() == true)
(!ok) to if (!ok) "Datei/Ordner nicht beschreibbar" else null
(!ok) to if (!ok) {
when {
!f.exists() && f.parentFile?.exists() != true -> "Pfad existiert nicht"
f.exists() && !f.isFile -> "Pfad ist keine Datei"
else -> "Datei/Ordner nicht beschreibbar"
}
} else null
}
}
}
@@ -69,19 +79,24 @@ actual fun MsFilePicker(
val chooser = JFileChooser().apply {
isMultiSelectionEnabled = false
// Initiales Verzeichnis/Pfad
selectedPath?.let { p ->
val f = File(p)
currentDirectory = when {
f.isDirectory -> f
f.parentFile?.isDirectory == true -> f.parentFile
else -> currentDirectory
run {
val home = File(System.getProperty("user.home") ?: ".")
val initial = selectedPath?.takeIf { it.isNotBlank() }?.let { File(it) }
val baseDir = when {
initial == null -> home
directoryOnly && initial.isDirectory -> initial
!directoryOnly && initial.isFile -> initial.parentFile ?: home
initial.parentFile?.isDirectory == true -> initial.parentFile
else -> home
}
if (!directoryOnly && f.isFile) selectedFile = f
currentDirectory = baseDir
if (!directoryOnly && initial?.isFile == true) selectedFile = initial
}
if (directoryOnly) {
fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
dialogType = JFileChooser.SAVE_DIALOG // ermöglicht "Neuer Ordner"
// KDE/Plasma: OPEN_DIALOG im DIRECTORIES_ONLYModus verwenden (kein SaveDialog)
dialogType = JFileChooser.OPEN_DIALOG
} else {
fileSelectionMode = JFileChooser.FILES_ONLY
if (fileExtensions.isNotEmpty()) {