[collab] Use toolbar for filter button
authorAleksandr Krasilnikov <aleksandr.krasilnikov@jetbrains.com>
Wed, 17 Aug 2022 15:48:09 +0000 (17:48 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Thu, 18 Aug 2022 14:26:25 +0000 (14:26 +0000)
GitOrigin-RevId: 92aa988ead7f89c686e616b7d3c6933e28bcd731

platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/list/search/ReviewListSearchPanelFactory.kt

index c292db2e1fe558d13a49db1546327d53f334c1eb..dac1881ab80bf53ee9a65aa9d281da7aad446097 100644 (file)
@@ -13,7 +13,6 @@ import com.intellij.ui.components.GradientViewport
 import com.intellij.ui.components.JBScrollPane
 import com.intellij.ui.components.JBThinOverlappingScrollBar
 import com.intellij.ui.components.panels.HorizontalLayout
 import com.intellij.ui.components.JBScrollPane
 import com.intellij.ui.components.JBThinOverlappingScrollBar
 import com.intellij.ui.components.panels.HorizontalLayout
-import com.intellij.util.ui.InlineIconButton
 import com.intellij.util.ui.JBUI
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.flow.update
 import com.intellij.util.ui.JBUI
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.flow.update
@@ -21,7 +20,6 @@ import kotlinx.coroutines.launch
 import org.jetbrains.annotations.Nls
 import java.awt.Adjustable
 import java.awt.BorderLayout
 import org.jetbrains.annotations.Nls
 import java.awt.Adjustable
 import java.awt.BorderLayout
-import java.awt.event.ActionListener
 import javax.swing.JComponent
 import javax.swing.JPanel
 import javax.swing.ScrollPaneConstants
 import javax.swing.JComponent
 import javax.swing.JPanel
 import javax.swing.ScrollPaneConstants
@@ -88,21 +86,23 @@ abstract class ReviewListSearchPanelFactory<S : ReviewListSearchValue, Q : Revie
   private inner class QuickFilterButtonFactory {
 
     fun create(viewScope: CoroutineScope, quickFilters: List<Q>): JComponent {
   private inner class QuickFilterButtonFactory {
 
     fun create(viewScope: CoroutineScope, quickFilters: List<Q>): JComponent {
-      val button = InlineIconButton(Companion.FILTER_ICON.originalIcon).apply {
-        border = JBUI.Borders.empty(3)
-      }.also {
-        it.actionListener = ActionListener { _ ->
-          showQuickFiltersPopup(it, quickFilters)
-        }
+      val toolbar = ActionManager.getInstance().createActionToolbar(
+        "Review.FilterToolbar",
+        DefaultActionGroup(FilterPopupMenuAction(quickFilters)),
+        true
+      ).apply {
+        layoutPolicy = ActionToolbar.NOWRAP_LAYOUT_POLICY
+        component.isOpaque = false
+        component.border = null
+        targetComponent = null
       }
 
       viewScope.launch {
         vm.searchState.collect {
       }
 
       viewScope.launch {
         vm.searchState.collect {
-          button.icon = if (it.filterCount == 0) Companion.FILTER_ICON.originalIcon else Companion.FILTER_ICON.getLiveIndicatorIcon(true)
+          toolbar.updateActionsImmediately()
         }
       }
         }
       }
-
-      return button
+      return toolbar.component
     }
 
     private fun showQuickFiltersPopup(parentComponent: JComponent, quickFilters: List<Q>) {
     }
 
     private fun showQuickFiltersPopup(parentComponent: JComponent, quickFilters: List<Q>) {
@@ -120,6 +120,16 @@ abstract class ReviewListSearchPanelFactory<S : ReviewListSearchValue, Q : Revie
         .showUnderneathOf(parentComponent)
     }
 
         .showUnderneathOf(parentComponent)
     }
 
+    private inner class FilterPopupMenuAction(private val quickFilters: List<Q>) : AnActionButton() {
+      override fun updateButton(e: AnActionEvent) {
+        e.presentation.icon = FILTER_ICON.getLiveIndicatorIcon(vm.searchState.value.filterCount != 0)
+      }
+
+      override fun actionPerformed(e: AnActionEvent) {
+        showQuickFiltersPopup(e.inputEvent.component as JComponent, quickFilters)
+      }
+    }
+
     private inner class QuickFilterAction(name: @Nls String, private val search: S)
       : DumbAwareAction(name), Toggleable {
       override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
     private inner class QuickFilterAction(name: @Nls String, private val search: S)
       : DumbAwareAction(name), Toggleable {
       override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT