IJPL-141 HTTP proxy settings UI: add a link to open system proxy settings, implement navigation for MacOS and Windows

GitOrigin-RevId: f682638f25a8ca3b292ce7a44a25e2ddbebcd301
This commit is contained in:
Vadim Salavatov
2024-04-19 12:49:55 +02:00
committed by intellij-monorepo-bot
parent a9c502e8d3
commit 3276caa605
4 changed files with 100 additions and 13 deletions

View File

@@ -243,6 +243,7 @@ proxy.manual.exclude=No proxy for:
proxy.manual.exclude.example=Example\: *.domain.com, 192.168.*
proxy.manual.auth=Proxy &authentication
proxy.test.button=Check connection
proxy.system.proxy.settings=&System proxy settings...
date.dialog.title=Choose Date

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.util.net.HttpProxySettingsUi">
<grid id="111c4" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="12" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="111c4" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="12" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="1" y="44" width="1134" height="648"/>
<xy x="1" y="44" width="1134" height="654"/>
</constraints>
<properties/>
<border type="none"/>
@@ -11,7 +11,7 @@
<grid id="fe3b6" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="8" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -130,7 +130,7 @@
</grid>
<vspacer id="53d33">
<constraints>
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="11" column="0" row-span="1" col-span="2" vsize-policy="7" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="862df" class="com.intellij.ui.components.JBRadioButton" binding="myAutoDetectProxyRb" default-binding="true">
@@ -144,7 +144,7 @@
</component>
<component id="9e485" class="com.intellij.ui.components.JBRadioButton" binding="myUseHTTPProxyRb" default-binding="true">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/UIBundle" key="proxy.manual.rb"/>
@@ -152,7 +152,7 @@
</component>
<component id="4b9f9" class="javax.swing.JLabel" binding="mySystemProxyDefined">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/UIBundle" key="proxy.system.label"/>
@@ -162,7 +162,7 @@
</component>
<component id="b027d" class="com.intellij.ui.components.JBRadioButton" binding="myNoProxyRb">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/UIBundle" key="proxy.direct.rb"/>
@@ -171,7 +171,7 @@
<grid id="1bb9b" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false"/>
<grid row="7" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -196,7 +196,7 @@
</grid>
<component id="ffae6" class="javax.swing.JLabel" binding="myErrorLabel">
<constraints>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="10" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label" noi18n="true"/>
@@ -204,7 +204,7 @@
</component>
<component id="de36" class="javax.swing.JButton" binding="myCheckButton">
<constraints>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="9" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/UIBundle" key="proxy.test.button"/>
@@ -212,7 +212,7 @@
</component>
<component id="98030" class="javax.swing.JLabel" binding="myOtherWarning">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<verticalTextPosition value="1"/>
@@ -221,7 +221,7 @@
<grid id="fee34" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -246,12 +246,20 @@
</grid>
<component id="c299" class="javax.swing.JButton" binding="myClearPasswordsButton" default-binding="true">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/UIBundle" key="proxy.pac.pw.clear.button"/>
</properties>
</component>
<component id="c8100" class="com.intellij.ui.components.ActionLink" binding="mySystemProxySettingsLink">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/UIBundle" key="proxy.system.proxy.settings"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@@ -5,6 +5,7 @@ import com.intellij.ide.IdeBundle;
import com.intellij.notification.NotificationAction;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.ConfigurableUi;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.progress.ProgressManager;
@@ -15,6 +16,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.PortField;
import com.intellij.ui.RawCommandLineEditor;
import com.intellij.ui.RelativeFont;
import com.intellij.ui.components.ActionLink;
import com.intellij.ui.components.JBRadioButton;
import com.intellij.ui.jcef.JBCefApp;
import com.intellij.util.io.HttpRequests;
@@ -59,6 +61,7 @@ class HttpProxySettingsUi implements ConfigurableUi<HttpConfigurable> {
private JLabel myNoProxyForLabel;
private JCheckBox myPacUrlCheckBox;
private JTextField myPacUrlTextField;
private ActionLink mySystemProxySettingsLink;
@Override
public boolean isModified(@NotNull HttpConfigurable settings) {
@@ -110,6 +113,18 @@ class HttpProxySettingsUi implements ConfigurableUi<HttpConfigurable> {
IdeBundle.message("dialog.title.auto.detected.proxy"), Messages.getInformationIcon());
});
mySystemProxySettingsLink.setExternalLinkIcon();
mySystemProxySettingsLink.setAutoHideOnDisable(true);
mySystemProxySettingsLink.setEnabled(SystemProxySettings.getInstance().isProxySettingsOpenSupported());
mySystemProxySettingsLink.addActionListener((event) -> {
try {
SystemProxySettings.getInstance().openProxySettings();
} catch (Exception e) {
mySystemProxySettingsLink.setEnabled(false);
Logger.getInstance(HttpProxySettingsUi.class).error("failed to open system proxy settings", e);
}
});
configureCheckButton();
}

View File

@@ -0,0 +1,63 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.net;
import com.intellij.openapi.util.SystemInfoRt;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
abstract class SystemProxySettings {
public abstract void openProxySettings() throws IOException;
public abstract boolean isProxySettingsOpenSupported();
public static @NotNull SystemProxySettings getInstance() {
return Holder.instance;
}
private static class Holder {
private static final @NotNull SystemProxySettings instance;
static {
if (SystemInfoRt.isMac) {
instance = new MacOSSettings();
} else if (SystemInfoRt.isWindows) {
instance = new WindowsSettings();
} else {
instance = new UnsupportedOSSettings();
}
}
}
private static class MacOSSettings extends SystemProxySettings {
@Override
public void openProxySettings() throws IOException {
Desktop.getDesktop().browse(URI.create("x-apple.systempreferences:com.apple.Network-Settings.extension?Proxies"));
}
@Override
public boolean isProxySettingsOpenSupported() {
return SystemInfoRt.isMac && Desktop.isDesktopSupported();
}
}
private static class WindowsSettings extends SystemProxySettings {
@Override
public void openProxySettings() throws IOException {
Desktop.getDesktop().browse(URI.create("ms-settings:network-proxy"));
}
@Override
public boolean isProxySettingsOpenSupported() {
return SystemInfoRt.isWindows && Desktop.isDesktopSupported();
}
}
private static class UnsupportedOSSettings extends SystemProxySettings {
@Override
public void openProxySettings() { throw new UnsupportedOperationException(); }
@Override
public boolean isProxySettingsOpenSupported() { return false; }
}
}