Skip to content

Commit 8aa02ce

Browse files
authored
Merge pull request #28 from skydoves/feature/windowtool-header-guide
Enhance the window tool header guides
2 parents 492e479 + 1ead108 commit 8aa02ce

File tree

2 files changed

+60
-12
lines changed

2 files changed

+60
-12
lines changed

compose-stability-analyzer-idea/src/main/kotlin/com/skydoves/compose/stability/idea/toolwindow/StabilityNodeData.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public sealed class StabilityNodeData {
6060
public data class EmptyMessage(
6161
val message: String,
6262
) : StabilityNodeData()
63+
64+
/**
65+
* Clickable GitHub link node
66+
*/
67+
public data class GitHubLink(
68+
val text: String,
69+
val url: String,
70+
) : StabilityNodeData()
6371
}
6472

6573
/**

compose-stability-analyzer-idea/src/main/kotlin/com/skydoves/compose/stability/idea/toolwindow/StabilityToolWindow.kt

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.skydoves.compose.stability.idea.toolwindow
1717

1818
import com.intellij.icons.AllIcons
19+
import com.intellij.ide.BrowserUtil
1920
import com.intellij.openapi.actionSystem.ActionManager
2021
import com.intellij.openapi.actionSystem.ActionPlaces
2122
import com.intellij.openapi.actionSystem.AnAction
@@ -84,14 +85,25 @@ public class StabilityToolWindow(private val project: Project) {
8485
updateDetailsPanel(node)
8586
}
8687

87-
// Add double-click listener for navigation
88+
// Add double-click listener for navigation and single-click for GitHub links
8889
tree.addMouseListener(object : java.awt.event.MouseAdapter() {
8990
override fun mouseClicked(e: java.awt.event.MouseEvent) {
91+
val node = tree.lastSelectedPathComponent as? DefaultMutableTreeNode
92+
93+
// Handle single click on GitHub links
94+
if (e.clickCount == 1) {
95+
val gitHubLink = node?.userObject as? StabilityNodeData.GitHubLink
96+
if (gitHubLink != null) {
97+
BrowserUtil.browse(gitHubLink.url)
98+
return
99+
}
100+
}
101+
102+
// Handle double click on composables for navigation
90103
if (e.clickCount == 2) {
91-
val node = tree.lastSelectedPathComponent as? DefaultMutableTreeNode
92-
val data = node?.userObject as? StabilityNodeData.Composable
93-
if (data != null) {
94-
navigateToSource(data.info)
104+
val composable = node?.userObject as? StabilityNodeData.Composable
105+
if (composable != null) {
106+
navigateToSource(composable.info)
95107
}
96108
}
97109
}
@@ -196,16 +208,33 @@ public class StabilityToolWindow(private val project: Project) {
196208

197209
// Show helpful message if no composables found
198210
if (results.composables.isEmpty()) {
199-
val messageNode = DefaultMutableTreeNode(
200-
StabilityNodeData.EmptyMessage(
201-
"To view compose stability information:\n" +
202-
"1. Apply the Compose Stability Analyzer Gradle plugin to your module\n" +
203-
"2. Build your project to generate stability reports\n" +
204-
"3. Click the refresh button above",
211+
val headerNode = DefaultMutableTreeNode(
212+
StabilityNodeData.EmptyMessage("To view compose stability information:"),
213+
)
214+
rootNode.add(headerNode)
215+
216+
// Add each step as a child node
217+
val steps = listOf(
218+
"1. Apply the Compose Stability Analyzer Gradle plugin to your module",
219+
"2. Build your project to generate stability reports",
220+
"3. Click the refresh button above",
221+
)
222+
223+
steps.forEach { step ->
224+
headerNode.add(DefaultMutableTreeNode(StabilityNodeData.EmptyMessage(step)))
225+
}
226+
227+
// Add GitHub link
228+
val githubNode = DefaultMutableTreeNode(
229+
StabilityNodeData.GitHubLink(
230+
"For more information, check out GitHub",
231+
"https://github.com/skydoves/compose-stability-analyzer",
205232
),
206233
)
207-
rootNode.add(messageNode)
234+
headerNode.add(githubNode)
235+
208236
treeModel.reload()
237+
tree.expandRow(0) // Expand the header to show all steps
209238
return
210239
}
211240

@@ -553,6 +582,17 @@ public class StabilityToolWindow(private val project: Project) {
553582
append(data.message, SimpleTextAttributes.GRAYED_ATTRIBUTES)
554583
}
555584

585+
is StabilityNodeData.GitHubLink -> {
586+
icon = AllIcons.Ide.External_link_arrow
587+
append(
588+
data.text,
589+
SimpleTextAttributes(
590+
SimpleTextAttributes.STYLE_PLAIN,
591+
JBUI.CurrentTheme.Link.Foreground.ENABLED,
592+
),
593+
)
594+
}
595+
556596
else -> {
557597
append(data.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES)
558598
}

0 commit comments

Comments
 (0)