public Object getData(@NonNls final String dataId) {
      if (PlatformDataKeys.PROJECT.is(dataId)) {
        return myProject;
      }
      if (PlatformDataKeys.VIRTUAL_FILE.is(dataId)) {
        final VirtualFile selectedFile = myWindow.getSelectedFile();
        return selectedFile != null && selectedFile.isValid() ? selectedFile : null;
      }
      if (EditorWindow.DATA_KEY.is(dataId)) {
        return myWindow;
      }
      if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return HELP_ID;
      }

      if (CloseAction.CloseTarget.KEY.is(dataId)) {
        TabInfo selected = myTabs.getSelectedInfo();
        if (selected != null) {
          return EditorTabbedContainer.this;
        }
      }

      if (EditorWindow.DATA_KEY.is(dataId)) {
        return myWindow;
      }

      return null;
    }
  @Nullable
  private static PsiElement getElementToCopy(
      @Nullable final Editor editor, final DataContext dataContext) {
    PsiElement element = null;
    if (editor != null) {
      PsiReference reference = TargetElementUtilBase.findReference(editor);
      if (reference != null) {
        element = reference.getElement();
      }
    }

    if (element == null) {
      element = LangDataKeys.PSI_ELEMENT.getData(dataContext);
    }
    if (element == null && editor == null) {
      VirtualFile virtualFile = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext);
      Project project = PlatformDataKeys.PROJECT.getData(dataContext);
      if (virtualFile != null && project != null) {
        element = PsiManager.getInstance(project).findFile(virtualFile);
      }
    }
    if (element instanceof PsiFile && !((PsiFile) element).getViewProvider().isPhysical()) {
      return null;
    }

    for (QualifiedNameProvider provider : Extensions.getExtensions(QualifiedNameProvider.EP_NAME)) {
      PsiElement adjustedElement = provider.adjustElementToCopy(element);
      if (adjustedElement != null) return adjustedElement;
    }
    return element;
  }
Example #3
0
  public Object getData(String dataId) {
    if (PlatformDataKeys.VIRTUAL_FILE_ARRAY.getName().equals(dataId)) {
      List<VirtualFile> files = new LinkedList<VirtualFile>();
      TreePath[] treePaths = getSelectionPaths();
      if (treePaths != null) {
        for (TreePath tp : treePaths) {
          Object lastPathComponent = tp.getLastPathComponent();
          if (lastPathComponent instanceof AbstractFileTreeNode) {
            AbstractFileTreeNode node = (AbstractFileTreeNode) lastPathComponent;
            VirtualFile file = node.getFile();
            if (file.isValid()) {
              files.add(file);
            }
          }
        }
      }
      return files.toArray(new VirtualFile[files.size()]);
    } else if (PlatformDataKeys.VIRTUAL_FILE.getName().equals(dataId)) {
      TreePath tp = getSelectedPath();
      if (tp == null) {
        return super.getData(dataId);
      }
      Object lastPathComponent = tp.getLastPathComponent();
      if (lastPathComponent instanceof AbstractFileTreeNode) {
        AbstractFileTreeNode node = (AbstractFileTreeNode) lastPathComponent;
        VirtualFile file = node.getFile();
        if (file.isValid()) {
          return file;
        }
      }
    } else if (PlatformDataKeys.COPY_PROVIDER.getName().equals(dataId)) {
      return new FilePaneCopyProvider();
    } else if (PlatformDataKeys.PASTE_PROVIDER.getName().equals(dataId)) {
      return new FilePanePasteProvider();
    } else if (PlatformDataKeys.CUT_PROVIDER.getName().equals(dataId)) {
      return new FilePaneCopyProvider();
    } else if (dataId.equals(MPSDataKeys.PLACE.getName())) {
      TreeNode treeNode = getSelectedTreeNode(TreeNode.class);
      if (treeNode instanceof ModuleTreeNode) {
        return ActionPlace.PROJECT_PANE_MODULE;
      } else if (treeNode instanceof FileTreeNode) {
        return ActionPlace.PROJECT_PANE_FILE;
      } else if (treeNode instanceof FolderTreeNode) {
        return ActionPlace.PROJECT_PANE_FOLDER;
      }
    }

    return super.getData(dataId);
  }
  @Override
  protected void gotoActionPerformed(final AnActionEvent e) {
    final Project project = e.getData(PlatformDataKeys.PROJECT);
    if (project == null) return;

    PsiDocumentManager.getInstance(project).commitAllDocuments();

    final PsiElement psiElement = LangDataKeys.PSI_ELEMENT.getData(e.getDataContext());
    final PsiFile psiFile = LangDataKeys.PSI_FILE.getData(e.getDataContext());
    final VirtualFile virtualFile = PlatformDataKeys.VIRTUAL_FILE.getData(e.getDataContext());

    FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.inspection");

    final GotoInspectionModel model = new GotoInspectionModel(project);
    showNavigationPopup(
        e,
        model,
        new GotoActionCallback<Object>() {
          @Override
          protected ChooseByNameFilter<Object> createFilter(@NotNull ChooseByNamePopup popup) {
            popup.setSearchInAnyPlace(true);
            return super.createFilter(popup);
          }

          @Override
          public void elementChosen(ChooseByNamePopup popup, final Object element) {
            ApplicationManager.getApplication()
                .invokeLater(
                    new Runnable() {
                      @Override
                      public void run() {
                        runInspection(
                            project,
                            (InspectionToolWrapper) element,
                            virtualFile,
                            psiElement,
                            psiFile);
                      }
                    });
          }
        });
  }
  @Override
  public Object getData(final String dataId) {
    final Editor e = validateCurrentEditor();
    if (e == null) return null;

    if (!myProject.isDisposed()) {
      final Object o =
          ((FileEditorManagerImpl) FileEditorManager.getInstance(myProject))
              .getData(dataId, e, myFile);
      if (o != null) return o;
    }

    if (PlatformDataKeys.EDITOR.is(dataId)) {
      return e;
    }
    if (PlatformDataKeys.VIRTUAL_FILE.is(dataId)) {
      return myFile.isValid() ? myFile : null; // fix for SCR 40329
    }
    return null;
  }
 private VirtualFile getVirtualFiles(AnActionEvent e) {
   return PlatformDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
 }
Example #7
0
 public static Module getCurrentModule() {
   final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
   VirtualFile file =
       PlatformDataKeys.VIRTUAL_FILE.getData(DataManager.getInstance().getDataContext(owner));
   return ModuleUtil.findModuleForFile(file, getCurrentProject());
 }
 private VirtualFile getDir(DataContext dataContext) {
   VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext);
   if (file == null || !file.isDirectory()) return null;
   return file;
 }