Skip to content

Commit

Permalink
Revert "Fixed issue publishing Intellij Plugin"
Browse files Browse the repository at this point in the history
This reverts commit 38c5380.
  • Loading branch information
cjbrooks12 committed Sep 29, 2022
1 parent e44aa46 commit 0e36915
Show file tree
Hide file tree
Showing 25 changed files with 1,540 additions and 8 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
## 2.0.1 - 2022-09-06

- Fixed issue publishing Intellij Plugin

## 2.0.0 - 2022-09-02

- Updates to Kotlin 1.7.10
Expand Down
6 changes: 3 additions & 3 deletions ballast-idea-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ description = "Debugger UI application for Ballast MVI"

dependencies {
// compose Desktop Intellij Plugin
// compileOnly(compose.desktop.currentOs)
// implementation(compose.desktop.components.splitPane)
// implementation(compose.materialIconsExtended)
compileOnly(compose.desktop.currentOs)
implementation(compose.desktop.components.splitPane)
implementation(compose.materialIconsExtended)

// Ktor websocker server
implementation(libs.kotlinx.coroutines.swing)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.copperleaf.ballast.debugger.di

import androidx.compose.runtime.compositionLocalOf
import com.copperleaf.ballast.BallastViewModelConfiguration
import com.copperleaf.ballast.debugger.idea.settings.BallastPluginPrefs
import com.copperleaf.ballast.debugger.idea.settings.BallastPluginPrefsImpl
Expand All @@ -10,6 +11,9 @@ import com.copperleaf.ballast.debugger.ui.debugger.DebuggerViewModel
import com.intellij.openapi.project.Project
import kotlinx.coroutines.CoroutineScope

val LocalProject = compositionLocalOf<Project> { error("LocalProject not provided") }
val LocalInjector = compositionLocalOf<BallastDebuggerInjector> { error("LocalInjector not provided") }

interface BallastDebuggerInjector {
val prefs: BallastPluginPrefs

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.copperleaf.ballast.debugger.idea

class BallastIdeaPlugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.copperleaf.ballast.debugger.idea.base

import androidx.compose.runtime.Composable
import androidx.compose.ui.awt.ComposePanel
import com.copperleaf.ballast.debugger.idea.theme.IdeaPluginTheme
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.ui.content.Content
import com.intellij.ui.content.ContentFactory

abstract class BaseToolWindow : ToolWindowFactory {

override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
val contentFactory = ContentFactory.SERVICE.getInstance()
val content: Content = contentFactory.createContent(
ComposePanel().apply {
setContent {
IdeaPluginTheme(project) {
Content()
}
}
},
"",
false,
)
toolWindow.contentManager.addContent(content)
}

@Composable
abstract fun Content()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.copperleaf.ballast.debugger.idea.settings

import com.copperleaf.ballast.debugger.ui.widgets.ViewModelContentTab

/**
* Save the UI state
* - Divider percentages
Expand All @@ -13,5 +15,6 @@ interface BallastPluginPrefs {
var connectionsPanePercentage: Float
var viewModelsPanePercentage: Float
var eventsPanePercentage: Float
var selectedViewModelContentTab: ViewModelContentTab
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.copperleaf.ballast.debugger.idea.settings

import com.copperleaf.ballast.debugger.idea.base.BasePluginPrefs
import com.copperleaf.ballast.debugger.ui.widgets.ViewModelContentTab
import com.intellij.openapi.project.Project

class BallastPluginPrefsImpl(
Expand All @@ -16,4 +17,5 @@ class BallastPluginPrefsImpl(
override var connectionsPanePercentage: Float by float(CONNECTIONS_DEFAULT_VALUE)
override var viewModelsPanePercentage: Float by float(VIEW_MODELS_DEFAULT_VALUE)
override var eventsPanePercentage: Float by float(EVENTS_DEFAULT_VALUE)
override var selectedViewModelContentTab: ViewModelContentTab by enum(ViewModelContentTab.Inputs, ViewModelContentTab::valueOf)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.copperleaf.ballast.debugger.idea.theme

import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.graphics.Color
import com.copperleaf.ballast.debugger.di.BallastDebuggerInjector
import com.copperleaf.ballast.debugger.di.LocalInjector
import com.copperleaf.ballast.debugger.di.LocalProject
import com.intellij.openapi.project.Project

@Composable
fun IdeaPluginTheme(
project: Project,
darkTheme: Boolean = false,
content: @Composable () -> Unit,
) {
val primaryColor = Color(0xff_9e9e9e)
val secondaryColor = Color(0xff_ffab00)

val materialColors = if (darkTheme) {
darkColors(primary = primaryColor, secondary = secondaryColor)
} else {
lightColors(primary = primaryColor, secondary = secondaryColor)
}

val swingColor = SwingColor()

MaterialTheme(
colors = materialColors.copy(
background = swingColor.background,
onBackground = swingColor.onBackground,
surface = swingColor.background,
onSurface = swingColor.onBackground,
),
typography = typography,
content = {
CompositionLocalProvider(
LocalProject provides project,
LocalInjector provides BallastDebuggerInjector.getInstance(project),
) {
content()
}
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.copperleaf.ballast.debugger.idea.theme

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import com.intellij.ide.ui.LafManager
import com.intellij.ide.ui.LafManagerListener
import com.intellij.openapi.application.ApplicationManager
import javax.swing.UIManager
import java.awt.Color as AWTColor

internal class ThemeChangeListener(
val updateColors: () -> Unit
) : LafManagerListener {
override fun lookAndFeelChanged(source: LafManager) {
updateColors()
}
}

interface SwingColor {
val background: Color
val onBackground: Color
}

@Composable
fun SwingColor(): SwingColor {
val swingColor = remember { SwingColorImpl() }

val messageBus = remember {
ApplicationManager.getApplication().messageBus.connect()
}

remember(messageBus) {
messageBus.subscribe(
LafManagerListener.TOPIC,
ThemeChangeListener(swingColor::updateCurrentColors)
)
}

DisposableEffect(messageBus) {
onDispose {
messageBus.disconnect()
}
}

return swingColor
}

private class SwingColorImpl : SwingColor {
private val _backgroundState: MutableState<Color> = mutableStateOf(getBackgroundColor)
private val _onBackgroundState: MutableState<Color> = mutableStateOf(getOnBackgroundColor)

override val background: Color get() = _backgroundState.value
override val onBackground: Color get() = _onBackgroundState.value

private val getBackgroundColor get() = getColor(BACKGROUND_KEY)
private val getOnBackgroundColor get() = getColor(ON_BACKGROUND_KEY)

fun updateCurrentColors() {
_backgroundState.value = getBackgroundColor
_onBackgroundState.value = getOnBackgroundColor
}

private val AWTColor.asComposeColor: Color get() = Color(red, green, blue, alpha)
private fun getColor(key: String): Color = UIManager.getColor(key).asComposeColor

companion object {
private const val BACKGROUND_KEY = "Panel.background"
private const val ON_BACKGROUND_KEY = "Panel.foreground"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.copperleaf.ballast.debugger.idea.theme

import androidx.compose.material.Typography
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp

val typography = Typography(
body1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp
),
body2 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 14.sp
),
button = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.W500,
fontSize = 14.sp
),
caption = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 12.sp,
),
subtitle1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
color = Color.Gray
),
subtitle2 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
color = Color.Gray
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.copperleaf.ballast.debugger.idea.tool

import androidx.compose.runtime.Composable
import com.copperleaf.ballast.debugger.idea.base.BaseToolWindow
import com.copperleaf.ballast.debugger.ui.debugger.DebuggerUi
import com.intellij.openapi.project.DumbAware

class BallastDebuggerToolWindow : BaseToolWindow(), DumbAware {

@Composable
override fun Content() {
DebuggerUi.run()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.copperleaf.ballast.debugger.ui.debugger

import com.copperleaf.ballast.debugger.idea.settings.BallastPluginPrefsImpl.Companion.CONNECTIONS_DEFAULT_VALUE
import com.copperleaf.ballast.debugger.idea.settings.BallastPluginPrefsImpl.Companion.EVENTS_DEFAULT_VALUE
import com.copperleaf.ballast.debugger.idea.settings.BallastPluginPrefsImpl.Companion.VIEW_MODELS_DEFAULT_VALUE
import com.copperleaf.ballast.debugger.models.BallastApplicationState
import com.copperleaf.ballast.debugger.models.BallastConnectionState
import com.copperleaf.ballast.debugger.models.BallastDebuggerAction
Expand All @@ -9,8 +12,10 @@ import com.copperleaf.ballast.debugger.models.BallastInputState
import com.copperleaf.ballast.debugger.models.BallastSideJobState
import com.copperleaf.ballast.debugger.models.BallastStateSnapshot
import com.copperleaf.ballast.debugger.models.BallastViewModelState
import com.copperleaf.ballast.debugger.ui.widgets.ViewModelContentTab
import io.github.copper_leaf.ballast_idea_plugin.BALLAST_VERSION
import kotlinx.coroutines.flow.MutableSharedFlow
import org.jetbrains.compose.splitpane.SplitPaneState

object DebuggerContract {
data class State constructor(
Expand All @@ -24,6 +29,15 @@ object DebuggerContract {
val focusedConnectionId: String? = null,
val focusedViewModelName: String? = null,
val focusedDebuggerEventUuid: String? = null,

val connectionsPanePercentage: SplitPaneState = SplitPaneState(CONNECTIONS_DEFAULT_VALUE, true),
val connectionsPanePercentageValue: Float = CONNECTIONS_DEFAULT_VALUE,
val viewModelsPanePercentage: SplitPaneState = SplitPaneState(VIEW_MODELS_DEFAULT_VALUE, true),
val viewModelsPanePercentageValue: Float = VIEW_MODELS_DEFAULT_VALUE,
val eventsPanePercentage: SplitPaneState = SplitPaneState(EVENTS_DEFAULT_VALUE, true),
val eventsPanePercentageValue: Float = EVENTS_DEFAULT_VALUE,

val selectedViewModelContentTab: ViewModelContentTab = ViewModelContentTab.Inputs,
) {
val focusedConnection: BallastConnectionState? = applicationState
.connections
Expand Down Expand Up @@ -64,6 +78,12 @@ object DebuggerContract {

data class DebuggerEventReceived(val message: BallastDebuggerEvent) : Inputs()
data class SendDebuggerAction(val action: BallastDebuggerAction) : Inputs()

data class UpdateSelectedViewModelContentTab(val value: ViewModelContentTab) : Inputs()

data class UpdateConnectionsPanePercentageValue(val value: Float) : Inputs()
data class UpdateViewModelsPanePercentageValue(val value: Float) : Inputs()
data class UpdateEventsPanePercentageValue(val value: Float) : Inputs()
}

sealed class Events
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.copperleaf.ballast.debugger.ui.debugger

import androidx.compose.runtime.snapshotFlow
import com.copperleaf.ballast.InputHandler
import com.copperleaf.ballast.InputHandlerScope
import com.copperleaf.ballast.debugger.models.BallastConnectionState
Expand All @@ -9,6 +10,9 @@ import com.copperleaf.ballast.debugger.models.updateConnection
import com.copperleaf.ballast.debugger.models.updateViewModel
import com.copperleaf.ballast.debugger.models.updateWithDebuggerEvent
import com.copperleaf.ballast.debugger.server.BallastDebuggerServerConnection
import com.copperleaf.ballast.observeFlows
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map

class DebuggerInputHandler : InputHandler<
DebuggerContract.Inputs,
Expand All @@ -30,6 +34,23 @@ class DebuggerInputHandler : InputHandler<

server.runServer()
}

observeFlows("SplitPane State Observer") {
listOf(
snapshotFlow { currentStateWhenStarted.connectionsPanePercentage.positionPercentage }
.distinctUntilChanged()
.map { DebuggerContract.Inputs.UpdateConnectionsPanePercentageValue(it) },

snapshotFlow { currentStateWhenStarted.viewModelsPanePercentage.positionPercentage }
.distinctUntilChanged()
.map { DebuggerContract.Inputs.UpdateViewModelsPanePercentageValue(it) },

snapshotFlow { currentStateWhenStarted.eventsPanePercentage.positionPercentage }
.distinctUntilChanged()
.map { DebuggerContract.Inputs.UpdateEventsPanePercentageValue(it) }

)
}
}

is DebuggerContract.Inputs.ConnectionEstablished -> {
Expand Down Expand Up @@ -119,5 +140,18 @@ class DebuggerInputHandler : InputHandler<

currentState.actions.emit(input.action)
}

is DebuggerContract.Inputs.UpdateSelectedViewModelContentTab -> {
updateState { it.copy(selectedViewModelContentTab = input.value) }
}
is DebuggerContract.Inputs.UpdateConnectionsPanePercentageValue -> {
updateState { it.copy(connectionsPanePercentageValue = input.value) }
}
is DebuggerContract.Inputs.UpdateEventsPanePercentageValue -> {
updateState { it.copy(eventsPanePercentageValue = input.value) }
}
is DebuggerContract.Inputs.UpdateViewModelsPanePercentageValue -> {
updateState { it.copy(viewModelsPanePercentageValue = input.value) }
}
}
}
Loading

0 comments on commit 0e36915

Please sign in to comment.