1616
1717package com.valaphee.blit
1818
19- import com.valaphee.blit.data.config.Config
19+ import com.valaphee.blit.data.config.ConfigModel
2020import com.valaphee.blit.data.config.ConfigView
2121import com.valaphee.blit.data.locale.Locale
2222import com.valaphee.blit.data.manifest.IconManifest
2323import com.valaphee.blit.source.Entry
2424import com.valaphee.blit.source.Source
25- import com.valaphee.blit.util.Work
26- import com.valaphee.blit.util.comExecutor
27- import com.valaphee.blit.util.hWnd
2825import javafx.beans.property.SimpleObjectProperty
2926import javafx.beans.property.SimpleStringProperty
3027import javafx.collections.ObservableList
@@ -87,9 +84,9 @@ import java.util.concurrent.CompletableFuture
8784class MainView : View (" Blit" ) {
8885 private val locale by di<Locale >()
8986 private val iconManifest by di<IconManifest >()
90- private val _config by di<Config >()
87+ private val _config by di<ConfigModel >()
9188
92- private val work = Work ().apply {
89+ private val worker = Worker ().apply {
9390 val version = System .getProperty(" os.version" ).toFloatOrNull()
9491 if (System .getProperty(" os.name" ).startsWith(" Windows" ) && version != null && version >= 6.1f ) {
9592 val iTaskbarList3 = CompletableFuture .supplyAsync({ COMRuntime .newInstance(ITaskbarList3 ::class .java) }, comExecutor).join()
@@ -125,8 +122,8 @@ class MainView : View("Blit") {
125122 @Suppress(" UPPER_BOUND_VIOLATED_WARNING" ) add(Pane <Entry <* >>())
126123 @Suppress(" UPPER_BOUND_VIOLATED_WARNING" ) add(Pane <Entry <* >>())
127124 }
128- label(work .name)
129- progressbar(work .progress)
125+ label(worker .name)
126+ progressbar(worker .progress)
130127 }
131128
132129 inner class Pane <T : Entry <T >> : VBox () {
@@ -152,7 +149,7 @@ class MainView : View("Blit") {
152149 left = BreadCrumbBar <String >().apply {
153150 style(true ) { paddingTop = 2.0 }
154151
155- tree.rootProperty().onChange { it?.let { selectedCrumb = BreadCrumbBar .buildTreeModel(* normalizePath(it.value.toString()).split(' /' ).toTypedArray()) } }
152+ tree.rootProperty().onChange { it?.let { selectedCrumb = if (it.value.toString() == " / " ) BreadCrumbBar .buildTreeModel(" / " ) else BreadCrumbBar .buildTreeModel( * normalizePath(it.value.toString()).split(' /' ).toTypedArray(). apply { if ( this [ 0 ].isEmpty()) this [ 0 ] = " / " } ) } }
156153 selectedCrumbProperty().onChange {
157154 val path = StringBuilder ()
158155 var item = it
@@ -171,14 +168,14 @@ class MainView : View("Blit") {
171168 add(tree)
172169 }
173170
174- fun navigate (path : String ) {
171+ private fun navigate (path : String ) {
175172 val normalizedPath = normalizePath(path)
176173
177174 if (::_path .isInitialized && normalizedPath == _path ) return
178175 _path = normalizedPath
179176
180177 source.value?.let { source ->
181- work .launch(locale[" main.navigator.task.navigate.name" , path ]) {
178+ worker .launch(locale[" main.navigator.task.navigate.name" , normalizedPath ]) {
182179 if (source.isValid(normalizedPath)) {
183180 val item = source.get(normalizedPath).item
184181 runLater {
@@ -193,7 +190,7 @@ class MainView : View("Blit") {
193190
194191 fun navigateRelative (path : String ) = navigate(if (path.startsWith(' /' )) path else tree.root.value.toString() + " /$path " )
195192
196- inner class Tree <T : Entry <T >>() : TreeTableView<Entry<T>>() {
193+ inner class Tree <T : Entry <T >> : TreeTableView <Entry <T >>() {
197194 init {
198195 vgrow = Priority .ALWAYS
199196 isShowRoot = false
@@ -213,7 +210,7 @@ class MainView : View("Blit") {
213210 }
214211 column(locale[" main.tree.column.size.title" ], Entry <T >::self) {
215212 tableColumnBaseSetWidth(this , 75.0 )
216- cellFormat { text = if (it.directory) " " else _config .dataSizeUnit.format(it.size) }
213+ cellFormat { text = if (it.directory) " " else _config .dataSizeUnit.value. format(it.size) }
217214 setComparator { a, b -> a.size.compareTo(b.size) }
218215 }
219216 column(locale[" main.tree.column.modified.title" ], Entry <T >::modifyTime) {
@@ -227,7 +224,7 @@ class MainView : View("Blit") {
227224 setOnDragDetected {
228225 startDragAndDrop(TransferMode .MOVE ).apply {
229226 setContent {
230- work .runBlocking(locale[" main.tree.task.download.name" ]) {
227+ worker .runBlocking(locale[" main.tree.task.download.name" ]) {
231228 suspend fun flatten (entry : Entry <T >, path : String? = null): List <File > = if (entry.directory) {
232229 File (tmpdir, entry.name).mkdir()
233230 entry.list().flatMap { flatten(it, " ${path?.let { " $path /" } ? : " " }${entry.name} " ) }
@@ -256,7 +253,7 @@ class MainView : View("Blit") {
256253 setOnKeyPressed {
257254 when (it.code) {
258255 KeyCode .C -> if (it.isControlDown) Clipboard .getSystemClipboard().setContent {
259- work .runBlocking(locale[" main.tree.task.download.name" ]) {
256+ worker .runBlocking(locale[" main.tree.task.download.name" ]) {
260257 suspend fun flatten (entry : Entry <T >, path : String? = null): List <File > = if (entry.directory) {
261258 File (tmpdir, entry.name).mkdir()
262259 entry.list().flatMap { flatten(it, " ${path?.let { " $path /" } ? : " " }${entry.name} " ) }
@@ -271,12 +268,12 @@ class MainView : View("Blit") {
271268 if (hasFiles()) {
272269 val entry = selectionModel.selectedItem.value
273270 if (! entry.directory) TODO ()
274- files.forEach { file -> work .launch(locale[" main.tree.task.upload.name" , file.name]) { FileInputStream (file).use { entry.transferFrom(file.name, it, file.length()) } } }
271+ files.forEach { file -> worker .launch(locale[" main.tree.task.upload.name" , file.name]) { FileInputStream (file).use { entry.transferFrom(file.name, it, file.length()) } } }
275272 }
276273 }
277274 KeyCode .DELETE -> selectionModel.selectedItems.forEach {
278275 val entry = it.value
279- work .launch(locale[" main.tree.task.delete.name" , entry]) {
276+ worker .launch(locale[" main.tree.task.delete.name" , entry]) {
280277 entry.delete()
281278 runLater { populate(it.parent) }
282279 }
@@ -291,7 +288,7 @@ class MainView : View("Blit") {
291288 it.list.firstOrNull { it.value.directory }?.value?.let { navigateRelative(it.name) } ? : if (Desktop .isDesktopSupported()) {
292289 it.list.forEach {
293290 val entry = it.value
294- work .launch(locale[" main.tree.task.download.name" , entry]) { Desktop .getDesktop().open(File (tmpdir, 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.)
291+ worker .launch(locale[" main.tree.task.download.name" , entry]) { Desktop .getDesktop().open(File (tmpdir, 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.)
295292 }
296293 }
297294 }
@@ -301,7 +298,7 @@ class MainView : View("Blit") {
301298 action {
302299 it.list.forEach {
303300 val entry = it.value
304- work .launch(locale[" main.tree.task.delete.name" , entry]) {
301+ worker .launch(locale[" main.tree.task.delete.name" , entry]) {
305302 entry.delete()
306303 runLater { populate(it.parent) }
307304 }
@@ -313,7 +310,7 @@ class MainView : View("Blit") {
313310 }
314311
315312 fun populate (item : TreeItem <Entry <T >>) {
316- work .launch(locale[" main.tree.task.populate.name" , item.value]) {
313+ worker .launch(locale[" main.tree.task.populate.name" , item.value]) {
317314 val children = item.value!! .list()
318315 runLater {
319316 populateTree(item, { entry ->
0 commit comments