@Override
  public void update(@NotNull AnActionEvent e) {
    Presentation presentation = e.getPresentation();

    OpenInBrowserRequest result = BaseOpenInBrowserAction.doUpdate(e);
    if (result == null) {
      return;
    }

    String description = getTemplatePresentation().getDescription();
    if (HtmlUtil.isHtmlFile(result.getFile())) {
      description += " (hold Shift to open URL of local file)";
    }

    presentation.setText(getTemplatePresentation().getText());
    presentation.setDescription(description);

    WebBrowser browser = findUsingBrowser();
    if (browser != null) {
      presentation.setIcon(browser.getIcon());
    }

    if (ActionPlaces.isPopupPlace(e.getPlace())) {
      presentation.setVisible(presentation.isEnabled());
    }
  }
コード例 #2
0
  @Override
  public boolean canSelect(SelectInContext context) {
    Object selectorInFile = context.getSelectorInFile();
    if (!(selectorInFile instanceof PsiElement)) {
      return false;
    }

    PsiFile file = ((PsiElement) selectorInFile).getContainingFile();
    if (file == null || file.getVirtualFile() == null) {
      return false;
    }

    Pair<WebBrowserUrlProvider, Url> browserUrlProvider = WebBrowserServiceImpl.getProvider(file);
    currentName = XmlBundle.message("browser.select.in.default.name");
    if (browserUrlProvider == null) {
      return HtmlUtil.isHtmlFile(file) && !(file.getVirtualFile() instanceof LightVirtualFile);
    } else {
      String customText = browserUrlProvider.first.getOpenInBrowserActionText(file);
      if (customText != null) {
        currentName = customText;
      }
    }
    return true;
  }