Skip to content

Commit 979ef19

Browse files
committed
feat(github): improve GitHub issues popup positioning #408
- Move isGitHubRepository check to GitHubIssue class for better organization - Position popup relative to commit message editor field instead of default location - Add commit message context to popup creation for better integration
1 parent dc48d17 commit 979ef19

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

core/src/main/kotlin/cc/unitmesh/devti/actions/github/ShowGitHubIssuesAction.kt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ import com.intellij.openapi.ui.popup.JBPopup
1515
import com.intellij.openapi.ui.popup.JBPopupFactory
1616
import com.intellij.openapi.ui.popup.JBPopupListener
1717
import com.intellij.openapi.ui.popup.LightweightWindowEvent
18+
import com.intellij.openapi.vcs.VcsDataKeys
19+
import com.intellij.openapi.vcs.ui.CommitMessage
1820
import com.intellij.ui.ColoredListCellRenderer
21+
import com.intellij.ui.awt.RelativePoint
1922
import com.intellij.ui.speedSearch.SpeedSearchUtil.applySpeedSearchHighlighting
2023
import com.intellij.util.containers.nullize
24+
import com.intellij.util.ui.JBUI.scale
2125
import org.kohsuke.github.GHIssue
2226
import org.kohsuke.github.GHIssueState
27+
import java.awt.Point
2328
import javax.swing.JList
2429
import javax.swing.ListSelectionModel.SINGLE_SELECTION
2530

@@ -35,14 +40,16 @@ class ShowGitHubIssuesAction : DumbAwareAction() {
3540
e.presentation.text = "Show GitHub Issues"
3641
e.presentation.description = "Show and select GitHub issues from current repository"
3742

38-
e.presentation.isVisible = project != null && isGitHubProject(project)
43+
e.presentation.isVisible = project != null && GitHubIssue.isGitHubRepository(project)
3944
e.presentation.isEnabled = e.presentation.isVisible
4045
}
4146

4247
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
4348

4449
override fun actionPerformed(e: AnActionEvent) {
4550
val project = e.project!!
51+
val commitMessage = getCommitMessage(e)!!
52+
4653
ApplicationManager.getApplication().executeOnPooledThread {
4754
try {
4855
val issues = fetchGitHubIssues(project)
@@ -58,7 +65,7 @@ class ShowGitHubIssuesAction : DumbAwareAction() {
5865
}
5966

6067
ApplicationManager.getApplication().invokeLater {
61-
createIssuesPopup(project, issues).showInBestPositionFor(e.dataContext)
68+
createIssuesPopup(project, commitMessage, issues).showInBestPositionFor(e.dataContext)
6269
}
6370
} catch (ex: Exception) {
6471
ApplicationManager.getApplication().invokeLater {
@@ -72,13 +79,7 @@ class ShowGitHubIssuesAction : DumbAwareAction() {
7279
}
7380
}
7481

75-
private fun isGitHubProject(project: Project): Boolean {
76-
return try {
77-
GitHubIssue.parseGitHubRepository(project) != null
78-
} catch (e: Exception) {
79-
false
80-
}
81-
}
82+
private fun getCommitMessage(e: AnActionEvent) = e.getData(VcsDataKeys.COMMIT_MESSAGE_CONTROL) as? CommitMessage
8283

8384
private fun fetchGitHubIssues(project: Project): List<IssueDisplayItem> {
8485
val ghRepository = GitHubIssue.parseGitHubRepository(project)
@@ -95,7 +96,7 @@ class ShowGitHubIssuesAction : DumbAwareAction() {
9596
}
9697
}
9798

98-
private fun createIssuesPopup(project: Project, issues: List<IssueDisplayItem>): JBPopup {
99+
private fun createIssuesPopup(project: Project, commitMessage: CommitMessage, issues: List<IssueDisplayItem>): JBPopup {
99100
var chosenIssue: IssueDisplayItem? = null
100101
var selectedIssue: IssueDisplayItem? = null
101102

@@ -128,6 +129,13 @@ class ShowGitHubIssuesAction : DumbAwareAction() {
128129
}
129130
})
130131
.addListener(object : JBPopupListener {
132+
override fun beforeShown(event: LightweightWindowEvent) {
133+
val popup = event.asPopup()
134+
val relativePoint = RelativePoint(commitMessage.editorField, Point(0, -scale(3)))
135+
val screenPoint = Point(relativePoint.screenPoint).apply { translate(0, -popup.size.height) }
136+
137+
popup.setLocation(screenPoint)
138+
}
131139
override fun onClosed(event: LightweightWindowEvent) {
132140
chosenIssue?.let { issue ->
133141
handleIssueSelection(project, issue)

core/src/main/kotlin/cc/unitmesh/devti/flow/kanban/impl/GitHubIssue.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,25 @@ class GitHubIssue(var repoUrl: String, val token: String) : Kanban {
117117
val remoteUrl = parseGitHubRemoteUrl(repository) ?: return null
118118
return getGitHubRepository(project, remoteUrl)
119119
}
120+
121+
fun isGitHubRepository(project: Project): Boolean {
122+
val repositoryManager: VcsRepositoryManager = VcsRepositoryManager.getInstance(project)
123+
val repository = repositoryManager.getRepositoryForFile(project.baseDir)
124+
125+
if (repository == null) {
126+
return false
127+
}
128+
129+
if (repository !is GitRepository) {
130+
return false
131+
}
132+
133+
val remoteUrl = parseGitHubRemoteUrl(repository) ?: return false
134+
if (remoteUrl.contains("github.com")) {
135+
return true
136+
}
137+
138+
return false
139+
}
120140
}
121141
}

0 commit comments

Comments
 (0)