mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use ActionButton for Square Stripe buttons
GitOrigin-RevId: ce4fed7a161fab7baf70bbe89592b25eb8f12c60
This commit is contained in:
committed by
intellij-monorepo-bot
parent
debdee6540
commit
429d3fc5cf
@@ -151,6 +151,8 @@ public abstract class ActionPlaces {
|
||||
|
||||
public static final String QUICK_SWITCH_SCHEME_POPUP = "QuickSwitchSchemePopup";
|
||||
|
||||
public static final String TOOLWINDOW_SIDE_BAR = "ToolwindowSideBar";
|
||||
|
||||
/* Rider */
|
||||
public static final String RIDER_UNIT_TESTS_LEFT_TOOLBAR = "UnitTests.LeftToolbar";
|
||||
public static final String RIDER_UNIT_TESTS_TOP_TOOLBAR = "UnitTests.TopToolbar";
|
||||
|
||||
@@ -64,42 +64,41 @@ class IdeLeftToolbar(private val parentDisposable: @NotNull Disposable) : JPanel
|
||||
}
|
||||
|
||||
fun addStripeButton(project: Project, button: StripeButton) {
|
||||
val stickySquareButton = SquareStripeButton(button)
|
||||
if (PropertiesComponent.getInstance(project).getValues(STICKY_TW) == null) {
|
||||
ToolWindowSidebarProvider.getInstance().defaultToolwindows(project).forEach {
|
||||
saveTWid(project, it)
|
||||
}
|
||||
}
|
||||
|
||||
if (isTWSticky(project, stickySquareButton)) {
|
||||
if (isTWSticky(project, button)) {
|
||||
rebuildOrderedSquareButtons(project)
|
||||
}
|
||||
|
||||
addButtonOnExtendedPane(project, button, stickySquareButton)
|
||||
addButtonOnExtendedPane(project, button)
|
||||
}
|
||||
|
||||
private fun addButtonOnExtendedPane(project: Project, button: StripeButton, stickySquareButton: SquareStripeButton) {
|
||||
private fun addButtonOnExtendedPane(project: Project, button: StripeButton) {
|
||||
extendedBag.nextLine()
|
||||
extendedPane.apply {
|
||||
remove(horizontalGlue)
|
||||
add(SquareStripeButton(button), extendedBag.next())
|
||||
add(JLabel(button.text).apply { border = JBUI.Borders.emptyRight(50) }, extendedBag.next().anchor(GridBagConstraints.WEST))
|
||||
add(createOnOffButton(project, stickySquareButton), extendedBag.next().coverLine())
|
||||
add(createOnOffButton(project, button), extendedBag.next().coverLine())
|
||||
add(horizontalGlue, extendedBag.nextLine().next().weighty(1.0).fillCell().coverLine())
|
||||
}
|
||||
}
|
||||
|
||||
private fun createOnOffButton(project: Project, stickySquareButton: SquareStripeButton) =
|
||||
private fun createOnOffButton(project: Project, button: StripeButton) =
|
||||
OnOffButton().also {
|
||||
it.model.isSelected = isTWSticky(project, stickySquareButton)
|
||||
it.model.isSelected = isTWSticky(project, button)
|
||||
|
||||
it.addActionListener(object : AbstractAction() {
|
||||
override fun actionPerformed(e: ActionEvent) {
|
||||
if (it.isSelected) {
|
||||
addStickySquareStripeButton(project, stickySquareButton)
|
||||
addStickySquareStripeButton(project, button)
|
||||
}
|
||||
else {
|
||||
removeSquareStripeButton(project, stickySquareButton)
|
||||
removeSquareStripeButton(project, button)
|
||||
}
|
||||
squareButtonPane.revalidate()
|
||||
}
|
||||
@@ -110,18 +109,18 @@ class IdeLeftToolbar(private val parentDisposable: @NotNull Disposable) : JPanel
|
||||
squareButtonPane.removeAll()
|
||||
PropertiesComponent.getInstance(project).getValues(STICKY_TW).orEmpty().forEach { sticky ->
|
||||
val toolWindow = getInstance(project).getToolWindow(sticky) as ToolWindowImpl? ?: return@forEach
|
||||
squareButtonPane.add(SquareStripeButton(StripeButton(pane, toolWindow)))
|
||||
squareButtonPane.add(SquareStripeButton(StripeButton(pane, toolWindow).also { it.updatePresentation() }))
|
||||
}
|
||||
squareButtonPane.add(moreButton)
|
||||
}
|
||||
|
||||
private fun addStickySquareStripeButton(project: Project, stickySquareButton: SquareStripeButton) {
|
||||
saveTWid(project, stickySquareButton.toolWindow.id)
|
||||
private fun addStickySquareStripeButton(project: Project, button: StripeButton) {
|
||||
saveTWid(project, button.toolWindow.id)
|
||||
rebuildOrderedSquareButtons(project)
|
||||
}
|
||||
|
||||
private fun removeSquareStripeButton(project: Project, stickySquareButton: SquareStripeButton) {
|
||||
unsetTWid(project, stickySquareButton)
|
||||
private fun removeSquareStripeButton(project: Project, button: StripeButton) {
|
||||
unsetTWid(project, button)
|
||||
rebuildOrderedSquareButtons(project)
|
||||
}
|
||||
|
||||
@@ -129,6 +128,8 @@ class IdeLeftToolbar(private val parentDisposable: @NotNull Disposable) : JPanel
|
||||
extendedPane.isVisible = show
|
||||
}
|
||||
|
||||
fun isExtendedToolwindowPaneShown() = extendedPane.isVisible
|
||||
|
||||
companion object {
|
||||
private const val STICKY_TW = "STICKY_TW"
|
||||
|
||||
@@ -139,14 +140,14 @@ class IdeLeftToolbar(private val parentDisposable: @NotNull Disposable) : JPanel
|
||||
}
|
||||
}
|
||||
|
||||
private fun isTWSticky(project: Project, stickySquareButton: SquareStripeButton) =
|
||||
PropertiesComponent.getInstance(project).getValues(STICKY_TW)?.contains(stickySquareButton.toolWindow.id) ?: false
|
||||
private fun isTWSticky(project: Project, button: StripeButton) =
|
||||
PropertiesComponent.getInstance(project).getValues(STICKY_TW)?.contains(button.toolWindow.id) ?: false
|
||||
|
||||
private fun unsetTWid(project: Project, stickySquareButton: SquareStripeButton) {
|
||||
private fun unsetTWid(project: Project, button: StripeButton) {
|
||||
PropertiesComponent.getInstance(project).setValues(
|
||||
STICKY_TW,
|
||||
(PropertiesComponent.getInstance(project).getValues(STICKY_TW).orEmpty()).toMutableList().apply {
|
||||
remove(stickySquareButton.toolWindow.id)
|
||||
remove(button.toolWindow.id)
|
||||
}.toTypedArray().ifEmpty { null })
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,30 @@
|
||||
// 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 com.intellij.openapi.wm.impl;
|
||||
package com.intellij.openapi.wm.impl
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.openapi.actionSystem.ActionPlaces
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.Presentation
|
||||
import com.intellij.openapi.actionSystem.impl.ActionButton
|
||||
import com.intellij.openapi.project.DumbAware
|
||||
import com.intellij.ui.ToggleActionButton
|
||||
import java.awt.Dimension
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
class MoreSquareStripeButton(toolwindowSideBar: IdeLeftToolbar) :
|
||||
ActionButton(createAction(toolwindowSideBar), createPresentation(), ActionPlaces.TOOLWINDOW_SIDE_BAR, Dimension(40, 40)) {
|
||||
|
||||
public class MoreSquareStripeButton extends JToggleButton {
|
||||
private final IdeLeftToolbar myTWToolbar;
|
||||
companion object {
|
||||
fun createPresentation(): Presentation {
|
||||
return Presentation().apply {
|
||||
icon = AllIcons.Actions.More
|
||||
isEnabledAndVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
MoreSquareStripeButton(IdeLeftToolbar toolbar) {
|
||||
super(AllIcons.Actions.More);
|
||||
myTWToolbar = toolbar;
|
||||
|
||||
setBorder(JBUI.Borders.empty(5, 5, 0, 5));
|
||||
|
||||
addActionListener(e -> myTWToolbar.openExtendedToolwindowPane(model.isSelected()));
|
||||
|
||||
setRolloverEnabled(true);
|
||||
setOpaque(false);
|
||||
|
||||
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
|
||||
fun createAction(toolwindowSideBar: IdeLeftToolbar): ToggleActionButton =
|
||||
object : ToggleActionButton(Presentation.NULL_STRING, null), DumbAware {
|
||||
override fun isSelected(e: AnActionEvent?) = toolwindowSideBar.isExtendedToolwindowPaneShown()
|
||||
override fun setSelected(e: AnActionEvent?, state: Boolean) = toolwindowSideBar.openExtendedToolwindowPane(state)
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(40, 40);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUI() {
|
||||
setUI(MoreSquareStripeButtonUI.createMoreSquareUI(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +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 com.intellij.openapi.wm.impl;
|
||||
|
||||
import com.intellij.openapi.util.ScalableIcon;
|
||||
import com.intellij.util.IconUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.DimensionUIResource;
|
||||
import java.awt.*;
|
||||
|
||||
public class MoreSquareStripeButtonUI extends StripeButtonUI {
|
||||
public static ComponentUI createMoreSquareUI(JComponent c) {
|
||||
return new MoreSquareStripeButtonUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
return new DimensionUIResource(26, 26);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Graphics g, JComponent c) {
|
||||
MoreSquareStripeButton button = (MoreSquareStripeButton)c;
|
||||
|
||||
Icon icon = button.getIcon();
|
||||
if (icon instanceof ScalableIcon) {
|
||||
icon = ((ScalableIcon)icon).scale(1.4f);
|
||||
}
|
||||
|
||||
// Paint button's background
|
||||
Graphics2D g2 = (Graphics2D)g.create();
|
||||
try {
|
||||
ButtonModel model = button.getModel();
|
||||
|
||||
if (model.isArmed() && model.isPressed() || model.isSelected() || model.isRollover()) {
|
||||
g2.setColor(model.isSelected() ? SELECTED_BACKGROUND_COLOR : BACKGROUND_COLOR);
|
||||
g2.fillRect(0, 0, button.getWidth(), button.getHeight());
|
||||
}
|
||||
|
||||
if (icon != null) { // do not rotate icon
|
||||
IconUtil.paintInCenterOf(button, g2, icon);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,38 @@
|
||||
// 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 com.intellij.openapi.wm.impl
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionPlaces
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.Presentation
|
||||
import com.intellij.openapi.actionSystem.impl.ActionButton
|
||||
import com.intellij.openapi.project.DumbAware
|
||||
import com.intellij.openapi.util.ScalableIcon
|
||||
import com.intellij.ui.ToggleActionButton
|
||||
import java.awt.Dimension
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
open class SquareStripeButton(val button: StripeButton) : StripeButton(button.pane, button.toolWindow) {
|
||||
override fun getPreferredSize(): Dimension {
|
||||
return Dimension(40, 40)
|
||||
}
|
||||
class SquareStripeButton(button: StripeButton) : ActionButton(createAction(button), createPresentation(button),
|
||||
ActionPlaces.TOOLWINDOW_SIDE_BAR, Dimension(40, 40)) {
|
||||
companion object {
|
||||
fun createPresentation(button: StripeButton): Presentation {
|
||||
return Presentation(button.text).apply {
|
||||
icon = button.icon
|
||||
if (icon is ScalableIcon) icon = (icon as ScalableIcon).scale(1.4f)
|
||||
isEnabledAndVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateUI() {
|
||||
setUI(SquareStripeButtonUI.createSquareUI(this))
|
||||
fun createAction(button: StripeButton): ToggleActionButton =
|
||||
object : ToggleActionButton(button.text, null), DumbAware {
|
||||
override fun isSelected(e: AnActionEvent?) = button.toolWindow.isVisible
|
||||
override fun setSelected(e: AnActionEvent?, state: Boolean) {
|
||||
val manager = button.toolWindow.toolWindowManager
|
||||
if (!state) {
|
||||
manager.hideToolWindow(button.id, false, true, ToolWindowEventSource.StripeButton)
|
||||
}
|
||||
else {
|
||||
manager.activated(button.toolWindow, ToolWindowEventSource.StripeButton)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +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 com.intellij.openapi.wm.impl;
|
||||
|
||||
import com.intellij.openapi.util.ScalableIcon;
|
||||
import com.intellij.util.IconUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.DimensionUIResource;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class SquareStripeButtonUI extends StripeButtonUI {
|
||||
public static ComponentUI createSquareUI(JComponent c) {
|
||||
return new SquareStripeButtonUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
return new DimensionUIResource(26, 26);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Graphics g, JComponent c) {
|
||||
SquareStripeButton button = (SquareStripeButton)c;
|
||||
|
||||
//Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();
|
||||
Icon icon = button.getToolWindow().getIcon();
|
||||
if (icon instanceof ScalableIcon) {
|
||||
icon = ((ScalableIcon)icon).scale(1.4f);
|
||||
}
|
||||
|
||||
// Paint button's background
|
||||
Graphics2D g2 = (Graphics2D)g.create();
|
||||
try {
|
||||
ButtonModel model = button.getModel();
|
||||
|
||||
if (model.isArmed() && model.isPressed() || model.isSelected() || model.isRollover()) {
|
||||
g2.setColor(model.isSelected() ? SELECTED_BACKGROUND_COLOR : BACKGROUND_COLOR);
|
||||
g2.fillRect(0, 0, button.getWidth(), button.getHeight());
|
||||
}
|
||||
|
||||
if (icon != null) { // do not rotate icon
|
||||
IconUtil.paintInCenterOf(button, g2, icon);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -248,7 +248,7 @@ class PythonOnboardingTour(module: Module) :
|
||||
private fun LessonContext.openLearnToolwindow() {
|
||||
task {
|
||||
triggerByUiComponentAndHighlight { stripe: StripeButton ->
|
||||
(stripe !is SquareStripeButton) && stripe.windowInfo.id == "Learn"
|
||||
stripe.windowInfo.id == "Learn"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ class PythonOnboardingTour(module: Module) :
|
||||
}
|
||||
task {
|
||||
triggerByUiComponentAndHighlight { stripe: StripeButton ->
|
||||
(stripe !is SquareStripeButton) && stripe.windowInfo.id == "Project"
|
||||
stripe.windowInfo.id == "Project"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user