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 { else {
val f = File(currentValue) val f = File(currentValue)
if (directoryOnly) { if (directoryOnly) {
val ok = f.exists() && f.isDirectory && f.canWrite() when {
(!ok) to if (!ok) "Ordner existiert nicht oder ist nicht beschreibbar" else null !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 { } else {
val ok = (f.exists() && f.isFile && f.canWrite()) || (f.parentFile?.canWrite() == true) 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 { val chooser = JFileChooser().apply {
isMultiSelectionEnabled = false isMultiSelectionEnabled = false
// Initiales Verzeichnis/Pfad // Initiales Verzeichnis/Pfad
selectedPath?.let { p -> run {
val f = File(p) val home = File(System.getProperty("user.home") ?: ".")
currentDirectory = when { val initial = selectedPath?.takeIf { it.isNotBlank() }?.let { File(it) }
f.isDirectory -> f val baseDir = when {
f.parentFile?.isDirectory == true -> f.parentFile initial == null -> home
else -> currentDirectory 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) { if (directoryOnly) {
fileSelectionMode = JFileChooser.DIRECTORIES_ONLY 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 { } else {
fileSelectionMode = JFileChooser.FILES_ONLY fileSelectionMode = JFileChooser.FILES_ONLY
if (fileExtensions.isNotEmpty()) { if (fileExtensions.isNotEmpty()) {