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:
+26
-11
@@ -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_ONLY‑Modus verwenden (kein Save‑Dialog)
|
||||
dialogType = JFileChooser.OPEN_DIALOG
|
||||
} else {
|
||||
fileSelectionMode = JFileChooser.FILES_ONLY
|
||||
if (fileExtensions.isNotEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user