Skip to content

Commit

Permalink
Restore logs selection
Browse files Browse the repository at this point in the history
  • Loading branch information
romainguy committed May 17, 2024
1 parent e0f95c3 commit df99606
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
Binary file modified art/kotlin-explorer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 14 additions & 20 deletions src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.style.TextAlign.Companion.Center
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.*
import androidx.compose.ui.window.WindowPosition.Aligned
import dev.romainguy.kotlin.explorer.Shortcut.*
Expand Down Expand Up @@ -98,7 +99,6 @@ private const val FontSizePresentationMode = 20.0f

private class UiState(val explorerState: ExplorerState, window: ComposeWindow) {
var activeTextArea by mutableStateOf<RSyntaxTextArea?>(null)
var previousActiveTextArea by mutableStateOf<RSyntaxTextArea?>(null)
var status by mutableStateOf("Ready")
var progress by mutableStateOf(1f)
var logs by mutableStateOf(AnnotatedString(""))
Expand Down Expand Up @@ -133,20 +133,10 @@ private class UiState(val explorerState: ExplorerState, window: ComposeWindow) {
}
val focusTracker = object : FocusListener {
override fun focusGained(e: FocusEvent?) {
previousActiveTextArea = activeTextArea
activeTextArea = e?.component as RSyntaxTextArea
}

override fun focusLost(e: FocusEvent?) {
// TODO: Bit of a hack to keep focus on the text areas. Without this, clicking
// the background loses focus, so does opening/closing panels
if (e?.oppositeComponent !is RSyntaxTextArea) {
if (activeTextArea?.isShowing == true) {
activeTextArea?.requestFocusInWindow()
} else {
previousActiveTextArea?.requestFocusInWindow()
}
}
}
}

Expand Down Expand Up @@ -198,11 +188,11 @@ private fun FrameWindowScope.KotlinExplorer(
val sourcePanel: @Composable () -> Unit =
{ SourcePanel(uiState.sourceTextArea, explorerState) }
val byteCodePanel: @Composable () -> Unit =
{ TextPanel(uiState.byteCodeTextArea, explorerState) }
{ TextPanel(uiState.byteCodeTextArea, explorerState, "Byte Code") }
val dexPanel: @Composable () -> Unit =
{ TextPanel(uiState.dexTextArea, explorerState) }
{ TextPanel(uiState.dexTextArea, explorerState, "DEX") }
val oatPanel: @Composable () -> Unit =
{ TextPanel(uiState.oatTextArea, explorerState) }
{ TextPanel(uiState.oatTextArea, explorerState, "OAT") }
var panels by remember { mutableStateOf(explorerState.getPanels(sourcePanel, byteCodePanel, dexPanel, oatPanel)) }

MainMenu(
Expand Down Expand Up @@ -283,6 +273,7 @@ private fun LogsPanel(logs: AnnotatedString) {
Text(
text = logs,
fontFamily = FontFamily.Monospace,
fontSize = 12.sp,
modifier = Modifier
.fillMaxSize()
.background(Color.White)
Expand Down Expand Up @@ -356,12 +347,15 @@ private fun SourcePanel(sourceTextArea: RSyntaxTextArea, explorerState: Explorer
}

@Composable
private fun TextPanel(textArea: RSyntaxTextArea, explorerState: ExplorerState) {
SwingPanel(
modifier = Modifier.fillMaxSize(),
factory = { RTextScrollPane(textArea) },
update = { textArea.updateStyle(explorerState) }
)
private fun TextPanel(textArea: RSyntaxTextArea, explorerState: ExplorerState, title: String) {
Column {
Title(title)
SwingPanel(
modifier = Modifier.fillMaxSize(),
factory = { RTextScrollPane(textArea) },
update = { textArea.updateStyle(explorerState) }
)
}
}

@Composable
Expand Down

0 comments on commit df99606

Please sign in to comment.