-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix component showcase setup, prevent deadlocks in IJ
* The components showcase dialog setup makes more sense now (started from an action instead of a random button in the toolwindow) * Dialogs don't deadlock the IDE process hard anymore if opened before any other Compose UI is shown (workaround for IJPL-166436) * Jewel actions have been renamed and cleaned up * The whole components showcase modifier setup now makes sense to hoist (and uses the right padding default in standalone) * Icon buttons now allow passing a modifier to the inner icon * Toolbar icons in the showcase look (more) like the IDE ones now
- Loading branch information
Showing
17 changed files
with
289 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 56 additions & 7 deletions
63
...n/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/dialog/ComponentShowcaseDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,88 @@ | ||
package org.jetbrains.jewel.samples.ideplugin.dialog | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.shape.CornerSize | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.DpSize | ||
import androidx.compose.ui.unit.dp | ||
import com.intellij.ide.ui.UISettings | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.application.ModalityState | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.ui.DialogWrapper | ||
import com.intellij.toolWindow.ResizeStripeManager | ||
import com.intellij.util.ui.JBUI | ||
import com.intellij.util.ui.JBUI.CurrentTheme.Toolbar | ||
import java.awt.Dimension | ||
import javax.swing.JComponent | ||
import org.jetbrains.jewel.bridge.JewelComposePanel | ||
import org.jetbrains.jewel.bridge.retrieveArcAsCornerSizeOrDefault | ||
import org.jetbrains.jewel.bridge.theme.default | ||
import org.jetbrains.jewel.bridge.theme.macOs | ||
import org.jetbrains.jewel.bridge.toDpSize | ||
import org.jetbrains.jewel.bridge.toPaddingValues | ||
import org.jetbrains.jewel.foundation.theme.JewelTheme | ||
import org.jetbrains.jewel.samples.showcase.views.ComponentsView | ||
import org.jetbrains.jewel.samples.showcase.views.ComponentsViewModel | ||
import org.jetbrains.jewel.ui.component.styling.IconButtonMetrics | ||
import org.jetbrains.jewel.ui.component.styling.ScrollbarVisibility | ||
import org.jetbrains.jewel.ui.theme.iconButtonStyle | ||
|
||
internal class ComponentShowcaseDialog : DialogWrapper(true) { | ||
internal class ComponentShowcaseDialog(project: Project) : DialogWrapper(project) { | ||
init { | ||
title = "Component Showcase" | ||
ApplicationManager.getApplication() | ||
.invokeLater({ initializeComposeMainDispatcherChecker() }, ModalityState.any()) | ||
|
||
title = "Jewel Components Showcase" | ||
init() | ||
contentPanel.border = JBUI.Borders.empty() | ||
rootPane.border = JBUI.Borders.empty() | ||
} | ||
|
||
override fun createSouthPanel(): JComponent? = null | ||
|
||
override fun createCenterPanel(): JComponent { | ||
val dialogPanel = JewelComposePanel { | ||
val viewModel = | ||
ComponentsViewModel( | ||
alwaysVisibleScrollbarVisibility = ScrollbarVisibility.AlwaysVisible.default(), | ||
whenScrollingScrollbarVisibility = ScrollbarVisibility.WhenScrolling.macOs(), | ||
) | ||
|
||
val iconButtonMetrics = JewelTheme.iconButtonStyle.metrics | ||
val uiSettings = UISettings.Companion.getInstance() | ||
ComponentsView( | ||
viewModel = viewModel, | ||
railNavigationModifier = | ||
Modifier.size(40.dp).padding(start = 0.dp, end = 4.dp, top = 4.dp, bottom = 4.dp), | ||
toolbarButtonMetrics = | ||
remember(uiSettings.compactMode, ResizeStripeManager.isShowNames()) { | ||
iconButtonMetrics.tweak( | ||
minSize = Toolbar.stripeToolbarButtonSize().toDpSize(), | ||
// See com.intellij.openapi.wm.impl.SquareStripeButtonLook.getButtonArc | ||
cornerSize = | ||
retrieveArcAsCornerSizeOrDefault( | ||
"Button.ToolWindow.arc", | ||
CornerSize(if (uiSettings.compactMode) 4.dp else 6.dp), | ||
), | ||
padding = | ||
Toolbar.stripeToolbarButtonIconPadding( | ||
/* compactMode = */ uiSettings.compactMode, | ||
/* showNames = */ ResizeStripeManager.isShowNames(), | ||
) | ||
.toPaddingValues(), | ||
borderWidth = 0.dp, | ||
) | ||
}, | ||
) | ||
} | ||
dialogPanel.preferredSize = Dimension(800, 600) | ||
return dialogPanel | ||
} | ||
|
||
private fun IconButtonMetrics.tweak( | ||
cornerSize: CornerSize = this.cornerSize, | ||
borderWidth: Dp = this.borderWidth, | ||
padding: PaddingValues = this.padding, | ||
minSize: DpSize = this.minSize, | ||
) = IconButtonMetrics(cornerSize, borderWidth, padding, minSize) | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/kotlin/org/jetbrains/jewel/samples/ideplugin/dialog/ComponentShowcaseDialogAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.jetbrains.jewel.samples.ideplugin.dialog | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.application.EDT | ||
import com.intellij.openapi.application.ModalityState | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.project.DumbAwareAction | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
internal class ComponentShowcaseDialogAction : DumbAwareAction() { | ||
init { | ||
ApplicationManager.getApplication() | ||
.invokeLater({ initializeComposeMainDispatcherChecker() }, ModalityState.any()) | ||
} | ||
|
||
override fun actionPerformed(event: AnActionEvent) { | ||
val project = checkNotNull(event.project) { "Project not available" } | ||
val scope = project.service<ProjectScopeProviderService>().scope | ||
|
||
scope.launch(Dispatchers.EDT) { ComponentShowcaseDialog(project).showAndGet() } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/dialog/DialogDeadlockWorkaround.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.jetbrains.jewel.samples.ideplugin.dialog | ||
|
||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.LifecycleRegistry | ||
|
||
/** | ||
* Initializes the MainDispatcherChecker in Compose; this must be called from the UI thread in non-modal state. This is | ||
* a workaround for a freeze in the UI thread that is triggered by using Compose in a dialog before it has been used in | ||
* a non-modal state. | ||
* | ||
* See https://youtrack.jetbrains.com/issue/IJPL-166436 | ||
* | ||
* TODO Delete this when the upstream bug is fixed. | ||
*/ | ||
internal fun initializeComposeMainDispatcherChecker() { | ||
object : LifecycleOwner { | ||
override val lifecycle = LifecycleRegistry(this) | ||
|
||
init { | ||
lifecycle.currentState = Lifecycle.State.STARTED | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...c/main/kotlin/org/jetbrains/jewel/samples/ideplugin/dialog/ProjectScopeProviderService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.jetbrains.jewel.samples.ideplugin.dialog | ||
|
||
import com.intellij.openapi.components.Service | ||
import kotlinx.coroutines.CoroutineScope | ||
|
||
@Service(Service.Level.PROJECT) internal class ProjectScopeProviderService(val scope: CoroutineScope) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
samples/ide-plugin/src/main/resources/messages/JewelBundle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
toolwindow.stripe.JewelDemo=Jewel Demo | ||
action.JewelActionSystemTest.text=Jewel Action System Test | ||
action.JewelWizardDialog.text=Jewel Wizard Dialog | ||
action.JewelComponentShowcaseDialog.text=Jewel Components Showcase | ||
toolwindow.stripe.JewelDemo=Jewel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.