From f672acfc2791b3588dd4e5e2a3b3f792c642de84 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 7 Dec 2016 20:43:30 +0300 Subject: [PATCH] ui: allow to pass custom "Do Not Ask" checkbox --- .../intellij/openapi/ui/DialogWrapper.java | 20 +++++++++++++------ .../ShowSouthPanelTestDialogAction.java | 15 +++++++------- .../changes/conflicts/MoveChangesDialog.java | 7 ++++--- .../patch/ApplyPatchFromClipboardAction.java | 7 ++++--- .../shelf/UnshelveWithDialogAction.java | 8 ++++---- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java index 60ab85cd577a..a86bb5965ab4 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java @@ -569,7 +569,7 @@ public abstract class DialogWrapper { } @NotNull - public static JPanel addDoNotShowCheckBox(@NotNull JComponent southPanel, @NotNull JCheckBox checkBox) { + private static JPanel addDoNotShowCheckBox(@NotNull JComponent southPanel, @NotNull JComponent checkBox) { final JPanel panel = new JPanel(new BorderLayout()); JPanel wrapper = new JPanel(new GridBagLayout()); @@ -656,11 +656,14 @@ public abstract class DialogWrapper { if (doNotAsk != null) { myCheckBoxDoNotShowDialog = new JCheckBox(doNotAsk.getDoNotShowMessage()); - if (doNotAsk.canBeHidden()) { - panel = addDoNotShowCheckBox(panel, myCheckBoxDoNotShowDialog); - myCheckBoxDoNotShowDialog.setSelected(!doNotAsk.isToBeShown()); - DialogUtil.registerMnemonic(myCheckBoxDoNotShowDialog, '&'); - } + myCheckBoxDoNotShowDialog.setVisible(doNotAsk.canBeHidden()); + myCheckBoxDoNotShowDialog.setSelected(!doNotAsk.isToBeShown()); + DialogUtil.registerMnemonic(myCheckBoxDoNotShowDialog, '&'); + } + + JComponent doNotAskCheckbox = createDoNotAskCheckbox(); + if (doNotAskCheckbox != null) { + panel = addDoNotShowCheckBox(panel, doNotAskCheckbox); } if (getStyle() == DialogStyle.COMPACT) { @@ -675,6 +678,11 @@ public abstract class DialogWrapper { return panel; } + @Nullable + protected JComponent createDoNotAskCheckbox() { + return myCheckBoxDoNotShowDialog != null && myCheckBoxDoNotShowDialog.isVisible() ? myCheckBoxDoNotShowDialog : null; + } + @NotNull private JPanel createButtonsPanel(@NotNull List buttons) { int hgap = SystemInfo.isMacOSLeopard ? UIUtil.isUnderIntelliJLaF() ? 8 : 0 : 5; diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/ShowSouthPanelTestDialogAction.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/ShowSouthPanelTestDialogAction.java index 50b43a6f3e4a..93e6d7224acc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/ShowSouthPanelTestDialogAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/ShowSouthPanelTestDialogAction.java @@ -18,12 +18,12 @@ package com.intellij.openapi.wm.impl.status; import com.intellij.ide.ui.UISettings; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.MacOtherAction; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.OptionAction; import com.intellij.ui.components.panels.Wrapper; -import com.intellij.util.ObjectUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -105,12 +105,7 @@ public class ShowSouthPanelTestDialogAction extends AnAction implements DumbAwar } private void refreshSouthPanel() { - JComponent southPanel = super.createSouthPanel(); - if (myHasDoNotShowCheckbox.isSelected()) { - southPanel = addDoNotShowCheckBox(ObjectUtils.assertNotNull(super.createSouthPanel()), new JCheckBox("Do not show again")); - } - - mySouthPanel.setContent(southPanel); + mySouthPanel.setContent(super.createSouthPanel()); pack(); } @@ -143,6 +138,12 @@ public class ShowSouthPanelTestDialogAction extends AnAction implements DumbAwar return myCompact.isSelected() ? DialogStyle.COMPACT : DialogStyle.NO_STYLE; } + @Nullable + @Override + protected JComponent createDoNotAskCheckbox() { + return myHasDoNotShowCheckbox.isSelected() ? new JCheckBox("Do not show again") : null; + } + @Override protected boolean shouldAddErrorNearButtons() { return myMoveErrorTextToButtons.isSelected(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/conflicts/MoveChangesDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/conflicts/MoveChangesDialog.java index f7d8fbdc82c7..2c86570caa52 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/conflicts/MoveChangesDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/conflicts/MoveChangesDialog.java @@ -31,6 +31,7 @@ import com.intellij.openapi.vcs.changes.ui.TreeModelBuilder; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.components.JBCheckBox; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.DefaultTreeModel; @@ -134,10 +135,10 @@ public class MoveChangesDialog extends DialogWrapper { return !getIncludedChanges().isEmpty(); } + @Nullable @Override - protected JComponent createSouthPanel() { - JComponent panel = super.createSouthPanel(); - return addDoNotShowCheckBox(panel, myCheckBox); + protected JComponent createDoNotAskCheckbox() { + return myCheckBox; } /* diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchFromClipboardAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchFromClipboardAction.java index a7f6d7c6cc34..d04f9b94ff7a 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchFromClipboardAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchFromClipboardAction.java @@ -9,8 +9,8 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsApplicationSettings; import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.testFramework.LightVirtualFile; -import com.intellij.util.ObjectUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.event.ActionEvent; @@ -47,9 +47,10 @@ public class ApplyPatchFromClipboardAction extends DumbAwareAction { null, null, null, false); } + @Nullable @Override - protected JComponent createSouthPanel() { - return addDoNotShowCheckBox(ObjectUtils.assertNotNull(super.createSouthPanel()), FLY_OPTION_PANEL); + protected JComponent createDoNotAskCheckbox() { + return FLY_OPTION_PANEL; } @NotNull diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveWithDialogAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveWithDialogAction.java index f0684baf9a0b..3df376d25ad7 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveWithDialogAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/UnshelveWithDialogAction.java @@ -90,8 +90,8 @@ public class UnshelveWithDialogAction extends DumbAwareAction { VcsBundle.message("unshelve.changelist.chooser.title"), suggestedName) { @Nullable @Override - protected JComponent createSouthPanel() { - return addDoNotShowCheckBox(ObjectUtils.assertNotNull(super.createSouthPanel()), createRemoveFilesStrategyCheckbox(project)); + protected JComponent createDoNotAskCheckbox() { + return createRemoveFilesStrategyCheckbox(project); } }; @@ -127,8 +127,8 @@ public class UnshelveWithDialogAction extends DumbAwareAction { @Nullable @Override - protected JComponent createSouthPanel() { - return addDoNotShowCheckBox(ObjectUtils.assertNotNull(super.createSouthPanel()), createRemoveFilesStrategyCheckbox(myProject)); + protected JComponent createDoNotAskCheckbox() { + return createRemoveFilesStrategyCheckbox(myProject); } }