Right click -> Open in Browser

Hi all,

I have a request for the AsciiDoc plugin to add the 'open in browser' feature, but right now I'm not sure how to do that, and I'm not even sure if it's possible. Any hints?

Thanks,

Erik

0

You can use the WebBrowserUrlProvider extension point to implement this.

0

Update: Okay, I thought it was implemented, but it isn't. It works when I run the plugin (run plugin configuration, which starts my IntelliJ community edition), but when I release the plugin and install it, it doesn't work. The icon is displayed, but when I click on it, nothing happens. I'm sure I implemented it work, though I'm surprised it works in development mode.

 
public class AsciiDocBrowserUrlProvider extends WebBrowserUrlProvider {
  @Override
  public boolean
canHandleElement(OpenInBrowserRequest request) {
    if(request.getFile().getFileType() instanceof AsciiDocFileType) {
      return true;
    }

    return super.canHandleElement(request);
  }

  @Nullable
  @Override
  protected
Url getUrl(OpenInBrowserRequest request, VirtualFile virtualFile) throws BrowserException {
    String path = virtualFile.getPath();
    System.out.println(path);
    return new UrlImpl(path);
  }
}


This is my current implementation. It work in development mode, but not when I release the plugin. Also, it gives the following exception when I open the file:

[   4266]   WARN - j.ui.mac.MacMainFrameDecorator - no url bundle present. To use platform protocol handler to open external links specify required protocols in the mac app layout section of the build file Example: args.urlSchemes = ["your-protocol"] will handle following links: your-protocol://open?file=file&line=line /Users/erikp/IdeaProjects/test/test.adoc [  15212]   WARN - rowsers.BrowserLauncherAppless - Error while using Desktop API, fallback to CLI java.io.IOException: Failed to mail or browse file:///Users/erikp/IdeaProjects/test/test.adoc. Error code: -10814      at apple.awt.CDesktopPeer.lsOpen(CDesktopPeer.java:52)      at apple.awt.CDesktopPeer.browse(CDesktopPeer.java:45)      at java.awt.Desktop.browse(Desktop.java:368)      at com.intellij.ide.browsers.BrowserLauncherAppless.browse(BrowserLauncherAppless.java:133)      at com.intellij.ide.browsers.BrowserLauncherAppless.browse(BrowserLauncherAppless.java:122)      at com.intellij.ide.browsers.BrowserLauncherAppless.browse(BrowserLauncherAppless.java:117)      at com.intellij.ide.browsers.BrowserLauncherAppless.openOrBrowse(BrowserLauncherAppless.java:192)      at com.intellij.ide.browsers.BrowserLauncherAppless.browse(BrowserLauncherAppless.java:396)      at com.intellij.ide.browsers.actions.BaseOpenInBrowserAction$2.consume(BaseOpenInBrowserAction.java:181)      at com.intellij.ide.browsers.actions.BaseOpenInBrowserAction$2.consume(BaseOpenInBrowserAction.java:177)      at com.intellij.openapi.util.AsyncResult$2.run(AsyncResult.java:98)      at com.intellij.openapi.util.ExecutionCallback.doWhenExecuted(ExecutionCallback.java:101)      at com.intellij.openapi.util.ActionCallback.doWhenDone(ActionCallback.java:108)      at com.intellij.openapi.util.AsyncResult.doWhenDone(AsyncResult.java:95)      at com.intellij.ide.browsers.actions.BaseOpenInBrowserAction.open(BaseOpenInBrowserAction.java:177)      at com.intellij.ide.browsers.actions.BaseOpenInBrowserAction.open(BaseOpenInBrowserAction.java:166)      at com.intellij.ide.browsers.actions.OpenFileInDefaultBrowserAction.actionPerformed(OpenFileInDefaultBrowserAction.java:90)      at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:164)      at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter$1.run(ActionMenuItem.java:266)      at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:926)      at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:124)      at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:236)      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)      at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:105)      at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:512)      at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:44)      at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:532)      at java.awt.Component.processMouseEvent(Component.java:6414)      at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)      at java.awt.Component.processEvent(Component.java:6179)      at java.awt.Container.processEvent(Container.java:2084)      at java.awt.Component.dispatchEventImpl(Component.java:4776)      at java.awt.Container.dispatchEventImpl(Container.java:2142)      at java.awt.Component.dispatchEvent(Component.java:4604)      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4279)      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4209)      at java.awt.Container.dispatchEventImpl(Container.java:2128)      at java.awt.Window.dispatchEventImpl(Window.java:2492)      at java.awt.Component.dispatchEvent(Component.java:4604)      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:717)      at java.awt.EventQueue.access$400(EventQueue.java:82)      at java.awt.EventQueue$2.run(EventQueue.java:676)      at java.awt.EventQueue$2.run(EventQueue.java:674)      at java.security.AccessController.doPrivileged(Native Method)      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)      at java.awt.EventQueue$3.run(EventQueue.java:690)      at java.awt.EventQueue$3.run(EventQueue.java:688)      at java.security.AccessController.doPrivileged(Native Method)      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)      at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)      at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:748)      at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:573)      at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:384)      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Anyone suggestions?

0

You're opening the .adoc file in the browser directly. I would be surprised if this worked, because normally browsers don't support displaying asciiidoc files. Instead, you need to save the HTML generated from .adoc to a temporary file and open that file in the browser.

0

Hi Dmitry,

Thanks for the reply. I know I'm trying that, and that's exactly what I want: to display the raw contents of the .adoc file in the browser without the HTML transformation, because then the AsciiDoc plugin in Chrome will take over. However, it's not opened, and it doesn't explain the stacktrace.

0

So, basically, I just want IntelliJ to open this file: file:///Users/erikp/IdeaProjects/test/test.adoc, without using the interal web server. Tried that, but that failed (Chrome will download the file then, which is not what I want). Like I said above, it works in development mode, but not in the actual plugin.

edit:

Tried this too:

 
protected Url getUrl(OpenInBrowserRequest request, VirtualFile virtualFile) throws BrowserException {
  String path = virtualFile.getPath();
  System.out.println(path);

  return Urls.parse(path, true);
}


but that also fails. Same error as above.

0

This requires your users to have the AsciiDoc plugin for Chrome installed, which not everyone has. (And some people use Safari, for which, as far as I know, it's not possible to open AsciiDoc files directly.)

0

All correct, and that's exactly the requirement from one of the AsciiDoc plugin users. Still this doesn't bring me closer to a solution :-)

0

I don't think you'd see this exception when opening a regular .html file rather than .adoc.


0

I'm not sure what you mean. I'm not even sure the exception is the problem. Can we focus on a solution? I'm confused why it works when I run IntelliJ CE as a plugin (even then I have the stacktrace), but when test the plugin, it doesn't.

0

I'm offering you a solution - always export the .adoc file to .html and open the .html. We know that opening .html files via this API works correctly. We also know that this will work for all users of the plugin, and not only those who have a browser extension for .adoc support installed. Is there any other reason why this solution isn't satisfactory for you?

0

Hi Dmitry, thanks for the feedback, but that's just not what I am looking for. I'm looking for a way to satisfy this requirement: https://github.com/asciidoctor/asciidoctor-intellij-plugin/issues/82, and rendering to HTML will just not give the same result due to a different way of rendering in the plugin. That's why it's not satisfactory for me. Well, actually, it's not my requirement, but I'd like to help out, and I just would like to understand why rendering the .adoc works when running the plugin, but not when the plugin is installed.

0

请先登录再写评论。