Search in sources :

Example 6 with PluginDescriptor

use of com.intellij.openapi.extensions.PluginDescriptor in project intellij-community by JetBrains.

the class TipUIUtil method openTipInBrowser.

public static void openTipInBrowser(@Nullable TipAndTrickBean tip, JEditorPane browser) {
    if (tip == null)
        return;
    try {
        PluginDescriptor pluginDescriptor = tip.getPluginDescriptor();
        ClassLoader tipLoader = pluginDescriptor == null ? TipUIUtil.class.getClassLoader() : ObjectUtils.notNull(pluginDescriptor.getPluginClassLoader(), TipUIUtil.class.getClassLoader());
        URL url = ResourceUtil.getResource(tipLoader, "/tips/", tip.fileName);
        if (url == null) {
            setCantReadText(browser, tip);
            return;
        }
        StringBuffer text = new StringBuffer(ResourceUtil.loadText(url));
        updateShortcuts(text);
        updateImages(text, tipLoader, browser);
        String replaced = text.toString().replace("&productName;", ApplicationNamesInfo.getInstance().getFullProductName());
        String major = ApplicationInfo.getInstance().getMajorVersion();
        replaced = replaced.replace("&majorVersion;", major);
        String minor = ApplicationInfo.getInstance().getMinorVersion();
        replaced = replaced.replace("&minorVersion;", minor);
        replaced = replaced.replace("&majorMinorVersion;", major + ("0".equals(minor) ? "" : ("." + minor)));
        replaced = replaced.replace("&settingsPath;", CommonBundle.settingsActionPath());
        // don't reload the styles
        replaced = replaced.replaceFirst("<link rel=\"stylesheet\".*tips\\.css\">", "");
        if (browser.getUI() == null) {
            browser.updateUI();
            boolean succeed = browser.getUI() != null;
            String message = "reinit JEditorPane.ui: " + (succeed ? "OK" : "FAIL") + ", laf=" + LafManager.getInstance().getCurrentLookAndFeel();
            if (succeed)
                LOG.warn(message);
            else
                LOG.error(message);
        }
        adjustFontSize(((HTMLEditorKit) browser.getEditorKit()).getStyleSheet());
        browser.read(new StringReader(replaced), url);
    } catch (IOException e) {
        setCantReadText(browser, tip);
    }
}
Also used : IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginDescriptor(com.intellij.openapi.extensions.PluginDescriptor) StringReader(java.io.StringReader) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

PluginDescriptor (com.intellij.openapi.extensions.PluginDescriptor)6 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)4 IOException (java.io.IOException)3 URL (java.net.URL)3 Nullable (org.jetbrains.annotations.Nullable)3 LanguageExtensionPoint (com.intellij.lang.LanguageExtensionPoint)2 ExtensionPoint (com.intellij.openapi.extensions.ExtensionPoint)2 SeparatorWithText (com.intellij.ui.SeparatorWithText)2 EmptyIcon (com.intellij.util.ui.EmptyIcon)2 com.intellij.codeInsight.daemon (com.intellij.codeInsight.daemon)1 IdeaPluginDescriptorImpl (com.intellij.ide.plugins.IdeaPluginDescriptorImpl)1 PluginClassLoader (com.intellij.ide.plugins.cl.PluginClassLoader)1 EditorSettingsExternalizable (com.intellij.openapi.editor.ex.EditorSettingsExternalizable)1 Extensions (com.intellij.openapi.extensions.Extensions)1 PluginId (com.intellij.openapi.extensions.PluginId)1 Configurable (com.intellij.openapi.options.Configurable)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Project (com.intellij.openapi.project.Project)1 ProjectManager (com.intellij.openapi.project.ProjectManager)1 Comparing (com.intellij.openapi.util.Comparing)1