Пример #1
0
  protected void updateForEditor(DataContext dataContext, Presentation presentation) {
    Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
    if (editor == null) {
      presentation.setVisible(false);
      return;
    }

    Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
      return;
    }
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());

    PsiElement element = getTargetElement(editor, project);
    boolean result = element != null && CopyHandler.canCopy(new PsiElement[] {element});

    if (!result && file != null) {
      result = CopyHandler.canCopy(new PsiElement[] {file});
    }

    presentation.setEnabled(result);
    presentation.setVisible(true);
  }
Пример #2
0
  public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
      return;
    }

    CommandProcessor.getInstance()
        .executeCommand(
            project,
            new Runnable() {
              public void run() {
                PsiDocumentManager.getInstance(project).commitAllDocuments();
              }
            },
            "",
            null);
    final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
    PsiElement[] elements;

    PsiDirectory defaultTargetDirectory;
    if (editor != null) {
      PsiElement aElement = getTargetElement(editor, project);
      PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
      if (file == null) return;
      elements = new PsiElement[] {aElement};
      if (aElement == null || !CopyHandler.canCopy(elements)) {
        elements = new PsiElement[] {file};
      }
      defaultTargetDirectory = file.getContainingDirectory();
    } else {
      PsiElement element = LangDataKeys.TARGET_PSI_ELEMENT.getData(dataContext);
      defaultTargetDirectory = element instanceof PsiDirectory ? (PsiDirectory) element : null;
      elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
    }
    doCopy(elements, defaultTargetDirectory);
  }
Пример #3
0
 protected void doCopy(PsiElement[] elements, PsiDirectory defaultTargetDirectory) {
   CopyHandler.doCopy(elements, defaultTargetDirectory);
 }
Пример #4
0
 protected void updateForToolWindow(
     String toolWindowId, DataContext dataContext, Presentation presentation) {
   PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
   presentation.setEnabled(elements != null && CopyHandler.canCopy(elements));
 }