Skip to content

Commit 87644ef

Browse files
committed
Open a thread on a dialog for copying text
1 parent 700d7ca commit 87644ef

File tree

8 files changed

+174
-79
lines changed

8 files changed

+174
-79
lines changed

merge-request-integration-core/src/main/kotlin/net/ntworld/mergeRequestIntegrationIde/component/comment/CommentComponent.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ package net.ntworld.mergeRequestIntegrationIde.component.comment
33
import net.ntworld.mergeRequestIntegrationIde.Component
44

55
interface CommentComponent : Component {
6+
7+
fun hideMoveToDialogButtons()
8+
9+
fun showMoveToDialogButtons()
10+
611
}

merge-request-integration-core/src/main/kotlin/net/ntworld/mergeRequestIntegrationIde/component/comment/CommentComponentImpl.kt

Lines changed: 84 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package net.ntworld.mergeRequestIntegrationIde.component.comment
22

3+
import com.intellij.icons.AllIcons
34
import com.intellij.ide.BrowserUtil
45
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
610
import com.intellij.openapi.ui.Messages
711
import com.intellij.openapi.ui.SimpleToolWindowPanel
812
import com.intellij.ui.JBColor
@@ -12,8 +16,8 @@ import net.ntworld.mergeRequest.Comment
1216
import net.ntworld.mergeRequest.MergeRequestInfo
1317
import net.ntworld.mergeRequest.ProviderData
1418
import net.ntworld.mergeRequestIntegration.util.DateTimeUtil
15-
import net.ntworld.mergeRequestIntegrationIde.util.HtmlHelper
1619
import net.ntworld.mergeRequestIntegrationIde.component.Icons
20+
import net.ntworld.mergeRequestIntegrationIde.util.HtmlHelper
1721
import java.awt.Color
1822
import java.awt.Cursor
1923
import java.awt.event.MouseEvent
@@ -28,8 +32,10 @@ class CommentComponentImpl(
2832
private val mergeRequestInfo: MergeRequestInfo,
2933
private val comment: Comment,
3034
private val indent: Int,
31-
private val borderLeftRight: Int = 1
35+
private val borderLeftRight: Int = 1,
36+
private val showMoveToDialog: Boolean = true
3237
) : CommentComponent {
38+
private var displayMoveToDialog: Boolean = showMoveToDialog
3339
private val myPanel = SimpleToolWindowPanel(true, false)
3440
private val myNameLabel = Label(comment.author.name)
3541
private val myUsernameLabel = Label("@${comment.author.username}")
@@ -41,55 +47,11 @@ class CommentComponentImpl(
4147
"/templates/mr.comment.html"
4248
).readText()
4349

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-
}
6050
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-
}
6951
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-
}
7852
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-
}
9253
private val myDeleteAction = MyDeleteAction(this)
54+
private val myMoveToDialogAction = MyMoveToDialogAction(this)
9355

