mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-186881 Improve Data Sharing options dialog
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.ide.actions;
|
||||
|
||||
import com.intellij.ide.gdpr.Consent;
|
||||
import com.intellij.ide.gdpr.ConsentOptions;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.ui.AppUIUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class DataSharingOptionsAction extends DumbAwareAction {
|
||||
public DataSharingOptionsAction() {
|
||||
super("Data Sharing Options...", "Data Sharing Options", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final Pair<Collection<Consent>, Boolean> consentsToShow = ConsentOptions.getInstance().getConsents();
|
||||
try {
|
||||
final Collection<Consent> result = AppUIUtil.confirmConsentOptions(consentsToShow.first);
|
||||
if (result != null) {
|
||||
ConsentOptions.getInstance().setConsents(result);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.getInstance(DataSharingOptionsAction.class).warn(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2000-2018 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.ide.gdpr;
|
||||
|
||||
import com.intellij.openapi.options.ConfigurableBase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ConsentConfigurable extends ConfigurableBase<ConsentSettingsUi, List<Consent>> {
|
||||
private final List<Consent> myConsents;
|
||||
|
||||
public ConsentConfigurable() {
|
||||
super("consents", "Analytics", null);
|
||||
myConsents = new ArrayList<>(ConsentOptions.getInstance().getConsents().first);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<Consent> getSettings() {
|
||||
return myConsents;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConsentSettingsUi createUi() {
|
||||
return new ConsentSettingsUi(true);
|
||||
}
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public final class ConsentOptions {
|
||||
}
|
||||
}
|
||||
|
||||
public Pair<Collection<Consent>, Boolean> getConsents() {
|
||||
public Pair<List<Consent>, Boolean> getConsents() {
|
||||
final Map<String, Consent> allDefaults = loadDefaultConsents();
|
||||
if (allDefaults.isEmpty()) {
|
||||
return Pair.create(Collections.emptyList(), Boolean.FALSE);
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
// Copyright 2000-2018 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.ide.gdpr;
|
||||
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.openapi.options.ConfigurableUi;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.HyperlinkAdapter;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.SwingHelper;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
import javax.swing.text.html.StyleSheet;
|
||||
import java.awt.*;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
|
||||
import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
|
||||
|
||||
public class ConsentSettingsUi extends JPanel implements ConfigurableUi<List<Consent>> {
|
||||
final Collection<Pair<JCheckBox, Consent>> consentMapping = new ArrayList<>();
|
||||
private final boolean myPreferencesMode;
|
||||
|
||||
public ConsentSettingsUi(boolean preferencesMode) {
|
||||
myPreferencesMode = preferencesMode;
|
||||
setLayout(new GridLayout(1, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(@NotNull List<Consent> consents) {
|
||||
consentMapping.clear();
|
||||
if (consents.isEmpty()) {
|
||||
JLabel label = new JLabel("There are no data-sharing options available", SwingConstants.CENTER);
|
||||
label.setVerticalAlignment(SwingConstants.CENTER);
|
||||
label.setOpaque(true);
|
||||
label.setBackground(JBColor.background());
|
||||
removeAll();
|
||||
add(label);
|
||||
return;
|
||||
}
|
||||
final JPanel body = new JPanel(new GridBagLayout());
|
||||
|
||||
boolean addCheckBox = myPreferencesMode || consents.size() > 1;
|
||||
for (Iterator<Consent> it = consents.iterator(); it.hasNext(); ) {
|
||||
final Consent consent = it.next();
|
||||
final JComponent comp = createConsentElement(consent, addCheckBox);
|
||||
boolean lastConsent = !it.hasNext();
|
||||
if (lastConsent) {
|
||||
body.setBackground(comp.getBackground());
|
||||
} else {
|
||||
comp.setBorder(JBUI.Borders.emptyBottom(15));
|
||||
}
|
||||
body.add(comp, new GridBagConstraints(
|
||||
0, GridBagConstraints.RELATIVE, 1, 1, 1.0, lastConsent && myPreferencesMode ? 1.0 : 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.insets(10, 0, 0, 0), 0, 0)
|
||||
);
|
||||
}
|
||||
if (!myPreferencesMode) {
|
||||
JLabel hintLabel = new JBLabel("You can always change this behavior in " + ShowSettingsUtil.getSettingsMenuName() + " | Appearance & Behavior | System Settings | Analytics.");
|
||||
hintLabel.setEnabled(false);
|
||||
hintLabel.setVerticalAlignment(SwingConstants.TOP);
|
||||
hintLabel.setFont(JBUI.Fonts.smallFont());
|
||||
//noinspection UseDPIAwareInsets
|
||||
body.add(hintLabel, new GridBagConstraints(
|
||||
0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
|
||||
new Insets(JBUI.scale(16), addCheckBox ? UIUtil.getCheckBoxTextHorizontalOffset(new JCheckBox()) : JBUI.scale(10), JBUI.scale(10), 0), 0, 0)
|
||||
);
|
||||
}
|
||||
body.setBorder(JBUI.Borders.empty(10));
|
||||
removeAll();
|
||||
add(new JBScrollPane(body, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JComponent createConsentElement(Consent consent, boolean addCheckBox) {
|
||||
//TODO: refactor DocumentationComponent to use external link marker here, there and everywhere
|
||||
final JEditorPane viewer = SwingHelper.createHtmlViewer(true, null, JBColor.WHITE, JBColor.BLACK);
|
||||
viewer.setFocusable(false);
|
||||
viewer.setCaret(new DefaultCaret(){
|
||||
@Override
|
||||
protected void adjustVisibility(Rectangle nloc) {
|
||||
//do nothing to avoid autoscroll
|
||||
}
|
||||
});
|
||||
viewer.addHyperlinkListener(new HyperlinkAdapter() {
|
||||
@Override
|
||||
protected void hyperlinkActivated(HyperlinkEvent e) {
|
||||
final URL url = e.getURL();
|
||||
if (url != null) {
|
||||
BrowserUtil.browse(url);
|
||||
}
|
||||
}
|
||||
});
|
||||
viewer.setText("<html>" + StringUtil.replace(consent.getText(), "\n", "<br>") + "</html>");
|
||||
StyleSheet styleSheet = ((HTMLDocument)viewer.getDocument()).getStyleSheet();
|
||||
//styleSheet.addRule("body {font-family: \"Segoe UI\", Tahoma, sans-serif;}");
|
||||
styleSheet.addRule("body {margin-top:0;padding-top:0;}");
|
||||
//styleSheet.addRule("body {font-size:" + JBUI.scaleFontSize(13) + "pt;}");
|
||||
styleSheet.addRule("h2, em {margin-top:" + JBUI.scaleFontSize(20) + "pt;}");
|
||||
styleSheet.addRule("h1, h2, h3, p, h4, em {margin-bottom:0;padding-bottom:0;}");
|
||||
styleSheet.addRule("p, h1 {margin-top:0;padding-top:"+JBUI.scaleFontSize(6)+"pt;}");
|
||||
styleSheet.addRule("li {margin-bottom:" + JBUI.scaleFontSize(6) + "pt;}");
|
||||
styleSheet.addRule("h2 {margin-top:0;padding-top:"+JBUI.scaleFontSize(13)+"pt;}");
|
||||
viewer.setCaretPosition(0);
|
||||
|
||||
final JPanel pane = new JPanel(new BorderLayout());
|
||||
pane.setBackground(viewer.getBackground());
|
||||
int leftInset = JBUI.scale(10);
|
||||
if (addCheckBox) {
|
||||
final JCheckBox cb = new JBCheckBox(consent.getName(), consent.isAccepted());
|
||||
cb.setBackground(viewer.getBackground());
|
||||
cb.setFont(cb.getFont().deriveFont(Font.BOLD));
|
||||
leftInset = UIUtil.getCheckBoxTextHorizontalOffset(cb);
|
||||
consentMapping.add(Pair.create(cb, consent));
|
||||
pane.add(cb, BorderLayout.NORTH);
|
||||
} else {
|
||||
consentMapping.add(Pair.create(null, consent));
|
||||
}
|
||||
//noinspection UseDPIAwareBorders
|
||||
viewer.setBorder(new EmptyBorder(addCheckBox ? 0 : JBUI.scale(5), leftInset, 0, 0));
|
||||
pane.add(viewer, BorderLayout.CENTER);
|
||||
return pane;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<Consent> getState() {
|
||||
final List<Consent> result = new ArrayList<>();
|
||||
for (Pair<JCheckBox, Consent> pair : consentMapping) {
|
||||
JCheckBox checkBox = pair.first;
|
||||
result.add(pair.second.derive(checkBox == null || checkBox.isSelected()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isModified(@NotNull List<Consent> consents) {
|
||||
List<Consent> state = getState();
|
||||
if (consents.size() != state.size()) return true;
|
||||
for (int i = 0; i < state.size(); i++) {
|
||||
Consent consent1 = state.get(i);
|
||||
Consent consent2 = consents.get(i);
|
||||
if (!consent1.equals(consent2)) return true;
|
||||
if (consent1.isAccepted() != consent2.isAccepted()) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(@NotNull List<Consent> consents) {
|
||||
consents.clear();
|
||||
consents.addAll(getState());
|
||||
if (myPreferencesMode) {
|
||||
ConsentOptions.getInstance().setConsents(consents);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JComponent getComponent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.intellij.ui;
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.ide.gdpr.Consent;
|
||||
import com.intellij.ide.gdpr.ConsentOptions;
|
||||
import com.intellij.ide.gdpr.ConsentSettingsUi;
|
||||
import com.intellij.ide.gdpr.EndUserAgreement;
|
||||
import com.intellij.idea.Main;
|
||||
import com.intellij.openapi.application.Application;
|
||||
@@ -36,10 +37,9 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.openapi.wm.ex.WindowManagerEx;
|
||||
import com.intellij.ui.AppIcon.MacAppIcon;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -54,25 +54,23 @@ import sun.awt.AWTAccessor;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.plaf.ButtonUI;
|
||||
import javax.swing.plaf.basic.BasicRadioButtonUI;
|
||||
import javax.swing.plaf.synth.SynthCheckBoxUI;
|
||||
import javax.swing.plaf.synth.SynthContext;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
import javax.swing.text.html.StyleSheet;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.AdjustmentEvent;
|
||||
import java.awt.event.AdjustmentListener;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static javax.swing.ScrollPaneConstants.*;
|
||||
import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
|
||||
import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -266,7 +264,7 @@ public class AppUIUtil {
|
||||
Logger.getInstance(AppUIUtil.class).warn(e);
|
||||
}
|
||||
}
|
||||
final Pair<Collection<Consent>, Boolean> consentsToShow = ConsentOptions.getInstance().getConsents();
|
||||
final Pair<List<Consent>, Boolean> consentsToShow = ConsentOptions.getInstance().getConsents();
|
||||
if (consentsToShow.second) {
|
||||
try {
|
||||
final Ref<Collection<Consent>> result = Ref.create(null);
|
||||
@@ -366,11 +364,12 @@ public class AppUIUtil {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
// todo: need a separate action to view and change state of all consets on demand
|
||||
|
||||
public static Collection<Consent> confirmConsentOptions(@NotNull Collection<Consent> consents) {
|
||||
final Collection<Pair<JCheckBox, Consent>> consentMapping = new ArrayList<>();
|
||||
final DialogWrapper dialog = new DialogWrapper(true) {
|
||||
@Nullable
|
||||
public static List<Consent> confirmConsentOptions(@NotNull List<Consent> consents) {
|
||||
if (consents.isEmpty()) return null;
|
||||
|
||||
ConsentSettingsUi ui = new ConsentSettingsUi(false);
|
||||
final DialogWrapper dialog = new DialogWrapper(WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow(), true) {
|
||||
@Nullable
|
||||
@Override
|
||||
protected Border createContentPaneBorder() {
|
||||
@@ -389,89 +388,24 @@ public class AppUIUtil {
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
|
||||
if (consents.isEmpty()) {
|
||||
JLabel label = new JLabel("There are no data-sharing options available", SwingConstants.CENTER);
|
||||
label.setVerticalAlignment(SwingConstants.CENTER);
|
||||
label.setOpaque(true);
|
||||
label.setBackground(JBColor.background());
|
||||
return label;
|
||||
}
|
||||
final JPanel body = new JPanel(new GridBagLayout());
|
||||
|
||||
//noinspection UseDPIAwareInsets
|
||||
body.add(new JLabel("Please review your options regarding sharing your data with " + ApplicationInfoImpl.getShadowInstance().getShortCompanyName() + ":"),
|
||||
new GridBagConstraints(
|
||||
0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH,
|
||||
new Insets(JBUI.scale(10), getLeftTextMargin(new JCheckBox()), JBUI.scale(10), 0), 0, 0));
|
||||
for (Iterator<Consent> it = consents.iterator(); it.hasNext(); ) {
|
||||
final Consent consent = it.next();
|
||||
final JComponent comp = createConsentElement(consent);
|
||||
boolean lastConsent = !it.hasNext();
|
||||
if (lastConsent) {
|
||||
body.setBackground(comp.getBackground());
|
||||
} else {
|
||||
comp.setBorder(JBUI.Borders.emptyBottom(15));
|
||||
}
|
||||
body.add(comp, new GridBagConstraints(
|
||||
0, GridBagConstraints.RELATIVE, 1, 1, 1.0, lastConsent ? 1.0 : 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.insets(10, 0, 0, 0), 0, 0)
|
||||
);
|
||||
}
|
||||
body.setBorder(JBUI.Borders.empty(10));
|
||||
return new JBScrollPane(body, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
return ui.getComponent();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JComponent createConsentElement(Consent consent) {
|
||||
final JEditorPane viewer = SwingHelper.createHtmlViewer(true, null, JBColor.WHITE, JBColor.BLACK);
|
||||
viewer.setFocusable(false);
|
||||
viewer.setCaret(new DefaultCaret(){
|
||||
@Override
|
||||
protected Action[] createActions() {
|
||||
if (consents.size() > 1) {
|
||||
return super.createActions();
|
||||
}
|
||||
setOKButtonText(consents.iterator().next().getName());
|
||||
return new Action[]{getOKAction(), new DialogWrapperAction("Don't send") {
|
||||
@Override
|
||||
protected void adjustVisibility(Rectangle nloc) {
|
||||
//do nothing to avoid autoscroll
|
||||
protected void doAction(ActionEvent e) {
|
||||
close(NEXT_USER_EXIT_CODE);
|
||||
}
|
||||
});
|
||||
viewer.addHyperlinkListener(new HyperlinkAdapter() {
|
||||
@Override
|
||||
protected void hyperlinkActivated(HyperlinkEvent e) {
|
||||
final URL url = e.getURL();
|
||||
if (url != null) {
|
||||
BrowserUtil.browse(url);
|
||||
}
|
||||
}
|
||||
});
|
||||
viewer.setText(consentTextToHtml(consent.getText()));
|
||||
StyleSheet styleSheet = ((HTMLDocument)viewer.getDocument()).getStyleSheet();
|
||||
//styleSheet.addRule("body {font-family: \"Segoe UI\", Tahoma, sans-serif;}");
|
||||
styleSheet.addRule("body {margin-top:0;padding-top:0;}");
|
||||
//styleSheet.addRule("body {font-size:" + JBUI.scaleFontSize(13) + "pt;}");
|
||||
styleSheet.addRule("h2, em {margin-top:" + JBUI.scaleFontSize(20) + "pt;}");
|
||||
styleSheet.addRule("h1, h2, h3, p, h4, em {margin-bottom:0;padding-bottom:0;}");
|
||||
styleSheet.addRule("p, h1 {margin-top:0;padding-top:"+JBUI.scaleFontSize(6)+"pt;}");
|
||||
styleSheet.addRule("li {margin-bottom:" + JBUI.scaleFontSize(6) + "pt;}");
|
||||
styleSheet.addRule("h2 {margin-top:0;padding-top:"+JBUI.scaleFontSize(13)+"pt;}");
|
||||
viewer.setCaretPosition(0);
|
||||
|
||||
final JCheckBox cb = new JBCheckBox(consent.getName(), consent.isAccepted());
|
||||
cb.setBackground(viewer.getBackground());
|
||||
cb.setFont(cb.getFont().deriveFont(Font.BOLD));
|
||||
int leftInset = getLeftTextMargin(cb);
|
||||
//noinspection UseDPIAwareBorders
|
||||
viewer.setBorder(new EmptyBorder(JBUI.scale(5), leftInset, 0, 0));
|
||||
|
||||
final JPanel pane = new JPanel(new BorderLayout());
|
||||
pane.setBackground(viewer.getBackground());
|
||||
pane.add(cb, BorderLayout.NORTH);
|
||||
pane.add(viewer, BorderLayout.CENTER);
|
||||
consentMapping.add(Pair.create(cb, consent));
|
||||
return pane;
|
||||
}};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String consentTextToHtml(String text) {
|
||||
return "<html>" + StringUtil.replace(text, "\n", "<br>") + "</html>";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createDefaultActions() {
|
||||
super.createDefaultActions();
|
||||
@@ -480,22 +414,25 @@ public class AppUIUtil {
|
||||
}
|
||||
|
||||
};
|
||||
ui.reset(consents);
|
||||
dialog.setModal(true);
|
||||
dialog.setTitle("Data Sharing Options");
|
||||
dialog.setSize(JBUI.scale(600), JBUI.scale(400));
|
||||
dialog.setTitle("Analytics");
|
||||
dialog.pack();
|
||||
dialog.setSize(JBUI.scale(600), dialog.getWindow().getHeight() * 4 / 3);
|
||||
//dialog.setSize(JBUI.scale(600), JBUI.scale(400));
|
||||
dialog.show();
|
||||
|
||||
final Collection<Consent> result;
|
||||
if (dialog.isOK()) {
|
||||
result = new ArrayList<>();
|
||||
for (Pair<JCheckBox, Consent> pair : consentMapping) {
|
||||
result.add(pair.second.derive(pair.first.isSelected()));
|
||||
}
|
||||
int exitCode = dialog.getExitCode();
|
||||
if (exitCode == DialogWrapper.CANCEL_EXIT_CODE) {
|
||||
return null; //Don't save any changes in this case: user hasn't made a choice
|
||||
}
|
||||
else {
|
||||
// no changes were made, save as-is
|
||||
result = consents;
|
||||
if (consents.size() == 1) {
|
||||
consents.set(0, consents.get(0).derive(exitCode == DialogWrapper.OK_EXIT_CODE));
|
||||
return consents;
|
||||
}
|
||||
|
||||
List<Consent> result = new ArrayList<>();
|
||||
ui.apply(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -521,29 +458,4 @@ public class AppUIUtil {
|
||||
GraphicsConfiguration gc = target != null ? target.getGraphicsConfiguration() : null;
|
||||
AWTAccessor.getComponentAccessor().setGraphicsConfiguration(comp, gc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns distance (px) from the left edge to actual text position for specified checkbox.
|
||||
* It may be used as left margin when you need to align text in a label located above or below the checkbox
|
||||
*/
|
||||
public static int getLeftTextMargin(@NotNull JCheckBox checkBox) {
|
||||
int leftMargin = 0;
|
||||
Insets margin = checkBox.getMargin();
|
||||
if (margin != null) leftMargin += margin.left;
|
||||
Border border = checkBox.getBorder();
|
||||
if (border != null) leftMargin += border.getBorderInsets(checkBox).left;
|
||||
ButtonUI ui = checkBox.getUI();
|
||||
Icon icon = null;
|
||||
if (ui instanceof BasicRadioButtonUI) {
|
||||
icon = ((BasicRadioButtonUI)ui).getDefaultIcon();
|
||||
} else if (ui instanceof SynthCheckBoxUI){
|
||||
SynthCheckBoxUI sui = (SynthCheckBoxUI)ui;
|
||||
SynthContext context = sui.getContext(checkBox);
|
||||
icon = context.getStyle().getIcon(context, "CheckBox.icon");
|
||||
}
|
||||
if (icon != null) {
|
||||
leftMargin += icon.getIconWidth() + checkBox.getIconTextGap();
|
||||
}
|
||||
return leftMargin;
|
||||
}
|
||||
}
|
||||
@@ -322,6 +322,7 @@
|
||||
<actionFromOptionDescriptorProvider implementation="com.intellij.ide.plugins.InstalledPluginsManagerMain$PluginsActionFromOptionDescriptorProvider"/>
|
||||
<customFileDropHandler implementation="com.intellij.ide.plugins.InstalledPluginsManagerMain$PluginDropHandler"/>
|
||||
<applicationConfigurable parentId="preferences.general" instance="com.intellij.util.net.HttpProxyConfigurable" id="http.proxy" displayName="HTTP Proxy"/>
|
||||
<applicationConfigurable parentId="preferences.general" instance="com.intellij.ide.gdpr.ConsentConfigurable" id="consents" displayName="Analytics"/>
|
||||
<applicationConfigurable groupId="tools" displayName="Server Certificates" id="http.certificates" instance="com.intellij.util.net.ssl.CertificateConfigurable"/>
|
||||
|
||||
<fileTypeFactory implementation="com.intellij.openapi.fileTypes.impl.PlatformFileTypeFactory"/>
|
||||
|
||||
@@ -558,7 +558,6 @@
|
||||
<action id="EditCustomProperties" class="com.intellij.ide.actions.EditCustomPropertiesAction"/>
|
||||
<action id="EditCustomVmOptions" class="com.intellij.ide.actions.EditCustomVmOptionsAction"/>
|
||||
<action id="LogDebugConfigure" class="com.intellij.ide.actions.DebugLogConfigureAction"/>
|
||||
<action id="DataSharingOptions" class="com.intellij.ide.actions.DataSharingOptionsAction"/>
|
||||
<separator/>
|
||||
<action id="CheckForUpdate" class="com.intellij.openapi.updateSettings.impl.CheckForUpdateAction"/>
|
||||
<action id="About" class="com.intellij.ide.actions.AboutAction"/>
|
||||
|
||||
@@ -9,7 +9,6 @@ import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -35,7 +34,7 @@ public class ConsentsTest extends TestCase{
|
||||
final ConsentOptions options = data.first;
|
||||
final MemoryIOBackend storage = data.second;
|
||||
|
||||
final Pair<Collection<Consent>, Boolean> beforeConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> beforeConfirm = options.getConsents();
|
||||
assertTrue("Consents should require confirmation", beforeConfirm.second);
|
||||
assertEquals(2, beforeConfirm.first.size());
|
||||
checkStorage(storage, JSON_CONSENTS_DATA, "", "");
|
||||
@@ -50,7 +49,7 @@ public class ConsentsTest extends TestCase{
|
||||
options.setConsents(beforeConfirm.first);
|
||||
|
||||
{
|
||||
final Pair<Collection<Consent>, Boolean> afterConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> afterConfirm = options.getConsents();
|
||||
assertFalse("Consents should NOT require confirmation", afterConfirm.second);
|
||||
final Consent consentAfterCorfirm = lookupConsent(CONSENT_ID_1, afterConfirm.first);
|
||||
assertNotNull(consentAfterCorfirm);
|
||||
@@ -63,7 +62,7 @@ public class ConsentsTest extends TestCase{
|
||||
Thread.sleep(1L);// ensure timestamp changes
|
||||
options.applyServerUpdates(createUpgradeJson(CONSENT_ID_1, newAcceptedState));
|
||||
{
|
||||
final Pair<Collection<Consent>, Boolean> afterUpgrade = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> afterUpgrade = options.getConsents();
|
||||
assertFalse("Consents should NOT require confirmation", afterUpgrade.second); // no confirmation on minor updates required
|
||||
final Consent consentAfterUpgrade = lookupConsent(CONSENT_ID_1, afterUpgrade.first);
|
||||
assertNotNull(consentAfterUpgrade);
|
||||
@@ -77,7 +76,7 @@ public class ConsentsTest extends TestCase{
|
||||
final ConsentOptions options = data.first;
|
||||
final MemoryIOBackend storage = data.second;
|
||||
|
||||
final Pair<Collection<Consent>, Boolean> beforeConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> beforeConfirm = options.getConsents();
|
||||
assertTrue("Consents should require confirmation", beforeConfirm.second);
|
||||
assertEquals(2, beforeConfirm.first.size());
|
||||
checkStorage(storage, JSON_CONSENTS_DATA, "", "");
|
||||
@@ -86,7 +85,7 @@ public class ConsentsTest extends TestCase{
|
||||
assertEquals(Version.fromString("1.0"), consentBeforeUpgrade.getVersion());
|
||||
|
||||
options.setConsents(beforeConfirm.first);
|
||||
final Pair<Collection<Consent>, Boolean> afterConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> afterConfirm = options.getConsents();
|
||||
assertFalse("Consents should NOT require confirmation", afterConfirm.second);
|
||||
assertEquals(2, afterConfirm.first.size());
|
||||
assertEquals(JSON_CONSENTS_DATA, storage.myBundled);
|
||||
@@ -95,7 +94,7 @@ public class ConsentsTest extends TestCase{
|
||||
|
||||
options.applyServerUpdates(JSON_MINOR_UPGRADE_CONSENTS_DATA);
|
||||
|
||||
final Pair<Collection<Consent>, Boolean> afterUpdate = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> afterUpdate = options.getConsents();
|
||||
assertFalse("Consents should NOT require confirmation", afterUpdate.second);
|
||||
assertEquals(2, afterUpdate.first.size());
|
||||
assertEquals(JSON_CONSENTS_DATA, storage.myBundled);
|
||||
@@ -112,7 +111,7 @@ public class ConsentsTest extends TestCase{
|
||||
final MemoryIOBackend storage = data.second;
|
||||
|
||||
{
|
||||
final Pair<Collection<Consent>, Boolean> beforeConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> beforeConfirm = options.getConsents();
|
||||
assertTrue("Consents should require confirmation", beforeConfirm.second);
|
||||
assertEquals(2, beforeConfirm.first.size());
|
||||
checkStorage(storage, JSON_CONSENTS_DATA, "", "");
|
||||
@@ -128,7 +127,7 @@ public class ConsentsTest extends TestCase{
|
||||
|
||||
// after-confirmation state
|
||||
{
|
||||
final Pair<Collection<Consent>, Boolean> afterConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> afterConfirm = options.getConsents();
|
||||
assertFalse("Consents should NOT require confirmation", afterConfirm.second);
|
||||
assertEquals(2, afterConfirm.first.size());
|
||||
assertEquals(JSON_CONSENTS_DATA, storage.myBundled);
|
||||
@@ -140,7 +139,7 @@ public class ConsentsTest extends TestCase{
|
||||
// updates from server
|
||||
{
|
||||
options.applyServerUpdates(JSON_MAJOR_UPGRADE_CONSENTS_DATA);
|
||||
final Pair<Collection<Consent>, Boolean> afterUpdate = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> afterUpdate = options.getConsents();
|
||||
assertTrue("Consents should require confirmation", afterUpdate.second);
|
||||
assertEquals(2, afterUpdate.first.size());
|
||||
assertEquals(JSON_CONSENTS_DATA, storage.myBundled);
|
||||
@@ -166,7 +165,7 @@ public class ConsentsTest extends TestCase{
|
||||
}
|
||||
|
||||
{
|
||||
final Pair<Collection<Consent>, Boolean> afterSecondConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> afterSecondConfirm = options.getConsents();
|
||||
assertFalse("Consents should NOT require confirmation", afterSecondConfirm.second);
|
||||
assertEquals(2, afterSecondConfirm.first.size());
|
||||
assertEquals(JSON_CONSENTS_DATA, storage.myBundled);
|
||||
@@ -185,7 +184,7 @@ public class ConsentsTest extends TestCase{
|
||||
final ConsentOptions options = data.first;
|
||||
final MemoryIOBackend storage = data.second;
|
||||
|
||||
final Pair<Collection<Consent>, Boolean> beforeConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> beforeConfirm = options.getConsents();
|
||||
assertTrue("Consents should require confirmation", beforeConfirm.second);
|
||||
assertEquals(2, beforeConfirm.first.size());
|
||||
assertEquals(JSON_CONSENTS_DATA, storage.myDefaults);
|
||||
@@ -195,7 +194,7 @@ public class ConsentsTest extends TestCase{
|
||||
assertEquals(ConsentOptions.Permission.UNDEFINED, options.isSendingUsageStatsAllowed());
|
||||
|
||||
options.setConsents(beforeConfirm.first);
|
||||
final Pair<Collection<Consent>, Boolean> afterConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> afterConfirm = options.getConsents();
|
||||
assertFalse("Consents should NOT require confirmation", afterConfirm.second);
|
||||
assertEquals(2, afterConfirm.first.size());
|
||||
assertEquals("", storage.myBundled);
|
||||
@@ -209,7 +208,7 @@ public class ConsentsTest extends TestCase{
|
||||
final ConsentOptions options = data.first;
|
||||
final MemoryIOBackend storage = data.second;
|
||||
|
||||
final Pair<Collection<Consent>, Boolean> consents = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> consents = options.getConsents();
|
||||
assertTrue("Consents should require confirmation", consents.second);
|
||||
assertEquals(1, consents.first.size());
|
||||
assertEquals(JSON_DELETED_CONSENTS_DATA, storage.myDefaults);
|
||||
@@ -224,7 +223,7 @@ public class ConsentsTest extends TestCase{
|
||||
final ConsentOptions options = data.first;
|
||||
final MemoryIOBackend storage = data.second;
|
||||
|
||||
final Pair<Collection<Consent>, Boolean> beforeConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> beforeConfirm = options.getConsents();
|
||||
assertTrue("Consents should require confirmation", beforeConfirm.second);
|
||||
assertEquals(2, beforeConfirm.first.size());
|
||||
assertEquals("", storage.myBundled);
|
||||
@@ -237,7 +236,7 @@ public class ConsentsTest extends TestCase{
|
||||
}
|
||||
options.setConsents(changedByUser);
|
||||
|
||||
final Pair<Collection<Consent>, Boolean> afterConfirm = options.getConsents();
|
||||
final Pair<List<Consent>, Boolean> afterConfirm = options.getConsents();
|
||||
assertFalse("Consents should NOT require confirmation", afterConfirm.second);
|
||||
assertEquals(2, afterConfirm.first.size());
|
||||
assertEquals("", storage.myBundled);
|
||||
@@ -251,7 +250,7 @@ public class ConsentsTest extends TestCase{
|
||||
}
|
||||
}
|
||||
|
||||
private static Consent lookupConsent(@NotNull String consentId, @NotNull Collection<Consent> container) {
|
||||
private static Consent lookupConsent(@NotNull String consentId, @NotNull List<Consent> container) {
|
||||
for (Consent c : container) {
|
||||
if (consentId.equals(c.getId())) {
|
||||
return c;
|
||||
@@ -260,7 +259,7 @@ public class ConsentsTest extends TestCase{
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Consent lookupConsent(@NotNull Consent consent, @NotNull Collection<Consent> container) {
|
||||
private static Consent lookupConsent(@NotNull Consent consent, @NotNull List<Consent> container) {
|
||||
for (Consent c : container) {
|
||||
if (c.equals(consent)) {
|
||||
return c;
|
||||
|
||||
Reference in New Issue
Block a user