Skip to content

Commit 6528a72

Browse files
committed
feat(mpp-idea): use DialogWrapper for IdeaMcpConfigDialog to center in IDE
- Create IdeaMcpConfigDialogWrapper using IntelliJ's DialogWrapper - Dialog now appears centered in the IDE window like IdeaModelConfigDialog - Proper z-index handling when used with SwingPanel components - Update IdeaBottomToolbar to use IdeaMcpConfigDialogWrapper.show() - Mark old IdeaMcpConfigDialog as deprecated
1 parent 0f5fd12 commit 6528a72

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/editor/IdeaBottomToolbar.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ fun IdeaBottomToolbar(
4242
onConfigureClick: () -> Unit = {},
4343
modifier: Modifier = Modifier
4444
) {
45-
var showMcpConfigDialog by remember { mutableStateOf(false) }
4645
Row(
4746
modifier = modifier
4847
.fillMaxWidth()
@@ -81,9 +80,9 @@ fun IdeaBottomToolbar(
8180
horizontalArrangement = Arrangement.spacedBy(4.dp),
8281
verticalAlignment = Alignment.CenterVertically
8382
) {
84-
// MCP Config button - opens MCP configuration dialog
83+
// MCP Config button - opens MCP configuration dialog using DialogWrapper
8584
IconButton(
86-
onClick = { showMcpConfigDialog = true },
85+
onClick = { IdeaMcpConfigDialogWrapper.show(project) },
8786
modifier = Modifier.size(32.dp)
8887
) {
8988
Icon(
@@ -162,12 +161,5 @@ fun IdeaBottomToolbar(
162161
}
163162
}
164163
}
165-
166-
// MCP Configuration Dialog
167-
if (showMcpConfigDialog) {
168-
IdeaMcpConfigDialog(
169-
onDismiss = { showMcpConfigDialog = false }
170-
)
171-
}
172164
}
173165

mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/editor/IdeaMcpConfigDialog.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import androidx.compose.ui.unit.dp
2424
import androidx.compose.ui.unit.sp
2525
import androidx.compose.ui.window.Dialog
2626
import androidx.compose.ui.window.DialogProperties
27+
import com.intellij.openapi.project.Project
28+
import com.intellij.openapi.ui.DialogWrapper
29+
import com.intellij.util.ui.JBUI
2730
import kotlinx.coroutines.flow.distinctUntilChanged
2831
import cc.unitmesh.agent.config.McpLoadingState
2932
import cc.unitmesh.agent.config.McpLoadingStateCallback
@@ -37,8 +40,11 @@ import cc.unitmesh.devins.ui.config.ConfigManager
3740
import kotlinx.coroutines.launch
3841
import kotlinx.serialization.encodeToString
3942
import kotlinx.serialization.json.Json
43+
import org.jetbrains.jewel.bridge.compose
4044
import org.jetbrains.jewel.foundation.theme.JewelTheme
4145
import org.jetbrains.jewel.ui.component.*
46+
import java.awt.Dimension
47+
import javax.swing.JComponent
4248

4349
// JSON serialization helpers
4450
private val json = Json {
@@ -63,6 +69,43 @@ private fun deserializeMcpConfig(jsonString: String): Result<Map<String, McpServ
6369
}
6470
}
6571

72+
/**
73+
* DialogWrapper for MCP configuration that uses IntelliJ's native dialog system.
74+
* This ensures proper z-index handling and centers the dialog in the IDE window.
75+
*/
76+
class IdeaMcpConfigDialogWrapper(
77+
private val project: Project?
78+
) : DialogWrapper(project) {
79+
80+
init {
81+
title = "MCP Configuration"
82+
init()
83+
contentPanel.border = JBUI.Borders.empty()
84+
rootPane.border = JBUI.Borders.empty()
85+
}
86+
87+
override fun createSouthPanel(): JComponent? = null
88+
89+
override fun createCenterPanel(): JComponent {
90+
val dialogPanel = compose {
91+
IdeaMcpConfigDialogContent(onDismiss = { close(CANCEL_EXIT_CODE) })
92+
}
93+
dialogPanel.preferredSize = Dimension(600, 600)
94+
return dialogPanel
95+
}
96+
97+
companion object {
98+
/**
99+
* Show the MCP configuration dialog.
100+
* @return true if the dialog was closed with OK, false otherwise
101+
*/
102+
fun show(project: Project?): Boolean {
103+
val dialog = IdeaMcpConfigDialogWrapper(project)
104+
return dialog.showAndGet()
105+
}
106+
}
107+
}
108+
66109
/**
67110
* MCP Configuration Dialog for IntelliJ IDEA.
68111
*
@@ -73,6 +116,8 @@ private fun deserializeMcpConfig(jsonString: String): Result<Map<String, McpServ
73116
* - Incremental MCP server loading
74117
*
75118
* Styled to match IdeaModelConfigDialog for consistency.
119+
*
120+
* @deprecated Use IdeaMcpConfigDialogWrapper.show() instead for proper z-index handling with SwingPanel.
76121
*/
77122
@Composable
78123
fun IdeaMcpConfigDialog(

0 commit comments

Comments
 (0)