9456
private class MyResolveAction(private val self: CommentComponentImpl) : AnAction() {
9557
override fun actionPerformed(e: AnActionEvent) {
@@ -126,6 +88,8 @@ class CommentComponentImpl(
12688
}
12789
}
12890

91+
override val component: JComponent = myPanel
92+
12993
init {
13094
if (indent == 0 && groupComponent.comments.size > 1) {
13195
myNameLabel.icon = if (groupComponent.collapse) Icons.CaretRight else Icons.CaretDown
@@ -143,7 +107,13 @@ class CommentComponentImpl(
143107
)
144108
}
145109

146-
override val component: JComponent = myPanel
110+
override fun hideMoveToDialogButtons() {
111+
displayMoveToDialog = false
112+
}
113+
114+
override fun showMoveToDialogButtons() {
115+
displayMoveToDialog = true
116+
}
147117

148118
private fun createToolbar(): JComponent {
149119
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(
157127
)
158128

159129
val rightActionGroup = DefaultActionGroup()
130+
if (showMoveToDialog) {
131+
rightActionGroup.add(myMoveToDialogAction)
132+
rightActionGroup.addSeparator()
133+
}
134+
160135
if (providerData.currentUser.id == comment.author.id) {
161136
rightActionGroup.add(myDeleteAction)
162137
rightActionGroup.addSeparator()
163138
}
139+
164140
rightActionGroup.add(myOpenInBrowserAction)
165141
rightActionGroup.addSeparator()
166142
if (comment.resolvable) {
@@ -187,4 +163,63 @@ class CommentComponentImpl(
187163

188164
return HtmlHelper.resolveRelativePath(providerData, output)
189165
}
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+
}
190225
}

merge-request-integration-core/src/main/kotlin/net/ntworld/mergeRequestIntegrationIde/component/comment/ComponentFactory.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ object ComponentFactory {
1515
borderTop: Boolean,
1616
groupId: String,
1717
comments: List<Comment>,
18-
borderLeftRight: Int = 1
18+
borderLeftRight: Int = 1,
19+
showMoveToDialog: Boolean = true
1920
) : GroupComponent {
2021
return GroupComponentImpl(
2122
borderTop,
@@ -24,7 +25,8 @@ object ComponentFactory {
2425
ideaProject,
2526
groupId,
2627
comments,
27-
borderLeftRight
28+
borderLeftRight,
29+
showMoveToDialog
2830
)
2931
}
3032

@@ -34,15 +36,17 @@ object ComponentFactory {
3436
mergeRequestInfo: MergeRequestInfo,
3537
comment: Comment,
3638
indent: Int,
37-
borderLeftRight: Int = 1
39+
borderLeftRight: Int = 1,
40+
showMoveToDialog: Boolean = true
3841
): CommentComponent {
3942
return CommentComponentImpl(
4043
groupComponent,
4144
providerData,
4245
mergeRequestInfo,
4346
comment,
4447
indent,
45-
borderLeftRight
48+
borderLeftRight,
49+
showMoveToDialog
4650
)
4751
}
4852

merge-request-integration-core/src/main/kotlin/net/ntworld/mergeRequestIntegrationIde/component/comment/GroupComponent.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ interface GroupComponent : Component, Disposable {
1111

1212
var collapse: Boolean
1313

14+
fun requestOpenDialog()
15+
1416
fun requestDeleteComment(comment: Comment)
1517

1618
fun requestToggleResolvedStateOfComment(comment: Comment)
@@ -23,9 +25,15 @@ interface GroupComponent : Component, Disposable {
2325

2426
fun addListener(listener: EventListener)
2527

28+
fun hideMoveToDialogButtons()
29+
30+
fun showMoveToDialogButtons()
31+
2632
interface EventListener : java.util.EventListener, CommentEvent {
2733
fun onResized()
2834

35+
fun onOpenDialogClicked()
36+
2937
fun onEditorCreated(groupId: String, editor: EditorComponent)
3038

3139
fun onEditorDestroyed(groupId: String, editor: EditorComponent)

merge-request-integration-core/src/main/kotlin/net/ntworld/mergeRequestIntegrationIde/component/comment/GroupComponentImpl.kt

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class GroupComponentImpl(
2020
private val project: IdeaProject,
2121
override val id: String,
2222
comments: List<Comment>,
23-
private val borderLeftRight: Int = 1
23+
private val borderLeftRight: Int = 1,
24+
private val showMoveToDialog: Boolean = true
2425
) : GroupComponent {
2526
private val dispatcher = EventDispatcher.create(GroupComponent.EventListener::class.java)
2627
private val myBoxLayoutPanel = JBUI.Panels.simplePanel()
@@ -101,6 +102,10 @@ class GroupComponentImpl(
101102
dispatcher.multicaster.onResized()
102103
}
103104

105+
override fun requestOpenDialog() {
106+
dispatcher.multicaster.onOpenDialogClicked()
107+
}
108+
104109
override fun requestDeleteComment(comment: Comment) {
105110
dispatcher.multicaster.onDeleteCommentRequested(comment)
106111
}
@@ -153,6 +158,14 @@ class GroupComponentImpl(
153158

154159
override fun addListener(listener: GroupComponent.EventListener) = dispatcher.addListener(listener)
155160

161+
override fun hideMoveToDialogButtons() {
162+
myCommentComponents.forEach { it.hideMoveToDialogButtons() }
163+
}
164+
165+
override fun showMoveToDialogButtons() {
166+
myCommentComponents.forEach { it.showMoveToDialogButtons() }
167+
}
168+
156169
override fun dispose() {
157170
dispatcher.listeners.clear()
158171
}
@@ -183,15 +196,15 @@ class GroupComponentImpl(
183196
myCommentComponents.clear()
184197

185198
items.forEachIndexed { index, comment ->
186-
val commentComponent =
187-
ComponentFactory.makeComment(
188-
this,
189-
providerData,
190-
mergeRequestInfo,
191-
comment,
192-
if (index == 0) 0 else 1,
193-
borderLeftRight
194-
)
199+
val commentComponent = ComponentFactory.makeComment(
200+
this,
201+
providerData,
202+
mergeRequestInfo,
203+
comment,
204+
if (index == 0) 0 else 1,
205+
borderLeftRight,
206+
showMoveToDialog
207+
)
195208

196209
myPanel.add(commentComponent.component)
197210
myCommentComponents.add(commentComponent)

0 commit comments

Comments
 (0)