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);
}
}
Aggregations