From a67ddea9e8a3e607126a2480e00f46eb63df6853 Mon Sep 17 00:00:00 2001 From: Ivan Semenov Date: Wed, 18 Jan 2023 16:28:05 +0100 Subject: [PATCH] [collab/github/space] extract comment edit button GitOrigin-RevId: 217e331df233c8191e3ab17508e57085f062fc01 --- .../comment/CodeReviewCommentUIUtil.kt | 11 +++++++ .../comment/ui/GHPRReviewCommentComponent.kt | 5 +-- .../github/pullrequest/ui/GHTextActions.kt | 31 ------------------- .../GHPRTimelineItemComponentFactory.kt | 17 +++++++--- 4 files changed, 26 insertions(+), 38 deletions(-) delete mode 100644 plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/GHTextActions.kt diff --git a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/CodeReviewCommentUIUtil.kt b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/CodeReviewCommentUIUtil.kt index c480cdb6ad9f..4ba75790a36a 100644 --- a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/CodeReviewCommentUIUtil.kt +++ b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/CodeReviewCommentUIUtil.kt @@ -4,6 +4,7 @@ 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.icons.AllIcons import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.EditorColorsManager import com.intellij.openapi.ui.MessageDialogBuilder @@ -55,6 +56,16 @@ object CodeReviewCommentUIUtil { return button } + fun createEditButton(actionListener: (ActionEvent) -> Unit): InlineIconButton { + val icon = AllIcons.General.Inline_edit + val hoverIcon = AllIcons.General.Inline_edit_hovered + return InlineIconButton(icon, hoverIcon, tooltip = CommonBundle.message("button.edit")).apply { + this.actionListener = ActionListener { + actionListener(it) + } + } + } + object Actions { const val HORIZONTAL_GAP = 8 } diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/comment/ui/GHPRReviewCommentComponent.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/comment/ui/GHPRReviewCommentComponent.kt index 3a32e2286f6c..d1e5804f9843 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/comment/ui/GHPRReviewCommentComponent.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/comment/ui/GHPRReviewCommentComponent.kt @@ -17,7 +17,6 @@ import org.jetbrains.plugins.github.i18n.GithubBundle import org.jetbrains.plugins.github.pullrequest.comment.GHSuggestedChange import org.jetbrains.plugins.github.pullrequest.data.provider.GHPRReviewDataProvider import org.jetbrains.plugins.github.pullrequest.ui.GHEditableHtmlPaneHandle -import org.jetbrains.plugins.github.pullrequest.ui.GHTextActions import org.jetbrains.plugins.github.pullrequest.ui.changes.GHPRSuggestedChangeHelper import org.jetbrains.plugins.github.pullrequest.ui.timeline.GHPRTimelineItemUIUtil import org.jetbrains.plugins.github.ui.avatars.GHAvatarIconsProvider @@ -70,7 +69,9 @@ object GHPRReviewCommentComponent { maxEditorWidth = maxTextWidth } - val editButton = GHTextActions.createEditButton(editablePaneHandle).apply { + val editButton = CodeReviewCommentUIUtil.createEditButton { + editablePaneHandle.showAndFocusEditor() + }.apply { isVisible = comment.canBeUpdated } val deleteButton = CodeReviewCommentUIUtil.createDeleteCommentIconButton { diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/GHTextActions.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/GHTextActions.kt deleted file mode 100644 index 6220de73c34f..000000000000 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/GHTextActions.kt +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -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 -import icons.CollaborationToolsIcons -import org.jetbrains.plugins.github.i18n.GithubBundle -import java.awt.event.ActionListener -import java.util.concurrent.CompletableFuture -import javax.swing.JComponent - -internal object GHTextActions { - - fun createEditButton(paneHandle: GHEditableHtmlPaneHandle): InlineIconButton { - return createEditButton().apply { - actionListener = ActionListener { - paneHandle.showAndFocusEditor() - } - } - } - - private fun createEditButton(): InlineIconButton { - val icon = AllIcons.General.Inline_edit - val hoverIcon = AllIcons.General.Inline_edit_hovered - return InlineIconButton(icon, hoverIcon, tooltip = CommonBundle.message("button.edit")) - } -} \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineItemComponentFactory.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineItemComponentFactory.kt index ca6a90247b78..647a2de74465 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineItemComponentFactory.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineItemComponentFactory.kt @@ -59,7 +59,6 @@ import org.jetbrains.plugins.github.pullrequest.data.provider.GHPRCommentsDataPr import org.jetbrains.plugins.github.pullrequest.data.provider.GHPRDetailsDataProvider import org.jetbrains.plugins.github.pullrequest.data.provider.GHPRReviewDataProvider import org.jetbrains.plugins.github.pullrequest.ui.GHEditableHtmlPaneHandle -import org.jetbrains.plugins.github.pullrequest.ui.GHTextActions import org.jetbrains.plugins.github.pullrequest.ui.changes.GHPRSuggestedChangeHelper import org.jetbrains.plugins.github.pullrequest.ui.timeline.GHPRTimelineItemUIUtil.buildTimelineItem import org.jetbrains.plugins.github.pullrequest.ui.timeline.GHPRTimelineItemUIUtil.createTimelineItem @@ -199,7 +198,9 @@ class GHPRTimelineItemComponentFactory(private val project: Project, } contentPanel = panelHandle.panel actionsPanel = if (details.viewerCanUpdate) HorizontalListPanel(CodeReviewCommentUIUtil.Actions.HORIZONTAL_GAP).apply { - add(GHTextActions.createEditButton(panelHandle)) + add(CodeReviewCommentUIUtil.createEditButton { + panelHandle.showAndFocusEditor() + }) } else null } @@ -220,7 +221,9 @@ class GHPRTimelineItemComponentFactory(private val project: Project, .successOnEdt { textPane.setHtmlBody(it.convertToHtml(project)) } } val actionsPanel = HorizontalListPanel(CodeReviewCommentUIUtil.Actions.HORIZONTAL_GAP).apply { - if (comment.viewerCanUpdate) add(GHTextActions.createEditButton(panelHandle)) + if (comment.viewerCanUpdate) add(CodeReviewCommentUIUtil.createEditButton { + panelHandle.showAndFocusEditor() + }) if (comment.viewerCanDelete) add(CodeReviewCommentUIUtil.createDeleteCommentIconButton { commentsDataProvider.deleteComment(EmptyProgressIndicator(), comment.id) }) @@ -290,7 +293,9 @@ class GHPRTimelineItemComponentFactory(private val project: Project, } val actionsPanel = HorizontalListPanel(CodeReviewCommentUIUtil.Actions.HORIZONTAL_GAP).apply { - if (firstComment.canBeUpdated) add(GHTextActions.createEditButton(panelHandle)) + if (firstComment.canBeUpdated) add(CodeReviewCommentUIUtil.createEditButton { + panelHandle.showAndFocusEditor() + }) if (firstComment.canBeDeleted) add(CodeReviewCommentUIUtil.createDeleteCommentIconButton { reviewDataProvider.deleteComment(EmptyProgressIndicator(), firstComment.id) }) @@ -465,7 +470,9 @@ class GHPRTimelineItemComponentFactory(private val project: Project, } val actionsPanel = HorizontalListPanel(8).apply { - if (panelHandle != null && review.viewerCanUpdate) add(GHTextActions.createEditButton(panelHandle)) + if (panelHandle != null && review.viewerCanUpdate) add(CodeReviewCommentUIUtil.createEditButton { + panelHandle.showAndFocusEditor() + }) } val stateText = when (review.state) {