Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

233 - Fix Jewel 0.12 Api usage, rollback to compose Splitpane, add InfoPanelConent #15

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ fun Project.configureGradleIntellijPlugin(packageSearchExtension: PackageSearchE
relocate("io.ktor", "shadow.io.ktor")
relocate("kotlinx.serialization", "shadow.kotlinx.serialization")
relocate("kotlinx.datetime", "shadow.kotlinx.datetime")
relocate("androidx", "shadow.androidx")
relocate("org.jetbrains.jewel", "shadow.org.jetbrains.jewel")
relocate("org.jetbrains.compose", "shadow.org.jetbrains.compose")
exclude {
it.name.containsAny(packageSearchExtension.librariesToDelete.get())
&& !it.name.containsAny(packageSearchExtension.librariesToKeep.get())
Expand All @@ -43,4 +40,4 @@ fun Project.configureGradleIntellijPlugin(packageSearchExtension: PackageSearchE
}
}
}
}
}
2 changes: 2 additions & 0 deletions packagesearch.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ ij-platform-ide-core = { module = "com.jetbrains.intellij.platform:ide-core", ve
ij-platform-ide-impl = { module = "com.jetbrains.intellij.platform:ide-impl", version.ref = "idea" }
jewel-ui = { module = "org.jetbrains.jewel:jewel-ui", version.ref = "jewel" }
jewel-foundation = { module = "org.jetbrains.jewel:jewel-foundation", version.ref = "jewel" }
jewel-standalone = { module= "org.jetbrains.jewel:jewel-int-ui-standalone", version.ref = "jewel" }
jewel-bridge-ij232 = { module = "org.jetbrains.jewel:jewel-ide-laf-bridge", version.ref = "jewel-bridge-232" }
jewel-bridge-ij233 = { module = "org.jetbrains.jewel:jewel-ide-laf-bridge", version.ref = "jewel-bridge-233" }
compose-desktop-components-splitpane = { module = "org.jetbrains.compose.components:components-splitpane", version.ref = "composeDesktop" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" }
Expand Down
6 changes: 5 additions & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ dependencies {
implementation(compose.desktop.macos_arm64)
implementation(compose.desktop.macos_x64)
implementation(compose.desktop.windows_x64)
implementation(packageSearchCatalog.kotlinx.serialization.core)
implementation(packageSearchCatalog.jewel.bridge.ij233)
implementation(packageSearchCatalog.kotlinx.serialization.core)
implementation(packageSearchCatalog.compose.desktop.components.splitpane){
exclude(group = "org.jetbrains.compose.runtime")
exclude(group = "org.jetbrains.compose.foundation")
}
implementation(packageSearchCatalog.ktor.client.logging)
implementation(packageSearchCatalog.packagesearch.api.models)
implementation(projects.plugin.gradle.base)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jetbrains.packagesearch.plugin.ui

import androidx.compose.ui.graphics.Color
import com.jetbrains.packagesearch.plugin.ui.bridge.pickComposeColorFromLaf

object PackageSearchColors {
object Backgrounds {
fun packageItemHeader(): Color =
pickComposeColorFromLaf("ToolWindow.HeaderTab.selectedInactiveBackground")


fun attributeBadge() = packageItemHeader()

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ object PackageSearchMetrics {
metrics.trackPadding.calculateEndPadding(LocalLayoutDirection.current)
}

object Splitpane {

val minWidth: Dp = 300.dp
const val firstSplitterPositionPercentage = .20f

const val secondSplittePositionPercentage = .80f
}

object Popups {

val minWidth: Dp = 50.dp
Expand Down Expand Up @@ -54,5 +62,4 @@ object PackageSearchMetrics {
}
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.jetbrains.packagesearch.plugin.ui

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import com.intellij.ui.JBColor
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule
import com.jetbrains.packagesearch.plugin.ui.bridge.packageSearchSplitter
import com.jetbrains.packagesearch.plugin.ui.model.ToolWindowViewModel
import com.jetbrains.packagesearch.plugin.ui.model.packageslist.PackageListItemEvent
import com.jetbrains.packagesearch.plugin.ui.panels.packages.PackageSearchCentralPanel
import com.jetbrains.packagesearch.plugin.ui.panels.side.PackageSearchInfoPanel
import com.jetbrains.packagesearch.plugin.ui.panels.tree.PackageSearchModulesTree
import org.jetbrains.jewel.ui.component.HorizontalSplitLayout
import org.jetbrains.compose.splitpane.HorizontalSplitPane
import org.jetbrains.jewel.bridge.toComposeColor
import org.jetbrains.jewel.foundation.theme.JewelTheme

@Composable
fun PackageSearchPackagePanel(
Expand All @@ -16,19 +25,31 @@ fun PackageSearchPackagePanel(
onLinkClick: (String) -> Unit,
onPackageEvent: (PackageListItemEvent) -> Unit,
) {
HorizontalSplitLayout(
first = { PackageSearchModulesTree(it, onSelectionModulesSelectionChanged) },
second = {
val toolWindowsViewModel = viewModel<ToolWindowViewModel>()

val splitPaneState by remember { toolWindowsViewModel.firstSplitPaneState }
val innerSplitPaneState by remember { toolWindowsViewModel.secondSplitPaneState }
val splitterColor by remember(JewelTheme.isDark) { mutableStateOf(JBColor.border().toComposeColor()) }

HorizontalSplitPane(Modifier.fillMaxSize(), splitPaneState) {
first(PackageSearchMetrics.Splitpane.minWidth) {
PackageSearchModulesTree(Modifier, onSelectionModulesSelectionChanged)
}
packageSearchSplitter(splitterColor)
second {
if (isInfoPanelOpen) {
HorizontalSplitLayout(
modifier = it,
initialDividerPosition = 700.dp,
first = { PackageSearchCentralPanel(it, onLinkClick) },
second = { PackageSearchInfoPanel(it, onLinkClick, onPackageEvent) },
maxRatio = 0.8f
)
} else PackageSearchCentralPanel(it, onLinkClick)
},
minRatio = 0.1f,
)
HorizontalSplitPane(Modifier.fillMaxSize(), innerSplitPaneState) {
first(PackageSearchMetrics.Splitpane.minWidth) {
PackageSearchCentralPanel(onLinkClick = onLinkClick)
}
packageSearchSplitter(splitterColor)
second(PackageSearchMetrics.Splitpane.minWidth) {
PackageSearchInfoPanel(onLinkClick = onLinkClick, onPackageEvent = onPackageEvent)
}
}

} else PackageSearchCentralPanel(onLinkClick = onLinkClick)
}
}
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.jetbrains.packagesearch.plugin.ui.bridge

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.onClick
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
Expand All @@ -15,8 +24,11 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import com.intellij.icons.AllIcons
import com.jetbrains.packagesearch.plugin.ui.PackageSearchColors
import com.jetbrains.packagesearch.plugin.ui.PackageSearchMetrics
import java.awt.Cursor
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.foundation.theme.LocalTextStyle
import org.jetbrains.jewel.ui.component.DropdownLink
Expand All @@ -25,6 +37,7 @@ import org.jetbrains.jewel.ui.component.IconButton
import org.jetbrains.jewel.ui.component.MenuScope
import org.jetbrains.jewel.ui.component.PopupMenu
import org.jetbrains.jewel.ui.component.Text
import org.jetbrains.compose.splitpane.SplitPaneScope

@Composable
fun LabelInfo(
Expand Down Expand Up @@ -130,3 +143,74 @@ internal fun PackageActionPopup(
}
}
}


internal fun SplitPaneScope.packageSearchSplitter(
splitterColor: Color,
cursor: PointerIcon = PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR)),
hidden: Boolean = false,
) {
splitter {
visiblePart {
if (!hidden) {
Box(
modifier = Modifier
.fillMaxHeight()
.width(1.dp)
.background(splitterColor),
)
}
}
handle {
if (!hidden) {
Box(
modifier = Modifier
.fillMaxHeight()
.width(8.dp)
.markAsHandle()
.pointerHoverIcon(cursor),
)
}
}
}
}


@Composable
internal fun AttributeBadge(text: String, onClick: () -> Unit) {
val isDark = JewelTheme.isDark
val background = remember(isDark) {
PackageSearchColors.Backgrounds.attributeBadge()
}

Box(
modifier = Modifier
.background(color = background, shape = RoundedCornerShape(12.dp))
.pointerHoverIcon(PointerIcon(Cursor(Cursor.HAND_CURSOR)))
.onClick { onClick() },
) {
Text(
modifier = Modifier.padding(horizontal = 8.dp, vertical = 2.dp), text = text,
)
}

}

//@Preview
//@Composable
//internal fun AttributeBadgePreview() {
// Column(modifier = Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
// IntUiTheme {
// Box(Modifier.background(LocalGlobalColors.current.paneBackground).padding(16.dp)) {
// AttributeBadge(text = "Android") {}
// }
// }
// IntUiTheme(true) {
// Box(Modifier.background(LocalGlobalColors.current.paneBackground).padding(16.dp)) {
// AttributeBadge(text = "Android") {}
// }
// }
// }
//
//
//}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ internal fun PackageSearchTabStyle(): TabStyle {
underlineThickness = current.metrics.underlineThickness,
tabPadding = current.metrics.tabPadding,
tabHeight = PackageSearchMetrics.searchBarHeight,
tabContentSpacing = 0.dp,
closeContentGap = current.metrics.closeContentGap,
),
icons = current.icons,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ fun isLightTheme(): Boolean {

private fun Color.getBrightness() = (red * 299 + green * 587 + blue * 114) / 1000

fun Modifier.pointerChangeToHandModifier() = this.pointerHoverIcon(PointerIcon(Cursor(Cursor.HAND_CURSOR)))
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.jetbrains.packagesearch.plugin.ui.model

import androidx.compose.runtime.mutableStateOf
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.Service.Level
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.jetbrains.packagesearch.plugin.PackageSearchBundle.message
import com.jetbrains.packagesearch.plugin.core.utils.smartModeFlow
import com.jetbrains.packagesearch.plugin.ui.PackageSearchMetrics
import com.jetbrains.packagesearch.plugin.ui.bridge.openLinkInBrowser
import com.jetbrains.packagesearch.plugin.ui.model.tree.TreeViewModel
import com.jetbrains.packagesearch.plugin.utils.PackageSearchProjectService
Expand All @@ -19,10 +21,25 @@ import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.retry
import kotlinx.coroutines.flow.stateIn
import org.jetbrains.compose.splitpane.SplitPaneState

@Service(Level.PROJECT)
class ToolWindowViewModel(project: Project, private val viewModelScope: CoroutineScope) {


val firstSplitPaneState = mutableStateOf(
SplitPaneState(
initialPositionPercentage = PackageSearchMetrics.Splitpane.firstSplitterPositionPercentage,
moveEnabled = true,
)
)
val secondSplitPaneState = mutableStateOf(
SplitPaneState(
initialPositionPercentage = PackageSearchMetrics.Splitpane.secondSplittePositionPercentage,
moveEnabled = true,
)
)

fun openLinkInBrowser(url: String) {
viewModelScope.openLinkInBrowser(url)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ internal val Project.isProjectImportingFlow
trySend(false)
}
}
}.withInitialValue(false)
}.withInitialValue(false)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jetbrains.packagesearch.plugin.ui.model.infopanel

import com.jetbrains.packagesearch.plugin.core.data.IconProvider
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModuleVariant
import com.jetbrains.packagesearch.plugin.ui.model.packageslist.PackageListItem

sealed interface InfoPanelContent {
Expand Down Expand Up @@ -140,4 +141,21 @@ sealed interface InfoPanelContent {
}
}

sealed interface Attributes : InfoPanelContent{
val attributes: List<PackageSearchModuleVariant.Attribute>

data class FromVariant(
override val tabTitle: String,
val variantName: String,
override val attributes: List<PackageSearchModuleVariant.Attribute>,
) : Attributes

data class FromSearch(
override val tabTitle: String,
override val attributes: List<PackageSearchModuleVariant.Attribute>,
val defaultSourceSet: String,
val additionalSourceSets: List<String>,
) : Attributes
}

}
Loading