1
1
package net.ntworld.mergeRequestIntegrationIde.component.comment
2
2
3
+ import com.intellij.icons.AllIcons
3
4
import com.intellij.ide.BrowserUtil
4
5
import com.intellij.ide.util.TipUIUtil
5
- import com.intellij.openapi.actionSystem.*
6
+ import com.intellij.openapi.actionSystem.ActionManager
7
+ import com.intellij.openapi.actionSystem.AnAction
8
+ import com.intellij.openapi.actionSystem.AnActionEvent
9
+ import com.intellij.openapi.actionSystem.DefaultActionGroup
6
10
import com.intellij.openapi.ui.Messages
7
11
import com.intellij.openapi.ui.SimpleToolWindowPanel
8
12
import com.intellij.ui.JBColor
@@ -12,8 +16,8 @@ import net.ntworld.mergeRequest.Comment
12
16
import net.ntworld.mergeRequest.MergeRequestInfo
13
17
import net.ntworld.mergeRequest.ProviderData
14
18
import net.ntworld.mergeRequestIntegration.util.DateTimeUtil
15
- import net.ntworld.mergeRequestIntegrationIde.util.HtmlHelper
16
19
import net.ntworld.mergeRequestIntegrationIde.component.Icons
20
+ import net.ntworld.mergeRequestIntegrationIde.util.HtmlHelper
17
21
import java.awt.Color
18
22
import java.awt.Cursor
19
23
import java.awt.event.MouseEvent
@@ -28,8 +32,10 @@ class CommentComponentImpl(
28
32
private val mergeRequestInfo : MergeRequestInfo ,
29
33
private val comment : Comment ,
30
34
private val indent : Int ,
31
- private val borderLeftRight : Int = 1
35
+ private val borderLeftRight : Int = 1 ,
36
+ private val showMoveToDialog : Boolean = true
32
37
) : CommentComponent {
38
+ private var displayMoveToDialog: Boolean = showMoveToDialog
33
39
private val myPanel = SimpleToolWindowPanel (true , false )
34
40
private val myNameLabel = Label (comment.author.name)
35
41
private val myUsernameLabel = Label (" @${comment.author.username} " )
@@ -41,55 +47,11 @@ class CommentComponentImpl(
41
47
" /templates/mr.comment.html"
42
48
).readText()
43
49
44
- private class MyTimeAction (private val self : CommentComponentImpl ) : AnAction(null , null , null ) {
45
- override fun actionPerformed (e : AnActionEvent ) {
46
- self.myUsePrettyTime = ! self.myUsePrettyTime
47
- }
48
-
49
- override fun update (e : AnActionEvent ) {
50
- e.presentation.text = if (self.myUsePrettyTime) {
51
- DateTimeUtil .toPretty(DateTimeUtil .toDate(self.comment.updatedAt))
52
- } else {
53
- DateTimeUtil .formatDate(DateTimeUtil .toDate(self.comment.updatedAt))
54
- }
55
- }
56
-
57
- override fun useSmallerFontForTextInToolbar (): Boolean = false
58
- override fun displayTextInToolbar () = true
59
- }
60
50
private val myTimeAction = MyTimeAction (this )
61
-
62
- private class MyOpenInBrowserAction (private val self : CommentComponentImpl ): AnAction(
63
- " View in browser" , " Open and view the comment in browser" , Icons .ExternalLink
64
- ) {
65
- override fun actionPerformed (e : AnActionEvent ) {
66
- BrowserUtil .open(self.providerData.info.createCommentUrl(self.mergeRequestInfo.url, self.comment))
67
- }
68
- }
69
51
private val myOpenInBrowserAction = MyOpenInBrowserAction (this )
70
-
71
- private class MyReplyAction (private val self : CommentComponentImpl ): AnAction(
72
- " Reply" , " Reply this comment" , Icons .ReplyComment
73
- ) {
74
- override fun actionPerformed (e : AnActionEvent ) {
75
- self.groupComponent.showReplyEditor()
76
- }
77
- }
78
52
private val myReplyAction = MyReplyAction (this )
79
-
80
- private class MyDeleteAction (private val self : CommentComponentImpl ) : AnAction(
81
- " Delete comment" , " Delete comment" , Icons .Trash
82
- ) {
83
- override fun actionPerformed (e : AnActionEvent ) {
84
- val result = Messages .showYesNoDialog(
85
- " Do you want to delete the comment?" , " Are you sure" , Messages .getQuestionIcon()
86
- )
87
- if (result == Messages .YES ) {
88
- self.groupComponent.requestDeleteComment(self.comment)
89
- }
90
- }
91
- }
92
53
private val myDeleteAction = MyDeleteAction (this )
54
+ private val myMoveToDialogAction = MyMoveToDialogAction (this )
93
55
94
56
private class MyResolveAction (private val self : CommentComponentImpl ) : AnAction() {
95
57
override fun actionPerformed (e : AnActionEvent ) {
@@ -126,6 +88,8 @@ class CommentComponentImpl(
126
88
}
127
89
}
128
90
91
+ override val component: JComponent = myPanel
92
+
129
93
init {
130
94
if (indent == 0 && groupComponent.comments.size > 1 ) {
131
95
myNameLabel.icon = if (groupComponent.collapse) Icons .CaretRight else Icons .CaretDown
@@ -143,7 +107,13 @@ class CommentComponentImpl(
143
107
)
144
108
}
145
109
146
- override val component: JComponent = myPanel
110
+ override fun hideMoveToDialogButtons () {
111
+ displayMoveToDialog = false
112
+ }
113
+
114
+ override fun showMoveToDialogButtons () {
115
+ displayMoveToDialog = true
116
+ }
147
117
148
118
private fun createToolbar (): JComponent {
149
119
val panel = JPanel (MigLayout (" ins 0, fill" , " 5[left]5[left]5[left]0[left, fill]push[right]" , " center" ))
@@ -157,10 +127,16 @@ class CommentComponentImpl(
157
127
)
158
128
159
129
val rightActionGroup = DefaultActionGroup ()
130
+ if (showMoveToDialog) {
131
+ rightActionGroup.add(myMoveToDialogAction)
132
+ rightActionGroup.addSeparator()
133
+ }
134
+
160
135
if (providerData.currentUser.id == comment.author.id) {
161
136
rightActionGroup.add(myDeleteAction)
162
137
rightActionGroup.addSeparator()
163
138
}
139
+
164
140
rightActionGroup.add(myOpenInBrowserAction)
165
141
rightActionGroup.addSeparator()
166
142
if (comment.resolvable) {
@@ -187,4 +163,63 @@ class CommentComponentImpl(
187
163
188
164
return HtmlHelper .resolveRelativePath(providerData, output)
189
165
}
166
+
167
+ private class MyMoveToDialogAction (private val self : CommentComponentImpl ): AnAction(
168
+ " Open in a Dialog" , " " , AllIcons .Actions .MoveToWindow
169
+ ) {
170
+ override fun actionPerformed (e : AnActionEvent ) {
171
+ self.groupComponent.requestOpenDialog()
172
+ }
173
+
174
+ override fun update (e : AnActionEvent ) {
175
+ super .update(e)
176
+ e.presentation.isVisible = self.displayMoveToDialog
177
+ }
178
+ }
179
+
180
+ private class MyTimeAction (private val self : CommentComponentImpl ) : AnAction(null , null , null ) {
181
+ override fun actionPerformed (e : AnActionEvent ) {
182
+ self.myUsePrettyTime = ! self.myUsePrettyTime
183
+ }
184
+
185
+ override fun update (e : AnActionEvent ) {
186
+ e.presentation.text = if (self.myUsePrettyTime) {
187
+ DateTimeUtil .toPretty(DateTimeUtil .toDate(self.comment.updatedAt))
188
+ } else {
189
+ DateTimeUtil .formatDate(DateTimeUtil .toDate(self.comment.updatedAt))
190
+ }
191
+ }
192
+
193
+ override fun useSmallerFontForTextInToolbar (): Boolean = false
194
+ override fun displayTextInToolbar () = true
195
+ }
196
+
197
+ private class MyOpenInBrowserAction (private val self : CommentComponentImpl ): AnAction(
198
+ " View in browser" , " Open and view the comment in browser" , Icons .ExternalLink
199
+ ) {
200
+ override fun actionPerformed (e : AnActionEvent ) {
201
+ BrowserUtil .open(self.providerData.info.createCommentUrl(self.mergeRequestInfo.url, self.comment))
202
+ }
203
+ }
204
+
205
+ private class MyReplyAction (private val self : CommentComponentImpl ): AnAction(
206
+ " Reply" , " Reply this comment" , Icons .ReplyComment
207
+ ) {
208
+ override fun actionPerformed (e : AnActionEvent ) {
209
+ self.groupComponent.showReplyEditor()
210
+ }
211
+ }
212
+
213
+ private class MyDeleteAction (private val self : CommentComponentImpl ) : AnAction(
214
+ " Delete comment" , " Delete comment" , Icons .Trash
215
+ ) {
216
+ override fun actionPerformed (e : AnActionEvent ) {
217
+ val result = Messages .showYesNoDialog(
218
+ " Do you want to delete the comment?" , " Are you sure" , Messages .getQuestionIcon()
219
+ )
220
+ if (result == Messages .YES ) {
221
+ self.groupComponent.requestDeleteComment(self.comment)
222
+ }
223
+ }
224
+ }
190
225
}
0 commit comments