@@ -15,11 +15,16 @@ import com.intellij.openapi.ui.popup.JBPopup
15
15
import com.intellij.openapi.ui.popup.JBPopupFactory
16
16
import com.intellij.openapi.ui.popup.JBPopupListener
17
17
import com.intellij.openapi.ui.popup.LightweightWindowEvent
18
+ import com.intellij.openapi.vcs.VcsDataKeys
19
+ import com.intellij.openapi.vcs.ui.CommitMessage
18
20
import com.intellij.ui.ColoredListCellRenderer
21
+ import com.intellij.ui.awt.RelativePoint
19
22
import com.intellij.ui.speedSearch.SpeedSearchUtil.applySpeedSearchHighlighting
20
23
import com.intellij.util.containers.nullize
24
+ import com.intellij.util.ui.JBUI.scale
21
25
import org.kohsuke.github.GHIssue
22
26
import org.kohsuke.github.GHIssueState
27
+ import java.awt.Point
23
28
import javax.swing.JList
24
29
import javax.swing.ListSelectionModel.SINGLE_SELECTION
25
30
@@ -35,14 +40,16 @@ class ShowGitHubIssuesAction : DumbAwareAction() {
35
40
e.presentation.text = " Show GitHub Issues"
36
41
e.presentation.description = " Show and select GitHub issues from current repository"
37
42
38
- e.presentation.isVisible = project != null && isGitHubProject (project)
43
+ e.presentation.isVisible = project != null && GitHubIssue .isGitHubRepository (project)
39
44
e.presentation.isEnabled = e.presentation.isVisible
40
45
}
41
46
42
47
override fun getActionUpdateThread (): ActionUpdateThread = ActionUpdateThread .BGT
43
48
44
49
override fun actionPerformed (e : AnActionEvent ) {
45
50
val project = e.project!!
51
+ val commitMessage = getCommitMessage(e)!!
52
+
46
53
ApplicationManager .getApplication().executeOnPooledThread {
47
54
try {
48
55
val issues = fetchGitHubIssues(project)
@@ -58,7 +65,7 @@ class ShowGitHubIssuesAction : DumbAwareAction() {
58
65
}
59
66
60
67
ApplicationManager .getApplication().invokeLater {
61
- createIssuesPopup(project, issues).showInBestPositionFor(e.dataContext)
68
+ createIssuesPopup(project, commitMessage, issues).showInBestPositionFor(e.dataContext)
62
69
}
63
70
} catch (ex: Exception ) {
64
71
ApplicationManager .getApplication().invokeLater {
@@ -72,13 +79,7 @@ class ShowGitHubIssuesAction : DumbAwareAction() {
72
79
}
73
80
}
74
81
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
82
83
83
84
private fun fetchGitHubIssues (project : Project ): List <IssueDisplayItem > {
84
85
val ghRepository = GitHubIssue .parseGitHubRepository(project)
@@ -95,7 +96,7 @@ class ShowGitHubIssuesAction : DumbAwareAction() {
95
96
}
96
97
}
97
98
98
- private fun createIssuesPopup (project : Project , issues : List <IssueDisplayItem >): JBPopup {
99
+ private fun createIssuesPopup (project : Project , commitMessage : CommitMessage , issues : List <IssueDisplayItem >): JBPopup {
99
100
var chosenIssue: IssueDisplayItem ? = null
100
101
var selectedIssue: IssueDisplayItem ? = null
101
102
@@ -128,6 +129,13 @@ class ShowGitHubIssuesAction : DumbAwareAction() {
128
129
}
129
130
})
130
131
.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
+ }
131
139
override fun onClosed (event : LightweightWindowEvent ) {
132
140
chosenIssue?.let { issue ->
133
141
handleIssueSelection(project, issue)
0 commit comments