feat: guess I can get the selected file from button now?
This commit is contained in:
parent
ebf9714183
commit
4189b304d8
9 changed files with 63 additions and 22 deletions
|
@ -1,7 +1,13 @@
|
|||
package xyz.atnrch.wrench.components
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import xyz.atnrch.wrench.components.center.input.InputEntries
|
||||
import xyz.atnrch.wrench.components.center.output.OutputEntries
|
||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||
|
@ -11,7 +17,16 @@ fun WatcherDisplay(
|
|||
watcherManager: WatcherManager
|
||||
) {
|
||||
Row {
|
||||
InputEntries(watcherManager)
|
||||
OutputEntries()
|
||||
if(watcherManager.getEntries().isEmpty()) {
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.fillMaxWidth().fillMaxHeight()
|
||||
) {
|
||||
Text("Add a file to start...")
|
||||
}
|
||||
} else {
|
||||
InputEntries(watcherManager)
|
||||
OutputEntries(watcherManager)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import xyz.atnrch.wrench.watcher.WatcherManager
|
|||
|
||||
@Composable
|
||||
fun WrenchScaffold() {
|
||||
val entries: MutableList<WatcherEntry> = remember { mutableStateListOf() }
|
||||
val entries: MutableMap<Int, WatcherEntry> = remember { mutableStateMapOf() }
|
||||
val watcher = remember { Watcher(entries) }
|
||||
val watcherManager = remember { WatcherManager(entries) }
|
||||
var buttonState by remember { mutableStateOf(false) }
|
||||
|
|
|
@ -3,9 +3,10 @@ package xyz.atnrch.wrench.components.debug
|
|||
import androidx.compose.runtime.Composable
|
||||
import xyz.atnrch.wrench.components.WatcherTextEntry
|
||||
import xyz.atnrch.wrench.watcher.WatcherEntry
|
||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||
import java.io.File
|
||||
|
||||
@Composable
|
||||
fun DummyTextEntry() {
|
||||
WatcherTextEntry(WatcherEntry(File("/home/aro/IdeaProjects/Wrench/dummy"), arrayListOf()))
|
||||
fun DummyTextEntry(watcherManager: WatcherManager) {
|
||||
WatcherTextEntry(0, WatcherEntry(File("/home/aro/IdeaProjects/Wrench/dummy"), arrayListOf()), watcherManager)
|
||||
}
|
|
@ -11,12 +11,14 @@ import androidx.compose.ui.unit.ExperimentalUnitApi
|
|||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.TextUnitType
|
||||
import xyz.atnrch.wrench.components.center.dialog.EntryDialog
|
||||
import xyz.atnrch.wrench.registery.ACTIVE_COMPOSABLE
|
||||
import xyz.atnrch.wrench.ui.Fonts
|
||||
import xyz.atnrch.wrench.watcher.WatcherEntry
|
||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||
|
||||
@OptIn(ExperimentalUnitApi::class)
|
||||
@Composable
|
||||
fun WatcherTextEntry(entry: WatcherEntry) {
|
||||
fun WatcherTextEntry(id: Int, entry: WatcherEntry, watcherManager: WatcherManager) {
|
||||
var dialogState by remember { mutableStateOf(false) }
|
||||
|
||||
Text(
|
||||
|
@ -28,6 +30,8 @@ fun WatcherTextEntry(entry: WatcherEntry) {
|
|||
),
|
||||
modifier = Modifier.clickable {
|
||||
dialogState = true
|
||||
ACTIVE_COMPOSABLE = id
|
||||
println("PATH IS ${watcherManager.getFromId(ACTIVE_COMPOSABLE)!!.file.path}")
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.graphics.RectangleShape
|
||||
import androidx.compose.ui.unit.dp
|
||||
import xyz.atnrch.wrench.components.WatcherTextEntry
|
||||
import xyz.atnrch.wrench.components.debug.DummyTextEntry
|
||||
import xyz.atnrch.wrench.registery.RegisterComposable
|
||||
import xyz.atnrch.wrench.ui.UIColors
|
||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||
|
||||
|
@ -30,10 +30,7 @@ fun InputEntries(
|
|||
verticalArrangement = Arrangement.spacedBy(15.dp)
|
||||
) {
|
||||
watcherManager.getEntries().forEach {
|
||||
WatcherTextEntry(it)
|
||||
}
|
||||
for (i in 0..5) {
|
||||
DummyTextEntry()
|
||||
RegisterComposable(it.key) { WatcherTextEntry(it.key, it.value, watcherManager) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,13 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.RectangleShape
|
||||
import androidx.compose.ui.unit.dp
|
||||
import xyz.atnrch.wrench.components.debug.DummyTextEntry
|
||||
import xyz.atnrch.wrench.registery.ACTIVE_COMPOSABLE
|
||||
import xyz.atnrch.wrench.ui.UIColors
|
||||
import xyz.atnrch.wrench.watcher.WatcherEntry
|
||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||
|
||||
@Composable
|
||||
fun OutputEntries() {
|
||||
fun OutputEntries(watcherManager: WatcherManager) {
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier
|
||||
|
@ -25,9 +27,7 @@ fun OutputEntries() {
|
|||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(15.dp)
|
||||
) {
|
||||
for (i in 0..5) {
|
||||
DummyTextEntry()
|
||||
}
|
||||
val entry: WatcherEntry? = watcherManager.getFromId(ACTIVE_COMPOSABLE)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package xyz.atnrch.wrench.registery
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
val REGISTRY: HashMap<Int, @Composable () -> Unit> = hashMapOf()
|
||||
var ACTIVE_COMPOSABLE = -1
|
||||
|
||||
@Composable
|
||||
fun RegisterComposable(id: Int, composable: @Composable () -> Unit) {
|
||||
REGISTRY[id] = composable
|
||||
composable.invoke()
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun GetActiveComposable(): Int {
|
||||
return ACTIVE_COMPOSABLE
|
||||
}
|
|
@ -6,7 +6,7 @@ import xyz.atnrch.wrench.logger.Logger
|
|||
import java.nio.file.Files
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class Watcher(private val entries: MutableList<WatcherEntry>) {
|
||||
class Watcher(private val entries: MutableMap<Int, WatcherEntry>) {
|
||||
companion object {
|
||||
var WATCHING = false
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class Watcher(private val entries: MutableList<WatcherEntry>) {
|
|||
while (WATCHING) {
|
||||
delay(TimeUnit.SECONDS.toMillis(5))
|
||||
val manager = WatcherManager(entries)
|
||||
for (entry: WatcherEntry in manager.getEntries()) {
|
||||
for (entry: WatcherEntry in manager.getEntries().values) {
|
||||
entry.map.forEach {
|
||||
Files.copy(entry.file.toPath(), it.toAbsolutePath())
|
||||
}
|
||||
|
|
|
@ -3,14 +3,21 @@ package xyz.atnrch.wrench.watcher
|
|||
import xyz.atnrch.wrench.logger.Logger
|
||||
import java.io.File
|
||||
|
||||
class WatcherManager(private val entries: MutableList<WatcherEntry>) {
|
||||
class WatcherManager(private val entries: MutableMap<Int, WatcherEntry>) {
|
||||
private var currentId: Int = -1
|
||||
|
||||
fun addFile(file: File) {
|
||||
val watcherEntry = WatcherEntry(file, arrayListOf())
|
||||
entries.add(watcherEntry)
|
||||
Logger.info("Tracking new file: ${file.name} (${file.absolutePath})")
|
||||
currentId += 1
|
||||
entries[currentId] = (watcherEntry)
|
||||
Logger.info("Tracking new file:\n ID: $currentId\n Name: ${file.name}\n Path: ${file.absolutePath}")
|
||||
}
|
||||
|
||||
fun getEntries(): MutableList<WatcherEntry> {
|
||||
fun getEntries(): MutableMap<Int, WatcherEntry> {
|
||||
return entries
|
||||
}
|
||||
|
||||
fun getFromId(id: Int): WatcherEntry? {
|
||||
return entries[id]
|
||||
}
|
||||
}
|
Reference in a new issue