Vcs: Fix commit option button
authorAleksandr Krasilnikov <aleksandr.krasilnikov@jetbrains.com>
Wed, 17 Aug 2022 11:05:53 +0000 (13:05 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Thu, 18 Aug 2022 14:26:23 +0000 (14:26 +0000)
GitOrigin-RevId: 6280abdb46d3f1c03271105dab79d58864f1df28

platform/vcs-impl/src/com/intellij/openapi/vcs/actions/ShowCommitOptionsAction.kt
platform/vcs-impl/src/com/intellij/vcs/commit/CommitActionsPanel.kt

index cc1a1ad3448a3533fcf17979114ed668ed9037dc..c014c950006a8e38a5698b31d7aad04a8ef7844b 100644 (file)
@@ -5,6 +5,7 @@ import com.intellij.icons.AllIcons
 import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.project.DumbAwareAction
+import com.intellij.ui.ExperimentalUI
 import com.intellij.vcs.commit.ChangesViewCommitWorkflowHandler
 import com.intellij.vcs.commit.NonModalCommitWorkflowHandler
 
@@ -21,6 +22,10 @@ class ShowCommitOptionsAction : DumbAwareAction() {
         is NonModalCommitWorkflowHandler<*, *> -> true
         else -> false
       }
+    if (ExperimentalUI.isNewUI()) {
+      e.presentation.icon = AllIcons.General.GearPlain
+      e.presentation.hoveredIcon = AllIcons.General.GearPlain
+    }
   }
 
   override fun getActionUpdateThread(): ActionUpdateThread {
index 6410c2aedd8f22b1e3c9f3ebd45b4dc637ff66ac..f79efd4941f2820426361c691fc9331f73fdca0f 100644 (file)
@@ -1,18 +1,15 @@
 // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
 package com.intellij.vcs.commit
 
-import com.intellij.icons.AllIcons
 import com.intellij.openapi.Disposable
 import com.intellij.openapi.actionSystem.*
 import com.intellij.openapi.actionSystem.ActionToolbar.NOWRAP_LAYOUT_POLICY
-import com.intellij.openapi.actionSystem.impl.ActionButton
 import com.intellij.openapi.project.DumbAwareAction
 import com.intellij.openapi.util.SystemInfo.isMac
 import com.intellij.ui.components.JBOptionButton
 import com.intellij.ui.components.JBOptionButton.Companion.getDefaultShowPopupShortcut
 import com.intellij.util.EventDispatcher
-import com.intellij.util.ui.JBUI
-import com.intellij.util.ui.components.BorderLayoutPanel
+import net.miginfocom.swing.MigLayout
 import org.jetbrains.annotations.Nls
 import java.awt.event.ActionEvent
 import java.awt.event.InputEvent.CTRL_DOWN_MASK
@@ -21,6 +18,7 @@ import java.awt.event.KeyEvent.VK_ENTER
 import javax.swing.AbstractAction
 import javax.swing.Action
 import javax.swing.JComponent
+import javax.swing.JPanel
 import javax.swing.KeyStroke.getKeyStroke
 
 private fun JBOptionButton.getBottomInset(): Int =
@@ -28,7 +26,7 @@ private fun JBOptionButton.getBottomInset(): Int =
   ?: (components.firstOrNull() as? JComponent)?.insets?.bottom
   ?: 0
 
-class CommitActionsPanel : BorderLayoutPanel(), CommitActionsUi {
+class CommitActionsPanel : JPanel(null), CommitActionsUi {
   private val executorEventDispatcher = EventDispatcher.create(CommitExecutorListener::class.java)
 
   private val defaultCommitAction = object : AbstractAction() {
@@ -52,29 +50,33 @@ class CommitActionsPanel : BorderLayoutPanel(), CommitActionsUi {
       component.border = null
     }
 
-  init {
-    addToLeft(commitButton)
-    addToCenter(primaryCommitActionsToolbar.component)
+  private val commitOptionToolbar = ActionManager.getInstance().createActionToolbar(
+    "ChangesView.ShowCommitOptions",
+    DefaultActionGroup(ActionManager.getInstance().getAction("ChangesView.ShowCommitOptions")),
+    true
+  ).apply {
+    setReservePlaceAutoPopupIcon(false)
+    layoutPolicy = NOWRAP_LAYOUT_POLICY
 
-    addToRight(createShowOptionButton())
+    component.isOpaque = false
+    component.border = null
   }
 
-  private fun createShowOptionButton(): ActionButton {
-    val presentation = Presentation().apply {
-      icon = AllIcons.General.GearPlain
-    }
-    val action = ActionManager.getInstance().getAction("ChangesView.ShowCommitOptions")
-    val actionButton = ActionButton(action, presentation, COMMIT_BUTTONS_TOOLBAR, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE).apply {
-      border = JBUI.Borders.empty(1, 2)
-    }
-    return actionButton
+  init {
+    layout = MigLayout("ins 0, fill", "[left]0[left, fill]push[pref:pref, right]", "center")
+    add(commitButton)
+    add(primaryCommitActionsToolbar.component)
+    add(commitOptionToolbar.component)
   }
 
   var isActive: Boolean = true
   var isCommitButtonDefault: () -> Boolean = { false }
 
   fun getBottomInset(): Int = commitButton.getBottomInset()
-  fun setTargetComponent(component: JComponent) = primaryCommitActionsToolbar.setTargetComponent(component)
+  fun setTargetComponent(component: JComponent) {
+    primaryCommitActionsToolbar.targetComponent = component
+    commitOptionToolbar.targetComponent = component
+  }
 
   fun createActions() = listOf(DefaultCommitAction(), ShowCustomCommitActions())