platform: allow providing custom web help for plugins (IDEA-177906)

This commit is contained in:
nik
2017-09-06 15:45:59 +02:00
parent d5b46bd86a
commit 465fac71be
3 changed files with 70 additions and 0 deletions
@@ -0,0 +1,54 @@
/*
* Copyright 2000-2017 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.openapi.help;
import com.intellij.openapi.extensions.PluginAware;
import com.intellij.openapi.extensions.PluginDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Override this class and register the implementation in {@code plugin.xml} to provide custom context web help for your plugin:
* <pre>
* &lt;extensions defaultExtensionNs="com.intellij"&gt;
* &nbsp;&nbsp;&lt;webHelpProvider implementation="qualified-class-name"/&gt;
* &lt;/extensions&gt;
* </pre>
* After that {@link #getHelpPageUrl(String)} method will be used to show help for topics which IDs start with '&lt;plugin ID&gt;.'.
*
* @author nik
*/
public abstract class WebHelpProvider implements PluginAware {
private String myHelpTopicPrefix;
/**
* Return URL of page which should be opened in browser when context help for {@code helpTopicId} is invoked. The method will be called
* only if {@code helpTopicId} starts with '&lt;plugin ID&gt;.' prefix.
* @param helpTopicId full ID of help topic including '&lt;plugin ID&gt;.' prefix
*/
@Nullable
public abstract String getHelpPageUrl(@NotNull String helpTopicId);
@Override
public final void setPluginDescriptor(PluginDescriptor pluginDescriptor) {
myHelpTopicPrefix = pluginDescriptor.getPluginId().getIdString() + ".";
}
@NotNull
public String getHelpTopicPrefix() {
return myHelpTopicPrefix;
}
}
@@ -25,7 +25,9 @@ import com.intellij.internal.statistic.UsageTrigger;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.help.WebHelpProvider;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.reference.SoftReference;
@@ -41,6 +43,8 @@ import java.net.URL;
public class HelpManagerImpl extends HelpManager {
private static final Logger LOG = Logger.getInstance("#com.intellij.help.impl.HelpManagerImpl");
private static final ExtensionPointName<WebHelpProvider>
WEB_HELP_PROVIDER_EP_NAME = ExtensionPointName.create("com.intellij.webHelpProvider");
@NonNls private static final String HELP_HS = "Help.hs";
@@ -51,6 +55,16 @@ public class HelpManagerImpl extends HelpManager {
UsageTrigger.trigger("ide.help." + id);
for (WebHelpProvider provider : WEB_HELP_PROVIDER_EP_NAME.getExtensions()) {
if (id.startsWith(provider.getHelpTopicPrefix())) {
String url = provider.getHelpPageUrl(id);
if (url != null) {
BrowserUtil.browse(url);
return;
}
}
}
if (MacHelpUtil.isApplicable() && MacHelpUtil.invokeHelp(id)) {
return;
}
@@ -287,6 +287,8 @@
<extensionPoint name="projectNameProvider" interface="com.intellij.openapi.project.ex.ProjectNameProvider"/>
<extensionPoint name="streamProviderFactory" interface="com.intellij.configurationStore.StreamProviderFactory" area="IDEA_PROJECT"/>
<extensionPoint name="webHelpProvider" interface="com.intellij.openapi.help.WebHelpProvider"/>
<extensionPoint name="reporting.sendPermission" interface="com.intellij.reporting.DataSendPermission"/>
<extensionPoint name="tasks.contextProvider" interface="com.intellij.tasks.context.WorkingContextProvider" area="IDEA_PROJECT"/>