package com.karateca.jstoolbox.tobrowser;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.karateca.jstoolbox.MyAction;
import com.karateca.jstoolbox.config.JsToolboxSettings;

/**
 * @author andresdom@google.com (Andres Dominguez)
 */
public class ToBrowserAction extends MyAction {
  @Override
  public void actionPerformed(AnActionEvent actionEvent) {
    if (!canEnableAction(actionEvent)) {
      return;
    }

    JsToolboxSettings settings = new JsToolboxSettings();

    String fileName = getCurrentFileName(actionEvent);

    String searchUrl = settings.getSearchUrl();
    String url = searchUrl.replace(JsToolboxSettings.FILE_NAME_TOKEN, fileName);
    openBrowser(url);
  }

  private void openBrowser(String url) {
    try {
      BrowserUtil.browse(url);
    } catch (Exception e) {
      System.err.println("Error: " + e.getMessage());
    }
  }
}

@@ -129,16 +129,104 @@
 nEvent;%0A
+import com.intellij.openapi.actionSystem.LangDataKeys;%0Aimport com.intellij.psi.PsiFile;%0A
 import c
@@ -621,58 +621,437 @@
     
-String fileName = getCurrentFileName(actionEvent);
+PsiFile file = actionEvent.getData(LangDataKeys.PSI_FILE);%0A    String fileName = getCurrentFileName(actionEvent);%0A%0A    if (settings.getUseFilePath()) %7B%0A      // Get the directory.%0A      String directory = file.getContainingDirectory().toString();%0A      String fromPath = settings.getFromPath();%0A      fileName = directory.replaceFirst(%22%5E.*%22 + fromPath, fromPath) +%0A          System.getProperty(%22file.separator%22) + fileName;%0A    %7D
 %0A%0A  
@@ -1092,24 +1092,25 @@
 earchUrl();%0A
+%0A
     String u

add directory to the go to file