[collab/github/space] extract delete icon button

GitOrigin-RevId: 81842f1b80d061d7546a7159b62c2254fcf6bb24
This commit is contained in:
Ivan Semenov
2023-01-16 19:35:29 +01:00
committed by intellij-monorepo-bot
parent d4a6040c2f
commit f962821f0d
6 changed files with 29 additions and 18 deletions

View File

@@ -57,4 +57,6 @@ review.details.status.reviewer.wait.for.updates={0} is waiting for updates
review.comments.reply.action=Reply
review.comments.replies.action={0} {0, choice, 1#reply|2#replies}
review.comments.resolve.action=Resolve
review.comments.unresolve.action=Unresolve
review.comments.unresolve.action=Unresolve
review.comments.delete.confirmation.title=Delete Comment
review.comments.delete.confirmation=Are you sure you want to delete this comment?

View File

@@ -1,12 +1,19 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.collaboration.ui.codereview.comment
import com.intellij.CommonBundle
import com.intellij.collaboration.messages.CollaborationToolsBundle
import com.intellij.collaboration.ui.CollaborationToolsUIUtil
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.ui.MessageDialogBuilder
import com.intellij.ui.IdeBorderFactory
import com.intellij.ui.JBColor
import com.intellij.util.ui.InlineIconButton
import icons.CollaborationToolsIcons
import java.awt.BorderLayout
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.awt.event.ComponentAdapter
import java.awt.event.ComponentEvent
import javax.swing.JComponent
@@ -35,6 +42,19 @@ object CodeReviewCommentUIUtil {
}
}
fun createDeleteCommentIconButton(actionListener: (ActionEvent) -> Unit): JComponent {
val icon = CollaborationToolsIcons.Delete
val hoverIcon = CollaborationToolsIcons.DeleteHovered
val button = InlineIconButton(icon, hoverIcon, tooltip = CommonBundle.message("button.delete"))
button.actionListener = ActionListener {
if (MessageDialogBuilder.yesNo(CollaborationToolsBundle.message("review.comments.delete.confirmation.title"),
CollaborationToolsBundle.message("review.comments.delete.confirmation")).ask(button)) {
actionListener(it)
}
}
return button
}
object Actions {
const val HORIZONTAL_GAP = 8
}

View File

@@ -330,8 +330,6 @@ pull.request.review.submit.approve.button=Approve
pull.request.review.submit.comment.button=Comment
pull.request.review.submit.comment.description=Submit general feedback without explicit approval
pull.request.review.submit.error=Error occurred while submitting a review
pull.request.review.comment.delete.dialog.msg=Are you sure you want to delete this comment?
pull.request.review.comment.delete.dialog.title=Delete Comment
pull.request.discard.pending.comments.dialog.title=Discard Pending Review
pull.request.discard.pending.comments.dialog.msg=Are you sure you want to delete all pending comments?
pull.request.discard.pending.comments=Discard pending comments

View File

@@ -3,6 +3,7 @@ package org.jetbrains.plugins.github.pullrequest.comment.ui
import com.intellij.collaboration.ui.HorizontalListPanel
import com.intellij.collaboration.ui.codereview.CodeReviewChatItemUIUtil
import com.intellij.collaboration.ui.codereview.comment.CodeReviewCommentUIUtil
import com.intellij.openapi.progress.EmptyProgressIndicator
import com.intellij.openapi.project.Project
import com.intellij.ui.components.JBLabel
@@ -72,7 +73,7 @@ object GHPRReviewCommentComponent {
val editButton = GHTextActions.createEditButton(editablePaneHandle).apply {
isVisible = comment.canBeUpdated
}
val deleteButton = GHTextActions.createDeleteButton {
val deleteButton = CodeReviewCommentUIUtil.createDeleteCommentIconButton {
reviewDataProvider.deleteComment(EmptyProgressIndicator(), comment.id)
}.apply {
isVisible = comment.canBeDeleted

View File

@@ -2,6 +2,8 @@
package org.jetbrains.plugins.github.pullrequest.ui
import com.intellij.CommonBundle
import com.intellij.collaboration.ui.CollaborationToolsUIUtil
import com.intellij.collaboration.ui.codereview.comment.CodeReviewCommentUIUtil
import com.intellij.icons.AllIcons
import com.intellij.openapi.ui.MessageDialogBuilder
import com.intellij.util.ui.InlineIconButton
@@ -12,18 +14,6 @@ import java.util.concurrent.CompletableFuture
import javax.swing.JComponent
internal object GHTextActions {
fun createDeleteButton(delete: () -> CompletableFuture<out Any?>): JComponent {
val icon = CollaborationToolsIcons.Delete
val hoverIcon = CollaborationToolsIcons.DeleteHovered
val button = InlineIconButton(icon, hoverIcon, tooltip = CommonBundle.message("button.delete"))
button.actionListener = ActionListener {
if (MessageDialogBuilder.yesNo(GithubBundle.message("pull.request.review.comment.delete.dialog.title"),
GithubBundle.message("pull.request.review.comment.delete.dialog.msg")).ask(button)) {
delete()
}
}
return button
}
fun createEditButton(paneHandle: GHEditableHtmlPaneHandle): InlineIconButton {
return createEditButton().apply {

View File

@@ -220,7 +220,7 @@ class GHPRTimelineItemComponentFactory(private val project: Project,
}
val actionsPanel = HorizontalListPanel(CodeReviewCommentUIUtil.Actions.HORIZONTAL_GAP).apply {
if (comment.viewerCanUpdate) add(GHTextActions.createEditButton(panelHandle))
if (comment.viewerCanDelete) add(GHTextActions.createDeleteButton {
if (comment.viewerCanDelete) add(CodeReviewCommentUIUtil.createDeleteCommentIconButton {
commentsDataProvider.deleteComment(EmptyProgressIndicator(), comment.id)
})
}
@@ -290,7 +290,7 @@ class GHPRTimelineItemComponentFactory(private val project: Project,
val actionsPanel = HorizontalListPanel(CodeReviewCommentUIUtil.Actions.HORIZONTAL_GAP).apply {
if (firstComment.canBeUpdated) add(GHTextActions.createEditButton(panelHandle))
if (firstComment.canBeDeleted) add(GHTextActions.createDeleteButton {
if (firstComment.canBeDeleted) add(CodeReviewCommentUIUtil.createDeleteCommentIconButton {
reviewDataProvider.deleteComment(EmptyProgressIndicator(), firstComment.id)
})
}