@@ -24,9 +24,9 @@ import com.valaphee.blit.data.locale.Locale
2424import com.valaphee.blit.data.manifest.IconManifest
2525import com.valaphee.blit.source.Entry
2626import com.valaphee.blit.source.Source
27+ import com.valaphee.blit.source.SourceConfig
2728import javafx.beans.property.SimpleObjectProperty
2829import javafx.beans.property.SimpleStringProperty
29- import javafx.collections.ObservableList
3030import javafx.scene.control.ContextMenu
3131import javafx.scene.control.SelectionMode
3232import javafx.scene.control.TableColumnBase
@@ -86,7 +86,7 @@ import java.util.concurrent.CompletableFuture
8686class MainView : View (" Blit" ) {
8787 private val locale by di<Locale >()
8888 private val iconManifest by di<IconManifest >()
89- private val configModel by di<Config . Model >()
89+ private val _config by di<Config >()
9090
9191 private val taskManager = TaskManager ().apply {
9292 val version = System .getProperty(" os.version" ).toFloatOrNull()
@@ -145,6 +145,14 @@ class MainView : View("Blit") {
145145 }
146146
147147 inner class Pane <T : Entry <T >> : VBox () {
148+ private val sourceConfig = SimpleObjectProperty <SourceConfig >().apply {
149+ onChange {
150+ it?.let {
151+ @Suppress(" UNCHECKED_CAST" )
152+ source.value = it.newSource() as Source <T >
153+ }
154+ }
155+ }
148156 private val source = SimpleObjectProperty <Source <T >>().apply {
149157 onChange {
150158 it?.let {
@@ -162,9 +170,9 @@ class MainView : View("Blit") {
162170 hgrow = Priority .ALWAYS
163171
164172 hbox {
165- combobox(source ) {
173+ combobox(sourceConfig ) {
166174 @Suppress(" UNCHECKED_CAST" )
167- items = configModel .sources as ObservableList < Source < T >>
175+ items = _config .sources
168176 }
169177 add(CustomTextField ().apply {
170178 bind(name)
@@ -245,7 +253,7 @@ class MainView : View("Blit") {
245253 }
246254 column(locale[" main.tree.column.size.title" ], Entry <T >::self) {
247255 tableColumnBaseSetWidth(this , 75.0 )
248- cellFormat { text = if (it.directory) " " else configModel .dataSizeUnit.value .format(it.size) }
256+ cellFormat { text = if (it.directory) " " else _config .dataSizeUnit.format(it.size) }
249257 setComparator { a, b -> a.size.compareTo(b.size) }
250258 }
251259 column(locale[" main.tree.column.modified.title" ], Entry <T >::modifyTime) {
@@ -261,9 +269,9 @@ class MainView : View("Blit") {
261269 setContent {
262270 taskManager.runBlocking(locale[" main.tree.task.download.name" ]) {
263271 suspend fun flatten (entry : Entry <T >, path : String? = null): List <File > = if (entry.directory) {
264- File (configModel .temporaryPath.value , entry.name).mkdir()
272+ File (_config .temporaryPath, entry.name).mkdir()
265273 entry.list().flatMap { flatten(it, " ${path?.let { " $path /" } ? : " " }${entry.name} " ) }
266- } else listOf (File (configModel .temporaryPath.value , " ${path?.let { " $path /" } ? : " " }${entry.name} " ).apply { FileOutputStream (this ).use { entry.transferTo(it) } })
274+ } else listOf (File (_config .temporaryPath, " ${path?.let { " $path /" } ? : " " }${entry.name} " ).apply { FileOutputStream (this ).use { entry.transferTo(it) } })
267275
268276 putFiles(selectionModel.selectedItems.flatMap { flatten(it.value) })
269277 }
@@ -302,9 +310,9 @@ class MainView : View("Blit") {
302310 KeyCode .C -> if (it.isControlDown) Clipboard .getSystemClipboard().setContent {
303311 taskManager.runBlocking(locale[" main.tree.task.download.name" ]) {
304312 suspend fun flatten (entry : Entry <T >, path : String? = null): List <File > = if (entry.directory) {
305- File (configModel .temporaryPath.value , entry.name).mkdir()
313+ File (_config .temporaryPath, entry.name).mkdir()
306314 entry.list().flatMap { flatten(it, " ${path?.let { " $path /" } ? : " " }${entry.name} " ) }
307- } else listOf (File (configModel .temporaryPath.value , " ${path?.let { " $path /" } ? : " " }${entry.name} " ).apply { FileOutputStream (this ).use { entry.transferTo(it) } })
315+ } else listOf (File (_config .temporaryPath, " ${path?.let { " $path /" } ? : " " }${entry.name} " ).apply { FileOutputStream (this ).use { entry.transferTo(it) } })
308316
309317 putFiles(selectionModel.selectedItems.flatMap { flatten(it.value) })
310318
@@ -333,7 +341,7 @@ class MainView : View("Blit") {
333341 private fun open (item : TreeItem <Entry <T >>) {
334342 if (Desktop .isDesktopSupported()) {
335343 val entry = item.value
336- taskManager.launch(locale[" main.tree.task.download.name" , entry]) { Desktop .getDesktop().open(File (configModel .temporaryPath.value , entry.name).apply { FileOutputStream (this ).use { entry.transferTo(it) } }) } // TODO: Desktop.open throws IOException (No application is associated with the specific file for this operation.)
344+ taskManager.launch(locale[" main.tree.task.download.name" , entry]) { Desktop .getDesktop().open(File (_config .temporaryPath, entry.name).apply { FileOutputStream (this ).use { entry.transferTo(it) } }) } // TODO: Desktop.open throws IOException (No application is associated with the specific file for this operation.)
337345 }
338346 }
339347
0 commit comments