feat: current selected file is now displayed on second panel

This commit is contained in:
aro 2022-11-27 16:43:05 +01:00
parent 4189b304d8
commit 62731eb74d
11 changed files with 140 additions and 35 deletions

View file

@ -1,23 +1,29 @@
package xyz.atnrch.wrench.components
import androidx.compose.foundation.interaction.MutableInteractionSource
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.runtime.*
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
import java.io.File
@Composable
fun WatcherDisplay(
watcherManager: WatcherManager
) {
var currentClick by remember { mutableStateOf(-1) }
val interactionSource = remember { MutableInteractionSource() }
Row {
if(watcherManager.getEntries().isEmpty()) {
if (watcherManager.getEntries().isEmpty()) {
watcherManager.addFile(File("/home/aro/IdeaProjects/Wrench/dummy"))
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxWidth().fillMaxHeight()
@ -25,8 +31,8 @@ fun WatcherDisplay(
Text("Add a file to start...")
}
} else {
InputEntries(watcherManager)
OutputEntries(watcherManager)
InputEntries(watcherManager, interactionSource) { currentClick = it }
OutputEntries(watcherManager, currentClick)
}
}
}

View file

@ -2,6 +2,8 @@ package xyz.atnrch.wrench.components
import androidx.compose.material.Scaffold
import androidx.compose.runtime.*
import xyz.atnrch.wrench.components.center.AddButton
import xyz.atnrch.wrench.components.top.TopBar
import xyz.atnrch.wrench.watcher.Watcher
import xyz.atnrch.wrench.watcher.WatcherEntry
import xyz.atnrch.wrench.watcher.WatcherManager

View file

@ -1,12 +1,26 @@
package xyz.atnrch.wrench.components.debug
package xyz.atnrch.wrench.components.center
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.runtime.Composable
import xyz.atnrch.wrench.components.WatcherTextEntry
import xyz.atnrch.wrench.registery.RegisterComposable
import xyz.atnrch.wrench.watcher.WatcherEntry
import xyz.atnrch.wrench.watcher.WatcherManager
import java.io.File
@Composable
fun DummyTextEntry(watcherManager: WatcherManager) {
WatcherTextEntry(0, WatcherEntry(File("/home/aro/IdeaProjects/Wrench/dummy"), arrayListOf()), watcherManager)
fun DummyTextEntry(
watcherManager: WatcherManager,
interactionSource: MutableInteractionSource,
onEntrySelected: (id: Int) -> Unit
) {
val id = 0
RegisterComposable(id) {
WatcherTextEntry(
id,
WatcherEntry(File("/home/aro/IdeaProjects/Wrench/dummy"), arrayListOf()),
watcherManager,
onEntrySelected,
interactionSource
)
}
}

View file

@ -1,4 +1,4 @@
package xyz.atnrch.wrench.components
package xyz.atnrch.wrench.components.center
import androidx.compose.ui.awt.ComposeWindow
import java.io.File

View file

@ -1,4 +1,4 @@
package xyz.atnrch.wrench.components
package xyz.atnrch.wrench.components.center
import androidx.compose.foundation.layout.size
import androidx.compose.material.FloatingActionButton

View file

@ -1,11 +1,14 @@
package xyz.atnrch.wrench.components
package xyz.atnrch.wrench.components.center
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.PointerMatcher
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.onClick
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerButton
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.ExperimentalUnitApi
import androidx.compose.ui.unit.TextUnit
@ -16,23 +19,44 @@ import xyz.atnrch.wrench.ui.Fonts
import xyz.atnrch.wrench.watcher.WatcherEntry
import xyz.atnrch.wrench.watcher.WatcherManager
@OptIn(ExperimentalUnitApi::class)
@OptIn(ExperimentalUnitApi::class, ExperimentalFoundationApi::class)
@Composable
fun WatcherTextEntry(id: Int, entry: WatcherEntry, watcherManager: WatcherManager) {
fun WatcherTextEntry(
id: Int,
entry: WatcherEntry,
watcherManager: WatcherManager,
onEntrySelected: (id: Int) -> Unit,
interactionSource: MutableInteractionSource,
) {
var dialogState by remember { mutableStateOf(false) }
Text(
text = "${entry.file.absolutePath}",
style = TextStyle(
color = Color.Black,
color = if(ACTIVE_COMPOSABLE == id) Color.Red else Color.Black,
fontSize = TextUnit(15F, TextUnitType.Sp),
fontFamily = Fonts.ROBOTO_REGULAR
),
modifier = Modifier.clickable {
dialogState = true
ACTIVE_COMPOSABLE = id
println("PATH IS ${watcherManager.getFromId(ACTIVE_COMPOSABLE)!!.file.path}")
}
modifier = Modifier
.onClick(
matcher = PointerMatcher.mouse(PointerButton.Primary),
interactionSource = interactionSource,
onClick = {
println("Active composable ID was $ACTIVE_COMPOSABLE")
ACTIVE_COMPOSABLE = id
println("Active composable ID is now $ACTIVE_COMPOSABLE")
if (ACTIVE_COMPOSABLE == id) {
onEntrySelected.invoke(id)
}
}
)
.onClick(
matcher = PointerMatcher.mouse(PointerButton.Secondary),
onClick = {
dialogState = true
println("PATH IS ${watcherManager.getFromId(ACTIVE_COMPOSABLE)!!.file.path}")
}
)
)
if (dialogState) {

View file

@ -3,6 +3,7 @@ package xyz.atnrch.wrench.components.center.dialog
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Button
import androidx.compose.material.Icon
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
@ -59,12 +60,19 @@ fun EntryDialog(
modifier = Modifier.size(45.dp)
)
Spacer(Modifier.width(75.dp))
Icon(
Icons.Filled.Settings,
tint = Color.Black,
contentDescription = "Entry Settings...",
modifier = Modifier.size(45.dp)
)
Button(
onClick = {
},
shape = CircleShape
) {
Icon(
Icons.Filled.Settings,
tint = Color.Black,
contentDescription = "Entry Settings...",
modifier = Modifier.size(45.dp)
)
}
}
}

View file

@ -2,20 +2,23 @@ package xyz.atnrch.wrench.components.center.input
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
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.WatcherTextEntry
import xyz.atnrch.wrench.components.center.WatcherTextEntry
import xyz.atnrch.wrench.registery.RegisterComposable
import xyz.atnrch.wrench.ui.UIColors
import xyz.atnrch.wrench.watcher.WatcherManager
@Composable
fun InputEntries(
watcherManager: WatcherManager
watcherManager: WatcherManager,
interactionSource: MutableInteractionSource,
onEntryClick: (id: Int) -> Unit
) {
Box(
contentAlignment = Alignment.Center,
@ -30,7 +33,15 @@ fun InputEntries(
verticalArrangement = Arrangement.spacedBy(15.dp)
) {
watcherManager.getEntries().forEach {
RegisterComposable(it.key) { WatcherTextEntry(it.key, it.value, watcherManager) }
RegisterComposable(it.key) {
WatcherTextEntry(
it.key,
it.value,
watcherManager,
onEntryClick,
interactionSource
)
}
}
}
}

View file

@ -3,18 +3,26 @@ package xyz.atnrch.wrench.components.center.output
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PostAdd
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.dp
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(watcherManager: WatcherManager) {
fun OutputEntries(
watcherManager: WatcherManager,
currentSelectedInputId: Int
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
@ -27,7 +35,36 @@ fun OutputEntries(watcherManager: WatcherManager) {
Column(
verticalArrangement = Arrangement.spacedBy(15.dp)
) {
val entry: WatcherEntry? = watcherManager.getFromId(ACTIVE_COMPOSABLE)
val entry: WatcherEntry? = watcherManager.getFromId(currentSelectedInputId)
if (entry != null) {
if (entry.map.isEmpty()) {
Box(
contentAlignment = Alignment.Center
) {
Column (
verticalArrangement = Arrangement.SpaceEvenly,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text("No output")
Spacer(Modifier.height(28.dp))
Text("CURRENT SELECTED FILE IS: ${entry.file.absolutePath}")
Spacer(Modifier.height(28.dp))
Button(
onClick = {
println("test")
}
) {
Icon(
Icons.Filled.PostAdd,
tint = Color.White,
contentDescription = "Add",
modifier = Modifier.size(28.dp)
)
}
}
}
}
}
}
}
}

View file

@ -1,4 +1,4 @@
package xyz.atnrch.wrench.components
package xyz.atnrch.wrench.components.top
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize

View file

@ -9,7 +9,7 @@ class WatcherManager(private val entries: MutableMap<Int, WatcherEntry>) {
fun addFile(file: File) {
val watcherEntry = WatcherEntry(file, arrayListOf())
currentId += 1
entries[currentId] = (watcherEntry)
entries[currentId] = watcherEntry
Logger.info("Tracking new file:\n ID: $currentId\n Name: ${file.name}\n Path: ${file.absolutePath}")
}
@ -18,6 +18,9 @@ class WatcherManager(private val entries: MutableMap<Int, WatcherEntry>) {
}
fun getFromId(id: Int): WatcherEntry? {
if (id == -1) {
return null
}
return entries[id]
}
}