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
|
package xyz.atnrch.wrench.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Row
|
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.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.input.InputEntries
|
||||||
import xyz.atnrch.wrench.components.center.output.OutputEntries
|
import xyz.atnrch.wrench.components.center.output.OutputEntries
|
||||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||||
|
@ -11,7 +17,16 @@ fun WatcherDisplay(
|
||||||
watcherManager: WatcherManager
|
watcherManager: WatcherManager
|
||||||
) {
|
) {
|
||||||
Row {
|
Row {
|
||||||
InputEntries(watcherManager)
|
if(watcherManager.getEntries().isEmpty()) {
|
||||||
OutputEntries()
|
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
|
@Composable
|
||||||
fun WrenchScaffold() {
|
fun WrenchScaffold() {
|
||||||
val entries: MutableList<WatcherEntry> = remember { mutableStateListOf() }
|
val entries: MutableMap<Int, WatcherEntry> = remember { mutableStateMapOf() }
|
||||||
val watcher = remember { Watcher(entries) }
|
val watcher = remember { Watcher(entries) }
|
||||||
val watcherManager = remember { WatcherManager(entries) }
|
val watcherManager = remember { WatcherManager(entries) }
|
||||||
var buttonState by remember { mutableStateOf(false) }
|
var buttonState by remember { mutableStateOf(false) }
|
||||||
|
|
|
@ -3,9 +3,10 @@ package xyz.atnrch.wrench.components.debug
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import xyz.atnrch.wrench.components.WatcherTextEntry
|
import xyz.atnrch.wrench.components.WatcherTextEntry
|
||||||
import xyz.atnrch.wrench.watcher.WatcherEntry
|
import xyz.atnrch.wrench.watcher.WatcherEntry
|
||||||
|
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DummyTextEntry() {
|
fun DummyTextEntry(watcherManager: WatcherManager) {
|
||||||
WatcherTextEntry(WatcherEntry(File("/home/aro/IdeaProjects/Wrench/dummy"), arrayListOf()))
|
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.TextUnit
|
||||||
import androidx.compose.ui.unit.TextUnitType
|
import androidx.compose.ui.unit.TextUnitType
|
||||||
import xyz.atnrch.wrench.components.center.dialog.EntryDialog
|
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.ui.Fonts
|
||||||
import xyz.atnrch.wrench.watcher.WatcherEntry
|
import xyz.atnrch.wrench.watcher.WatcherEntry
|
||||||
|
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||||
|
|
||||||
@OptIn(ExperimentalUnitApi::class)
|
@OptIn(ExperimentalUnitApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun WatcherTextEntry(entry: WatcherEntry) {
|
fun WatcherTextEntry(id: Int, entry: WatcherEntry, watcherManager: WatcherManager) {
|
||||||
var dialogState by remember { mutableStateOf(false) }
|
var dialogState by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
|
@ -28,6 +30,8 @@ fun WatcherTextEntry(entry: WatcherEntry) {
|
||||||
),
|
),
|
||||||
modifier = Modifier.clickable {
|
modifier = Modifier.clickable {
|
||||||
dialogState = true
|
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.graphics.RectangleShape
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import xyz.atnrch.wrench.components.WatcherTextEntry
|
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.ui.UIColors
|
||||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||||
|
|
||||||
|
@ -30,10 +30,7 @@ fun InputEntries(
|
||||||
verticalArrangement = Arrangement.spacedBy(15.dp)
|
verticalArrangement = Arrangement.spacedBy(15.dp)
|
||||||
) {
|
) {
|
||||||
watcherManager.getEntries().forEach {
|
watcherManager.getEntries().forEach {
|
||||||
WatcherTextEntry(it)
|
RegisterComposable(it.key) { WatcherTextEntry(it.key, it.value, watcherManager) }
|
||||||
}
|
|
||||||
for (i in 0..5) {
|
|
||||||
DummyTextEntry()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,13 @@ import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.RectangleShape
|
import androidx.compose.ui.graphics.RectangleShape
|
||||||
import androidx.compose.ui.unit.dp
|
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.ui.UIColors
|
||||||
|
import xyz.atnrch.wrench.watcher.WatcherEntry
|
||||||
|
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun OutputEntries() {
|
fun OutputEntries(watcherManager: WatcherManager) {
|
||||||
Box(
|
Box(
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
@ -25,9 +27,7 @@ fun OutputEntries() {
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.spacedBy(15.dp)
|
verticalArrangement = Arrangement.spacedBy(15.dp)
|
||||||
) {
|
) {
|
||||||
for (i in 0..5) {
|
val entry: WatcherEntry? = watcherManager.getFromId(ACTIVE_COMPOSABLE)
|
||||||
DummyTextEntry()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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.nio.file.Files
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class Watcher(private val entries: MutableList<WatcherEntry>) {
|
class Watcher(private val entries: MutableMap<Int, WatcherEntry>) {
|
||||||
companion object {
|
companion object {
|
||||||
var WATCHING = false
|
var WATCHING = false
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class Watcher(private val entries: MutableList<WatcherEntry>) {
|
||||||
while (WATCHING) {
|
while (WATCHING) {
|
||||||
delay(TimeUnit.SECONDS.toMillis(5))
|
delay(TimeUnit.SECONDS.toMillis(5))
|
||||||
val manager = WatcherManager(entries)
|
val manager = WatcherManager(entries)
|
||||||
for (entry: WatcherEntry in manager.getEntries()) {
|
for (entry: WatcherEntry in manager.getEntries().values) {
|
||||||
entry.map.forEach {
|
entry.map.forEach {
|
||||||
Files.copy(entry.file.toPath(), it.toAbsolutePath())
|
Files.copy(entry.file.toPath(), it.toAbsolutePath())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,21 @@ package xyz.atnrch.wrench.watcher
|
||||||
import xyz.atnrch.wrench.logger.Logger
|
import xyz.atnrch.wrench.logger.Logger
|
||||||
import java.io.File
|
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) {
|
fun addFile(file: File) {
|
||||||
val watcherEntry = WatcherEntry(file, arrayListOf())
|
val watcherEntry = WatcherEntry(file, arrayListOf())
|
||||||
entries.add(watcherEntry)
|
currentId += 1
|
||||||
Logger.info("Tracking new file: ${file.name} (${file.absolutePath})")
|
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
|
return entries
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getFromId(id: Int): WatcherEntry? {
|
||||||
|
return entries[id]
|
||||||
|
}
|
||||||
}
|
}
|
Reference in a new issue