mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Browser API cleanup (pornographically named method moved out of public interface)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,8 +21,6 @@ import com.intellij.openapi.options.UnnamedConfigurable;
|
||||
* @author spleaner
|
||||
*/
|
||||
public abstract class BrowserSettingsProvider implements UnnamedConfigurable {
|
||||
public void disposeUIResources() {
|
||||
}
|
||||
|
||||
public void applySettingsFromWindowsRegistry() {}
|
||||
@Override
|
||||
public void disposeUIResources() { }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -111,21 +111,6 @@ public class BrowserSettingsPanel extends JPanel {
|
||||
for (BrowserSettingsProvider settingsProvider : mySettingsProviders) {
|
||||
outerPanel.add(settingsProvider.createComponent());
|
||||
}
|
||||
if (SystemInfo.isWindows) {
|
||||
JPanel wrapperPanel = new JPanel(new BorderLayout());
|
||||
JButton registryButton = new JButton("Retrieve settings from Windows registry");
|
||||
registryButton.setMnemonic('W');
|
||||
registryButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (BrowserSettingsProvider settingsProvider : mySettingsProviders) {
|
||||
settingsProvider.applySettingsFromWindowsRegistry();
|
||||
}
|
||||
}
|
||||
});
|
||||
wrapperPanel.add(registryButton, BorderLayout.EAST);
|
||||
outerPanel.add(wrapperPanel);
|
||||
}
|
||||
|
||||
add(outerPanel, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
@@ -248,4 +248,6 @@ zen.coding.incorrect.abbreviation.error=Incorrect abbreviation
|
||||
title.cannot.create.html.file=Cannot create HTML file
|
||||
new.html.file.action=HTML File
|
||||
new.html.file.action.description=Creates new HTML file
|
||||
html5.outline.mode=HTML5 Outline
|
||||
html5.outline.mode=HTML5 Outline
|
||||
|
||||
read.win.registry=Retrieve settings from &Windows registry
|
||||
|
||||
@@ -375,7 +375,7 @@
|
||||
|
||||
<metaDataContributor implementation="com.intellij.xml.util.XmlApplicationComponent"/>
|
||||
|
||||
<browserSettingsProvider instance="com.intellij.ide.browsers.BrowserSettingsProviderImpl"/>
|
||||
<browserSettingsProvider instance="com.intellij.ide.browsers.impl.BrowserSettingsProviderImpl"/>
|
||||
|
||||
<xml.xmlSuppressionProvider implementation="com.intellij.codeInspection.DefaultXmlSuppressionProvider" order="last"/>
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.WindowsRegistryUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
|
||||
@@ -38,7 +37,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -255,50 +253,4 @@ public class BrowsersConfiguration implements PersistentStateComponent<Element>
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data from Windows registry, may take some time to run (up to ~300ms)
|
||||
*
|
||||
* @return Map[BrowserFamily -> "path to .exe"]
|
||||
*/
|
||||
@NotNull
|
||||
public static EnumMap<BrowserFamily, String> getWindowsBrowsersEXE() {
|
||||
EnumMap<BrowserFamily, String> map = new EnumMap<BrowserFamily, String>(BrowserFamily.class);
|
||||
if (SystemInfo.isWindows) {
|
||||
List<String> sections = WindowsRegistryUtil.readRegistryBranch("HKEY_LOCAL_MACHINE\\SOFTWARE\\Clients\\StartMenuInternet");
|
||||
for (String section : sections) {
|
||||
BrowserFamily family = getFamily(section);
|
||||
if (family == null) {
|
||||
continue; //We ignore "unknown" browsers like Maxthon, RockMelt, SeaMonkey, Deepnet Explorer, Avant Browser etc.
|
||||
}
|
||||
String pathToExe = WindowsRegistryUtil.readRegistryDefault(
|
||||
"HKLM\\SOFTWARE\\Clients\\StartMenuInternet\\" + section + "\\shell\\open\\command");
|
||||
if (pathToExe != null) {
|
||||
map.put(family, pathToExe);
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static BrowserFamily getFamily(String registryName) {
|
||||
registryName = registryName.toLowerCase();
|
||||
if (registryName.contains("firefox")) {
|
||||
return BrowserFamily.FIREFOX;
|
||||
}
|
||||
if (registryName.contains("iexplore")) {
|
||||
return BrowserFamily.EXPLORER;
|
||||
}
|
||||
if (registryName.contains("opera")) {
|
||||
return BrowserFamily.OPERA;
|
||||
}
|
||||
if (registryName.contains("safari")) {
|
||||
return BrowserFamily.SAFARI;
|
||||
}
|
||||
if (registryName.contains("google")) {
|
||||
return BrowserFamily.CHROME;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,13 +16,14 @@
|
||||
package com.intellij.ide.browsers;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.browsers.impl.BrowserConfigurationHelper;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.xml.XmlBundle;
|
||||
@@ -32,7 +33,6 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@@ -60,6 +60,8 @@ public class WebBrowsersPanel extends JPanel {
|
||||
createIndividualSettings(BrowsersConfiguration.BrowserFamily.SAFARI, mySettingsPanel);
|
||||
createIndividualSettings(BrowsersConfiguration.BrowserFamily.CHROME, mySettingsPanel);
|
||||
createIndividualSettings(BrowsersConfiguration.BrowserFamily.OPERA, mySettingsPanel);
|
||||
|
||||
createPlatformSpecificAction(mySettingsPanel);
|
||||
}
|
||||
|
||||
private void createIndividualSettings(@NotNull final BrowsersConfiguration.BrowserFamily family, final JPanel container) {
|
||||
@@ -125,53 +127,62 @@ public class WebBrowsersPanel extends JPanel {
|
||||
if (settings == null) {
|
||||
settings = family.createBrowserSpecificSettings();
|
||||
}
|
||||
|
||||
if (ShowSettingsUtil.getInstance().editConfigurable(mySettingsPanel, settings.createConfigurable())) {
|
||||
if (settings != null && ShowSettingsUtil.getInstance().editConfigurable(mySettingsPanel, settings.createConfigurable())) {
|
||||
myConfiguration.updateBrowserSpecificSettings(family, settings);
|
||||
}
|
||||
}
|
||||
|
||||
public void applySettingsFromWindowsRegistry() {
|
||||
if (!SystemInfo.isWindows) {
|
||||
return;
|
||||
}
|
||||
ApplicationManager.getApplication()
|
||||
.executeOnPooledThread(new SwingWorker<EnumMap<BrowsersConfiguration.BrowserFamily, String>, Void>() {
|
||||
private void createPlatformSpecificAction(JPanel container) {
|
||||
if (SystemInfo.isWindows) {
|
||||
JButton registryButton = new JButton(XmlBundle.message("read.win.registry"));
|
||||
registryButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
protected EnumMap<BrowsersConfiguration.BrowserFamily, String> doInBackground() throws Exception {
|
||||
return BrowsersConfiguration.getWindowsBrowsersEXE();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
EnumMap<BrowsersConfiguration.BrowserFamily, String> map = null;
|
||||
try {
|
||||
map = get();
|
||||
}
|
||||
catch (InterruptedException ignored) {
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
}
|
||||
if (myBrowserSettingsMap == null) {
|
||||
return;//we are disposed
|
||||
}
|
||||
if (map != null && !map.isEmpty()) {
|
||||
for (BrowsersConfiguration.BrowserFamily family : BrowsersConfiguration.BrowserFamily.values()) {
|
||||
Pair<JCheckBox, TextFieldWithBrowseButton> pair = myBrowserSettingsMap.get(family);
|
||||
String pathToExe = map.get(family);
|
||||
if (pathToExe != null) {
|
||||
pair.first.setSelected(true);
|
||||
pair.second.setText(pathToExe);
|
||||
}
|
||||
else {
|
||||
pair.first.setSelected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
applySettingsFromWindowsRegistry();
|
||||
}
|
||||
});
|
||||
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
|
||||
panel.add(registryButton, BorderLayout.EAST);
|
||||
container.add(panel);
|
||||
}
|
||||
}
|
||||
|
||||
private void applySettingsFromWindowsRegistry() {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new SwingWorker<Map<BrowsersConfiguration.BrowserFamily, String>, Void>() {
|
||||
@Override
|
||||
protected Map<BrowsersConfiguration.BrowserFamily, String> doInBackground() throws Exception {
|
||||
return BrowserConfigurationHelper.getBrowserPathsFromRegistry();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
Map<BrowsersConfiguration.BrowserFamily, String> map = null;
|
||||
try {
|
||||
map = get();
|
||||
}
|
||||
catch (InterruptedException ignore) { }
|
||||
catch (ExecutionException ignore) { }
|
||||
|
||||
if (myBrowserSettingsMap == null || map == null || map.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (BrowsersConfiguration.BrowserFamily family : BrowsersConfiguration.BrowserFamily.values()) {
|
||||
Pair<JCheckBox, TextFieldWithBrowseButton> pair = myBrowserSettingsMap.get(family);
|
||||
String pathToExe = map.get(family);
|
||||
if (pathToExe != null) {
|
||||
pair.first.setSelected(true);
|
||||
pair.second.setText(pathToExe);
|
||||
}
|
||||
else {
|
||||
pair.first.setSelected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
myBrowserSettingsMap = null;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.browsers.impl;
|
||||
|
||||
import com.intellij.ide.browsers.BrowsersConfiguration;
|
||||
import com.intellij.openapi.util.io.WindowsRegistryUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class BrowserConfigurationHelper {
|
||||
private static final String START_MENU_KEY = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Clients\\StartMenuInternet";
|
||||
|
||||
/**
|
||||
* Read data from Windows registry (may take some time to run).
|
||||
*/
|
||||
@NotNull
|
||||
public static Map<BrowsersConfiguration.BrowserFamily, String> getBrowserPathsFromRegistry() {
|
||||
Map<BrowsersConfiguration.BrowserFamily, String> map =
|
||||
new EnumMap<BrowsersConfiguration.BrowserFamily, String>(BrowsersConfiguration.BrowserFamily.class);
|
||||
|
||||
List<String> sections = WindowsRegistryUtil.readRegistryBranch(START_MENU_KEY);
|
||||
for (String section : sections) {
|
||||
BrowsersConfiguration.BrowserFamily family = getFamily(section);
|
||||
if (family != null) {
|
||||
String pathToExe = WindowsRegistryUtil.readRegistryDefault(START_MENU_KEY + "\\" + section + "\\shell\\open\\command");
|
||||
if (pathToExe != null) {
|
||||
map.put(family, pathToExe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static BrowsersConfiguration.BrowserFamily getFamily(String registryName) {
|
||||
registryName = registryName.toLowerCase();
|
||||
for (BrowsersConfiguration.BrowserFamily family : BrowsersConfiguration.BrowserFamily.values()) {
|
||||
if (registryName.contains(family.getName().toLowerCase(Locale.US))) {
|
||||
return family;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+4
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,10 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.browsers;
|
||||
package com.intellij.ide.browsers.impl;
|
||||
|
||||
import com.intellij.ide.BrowserSettingsProvider;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.ide.browsers.BrowsersConfiguration;
|
||||
import com.intellij.ide.browsers.WebBrowsersPanel;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -26,8 +27,6 @@ import javax.swing.*;
|
||||
* @author spleaner
|
||||
*/
|
||||
public class BrowserSettingsProviderImpl extends BrowserSettingsProvider {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.browsers.BrowserSettingsProviderImpl");
|
||||
|
||||
private WebBrowsersPanel mySettingsPanel;
|
||||
private final BrowsersConfiguration myConfiguration;
|
||||
|
||||
@@ -35,12 +34,6 @@ public class BrowserSettingsProviderImpl extends BrowserSettingsProvider {
|
||||
myConfiguration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applySettingsFromWindowsRegistry() {
|
||||
if (mySettingsPanel != null)
|
||||
mySettingsPanel.applySettingsFromWindowsRegistry();
|
||||
}
|
||||
|
||||
public JComponent createComponent() {
|
||||
if (mySettingsPanel == null) {
|
||||
mySettingsPanel = new WebBrowsersPanel(myConfiguration);
|
||||
@@ -50,17 +43,14 @@ public class BrowserSettingsProviderImpl extends BrowserSettingsProvider {
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
LOG.assertTrue(mySettingsPanel != null);
|
||||
return mySettingsPanel.isModified();
|
||||
}
|
||||
|
||||
public void apply() throws ConfigurationException {
|
||||
LOG.assertTrue(mySettingsPanel != null);
|
||||
mySettingsPanel.apply();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
LOG.assertTrue(mySettingsPanel != null);
|
||||
mySettingsPanel.reset();
|
||||
}
|
||||
|
||||
@@ -68,5 +58,4 @@ public class BrowserSettingsProviderImpl extends BrowserSettingsProvider {
|
||||
mySettingsPanel.dispose();
|
||||
mySettingsPanel = null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user