ui: allow to pass custom "Do Not Ask" checkbox

This commit is contained in:
Aleksey Pivovarov
2016-12-20 13:42:44 +03:00
parent 2d190fbbf0
commit f672acfc27
5 changed files with 34 additions and 23 deletions
@@ -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<JButton> buttons) {
int hgap = SystemInfo.isMacOSLeopard ? UIUtil.isUnderIntelliJLaF() ? 8 : 0 : 5;
@@ -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();
@@ -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;
}
/*
@@ -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
@@ -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);
}
}