From 28c93a3a0681c235c131d38e5913c19f924710bc Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 12 Oct 2020 13:51:40 +0300 Subject: [PATCH] settings: cleanup: extract method GitOrigin-RevId: afdb687e78e7a54ed3599753ddccde671994d6f0 --- .../src/ChooseComponentsToExportDialog.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.kt b/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.kt index 4acceb0a65e9..d43bbe4a9e17 100644 --- a/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.kt +++ b/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.kt @@ -66,7 +66,7 @@ private fun addToExistingListElement(item: ExportableItem, return file != null } -fun chooseSettingsFile(oldPath: String?, parent: Component?, title: String, description: String, onFileChosen: (VirtualFile) -> Unit) { +fun chooseSettingsFile(initialPath: String?, parent: Component?, title: String, description: String, onFileChosen: (VirtualFile) -> Unit) { val chooserDescriptor = object: FileChooserDescriptor(true, true, true, true, false, false) { override fun isFileSelectable(file: VirtualFile?): Boolean { if (file?.isDirectory == true) { @@ -80,18 +80,18 @@ fun chooseSettingsFile(oldPath: String?, parent: Component?, title: String, desc chooserDescriptor.title = title chooserDescriptor.withFileFilter { ConfigImportHelper.isSettingsFile(it) } - var initialDir: VirtualFile? - if (oldPath != null) { - val oldFile = File(oldPath) - initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile) - if (initialDir == null && oldFile.parentFile != null) { - initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile.parentFile) + FileChooser.chooseFile(chooserDescriptor, null, parent, getFileOrParent(initialPath), onFileChosen) +} + +private fun getFileOrParent(path: String?): VirtualFile? { + if (path != null) { + val oldFile = File(path) + val initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile) + return initialDir ?: oldFile.parentFile?.let { + LocalFileSystem.getInstance().findFileByIoFile(it) } } - else { - initialDir = null - } - FileChooser.chooseFile(chooserDescriptor, null, parent, initialDir, onFileChosen) + return null } internal class ChooseComponentsToExportDialog(fileToComponents: Map>,