Java 类com.intellij.openapi.actionSystem.LangDataKeys 实例源码

项目:DaggerHelper    文件:NewModuleDirAction.java   
@NotNull
@Override
protected void invokeDialog(AnActionEvent e,Project project, PsiDirectory dir) {
    BaseDialog dialog = new BaseDialog("请输入基类前缀:",project);
    dialog.show();
    if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        String prefix = dialog.getClassNamePrefix();
        if(prefix != null && !prefix.isEmpty()){
            Application application = ApplicationManager.getApplication();
            application.runWriteAction(() -> {
                PsiElement createdElement = createProjectDir(dir,prefix);
                final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
                if(view != null&&createdElement != null){
                    view.selectElement(createdElement);
                }
            });
        }
    }
}
项目:idea-php-typo3-plugin    文件:ExtensionUtility.java   
public static PsiDirectory getExtensionDirectory(@NotNull AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);
    if (project == null) {
        return null;
    }

    DataContext dataContext = event.getDataContext();
    IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
        return null;
    }

    PsiDirectory[] directories = view.getDirectories();
    if (directories.length == 0) {
        return null;
    }

    return FilesystemUtil.findParentExtensionDirectory(directories[0]);
}
项目:bamboo-soy    文件:ClosingTagHandler.java   
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) {
  myOriginalHandler.execute(editor, charTyped, dataContext);
  if (isMatchForClosingTag(editor, charTyped)) {
    int offset = editor.getCaretModel().getOffset();
    PsiFile file = dataContext.getData(LangDataKeys.PSI_FILE);
    if (file == null) {
      return;
    }
    PsiElement el = file.findElementAt(offset - 1);
    TagBlockElement block = (TagBlockElement) PsiTreeUtil
        .findFirstParent(el,
            parent -> parent instanceof TagBlockElement && !(parent instanceof SoyChoiceClause));
    if (block == null) {
      return;
    }
    String closingTag = block.getOpeningTag().generateClosingTag();
    insertClosingTag(editor, offset, closingTag);
    if (editor.getProject() != null) {
      PsiDocumentManager.getInstance(editor.getProject()).commitDocument(editor.getDocument());
      CodeStyleManager.getInstance(editor.getProject()).reformat(block);
    }
  }
}
项目:json2java4idea    文件:NewClassAction.java   
@CheckReturnValue
@VisibleForTesting
@SuppressWarnings("WeakerAccess")
static boolean isAvailable(@Nonnull AnActionEvent event) {
    final Project project = event.getProject();
    if (project == null) {
        return false;
    }

    final IdeView view = event.getData(LangDataKeys.IDE_VIEW);
    if (view == null) {
        return false;
    }

    final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
    final ProjectFileIndex fileIndex = rootManager.getFileIndex();
    final Optional<PsiDirectory> sourceDirectory = Stream.of(view.getDirectories())
            .filter(directory -> {
                final VirtualFile virtualFile = directory.getVirtualFile();
                return fileIndex.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES);
            })
            .findFirst();
    return sourceDirectory.isPresent();
}
项目:AndroidSourceViewer    文件:BaseSourceAction.java   
@Override
public final void actionPerformed(AnActionEvent event) {
    this.project = event.getProject();
    this.actionEvent = event;
    packageName = Utils.getClassPath(event);
    element = event.getData(LangDataKeys.PSI_ELEMENT);
    if (Utils.isEmpty(packageName)) {
        NotificationUtils.infoNotification("Must be Class or Method");
        return;
    }
    this.selectActionPerformed(event, element, packageName);
    if (shouldSelectVersion()) {
        data = Utils.getVersionList(packageName);
        if (data == null) {
            NotificationUtils.infoNotification("Invalid PackageName:" + packageName);
            return;
        }
        this.onClassSelected(this.actionEvent, packageName);
    }
}
项目:educational-plugin    文件:CCGetCourseFromStepic.java   
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (view == null || project == null) {
    return;
  }
  final String courseId = Messages.showInputDialog("Please, enter course id", "Get Course From Stepik", null);
  if (StringUtil.isNotEmpty(courseId)) {
    ProgressManager.getInstance().run(new Task.Modal(project, "Creating Course", true) {
      @Override
      public void run(@NotNull final ProgressIndicator indicator) {
        createCourse(project, courseId);
      }
    });
  }
}
项目:educational-plugin    文件:CCCreateStudyItemActionBase.java   
@Override
public void actionPerformed(AnActionEvent e) {
  final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
  final Project project = e.getProject();
  if (view == null || project == null) {
    return;
  }
  final PsiDirectory[] directories = view.getDirectories();
  if (directories.length == 0 || directories.length > 1) {
    return;
  }

  final PsiDirectory directory = directories[0];
  if (directory == null) return;
  final Course course = StudyTaskManager.getInstance(project).getCourse();
  if (course == null) {
    return;
  }
  createItem(view, project, directory, course);
}
项目:educational-plugin    文件:CCChangeCourseInfo.java   
@Override
public void update(@NotNull AnActionEvent event) {
  final Project project = event.getProject();
  final Presentation presentation = event.getPresentation();
  if (project == null) {
    return;
  }
  presentation.setEnabledAndVisible(false);
  if (!CCUtils.isCourseCreator(project)) {
    return;
  }
  final IdeView view = event.getData(LangDataKeys.IDE_VIEW);
  if (view == null) {
    return;
  }
  final PsiDirectory[] directories = view.getDirectories();
  if (directories.length == 0) {
    return;
  }
  presentation.setEnabledAndVisible(true);
}
项目:educational-plugin    文件:CCLessonMoveHandlerDelegate.java   
@Override
public boolean canMove(DataContext dataContext) {
  if (CommonDataKeys.PSI_FILE.getData(dataContext) != null) {
    return false;
  }
  IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
  if (view == null) {
    return false;
  }

  final PsiDirectory[] directories = view.getDirectories();
  if (directories.length == 0 || directories.length > 1) {
    return false;
  }

  final PsiDirectory sourceDirectory = directories[0];
  return CCUtils.isLessonDir(sourceDirectory);
}
项目:educational-plugin    文件:CCTaskMoveHandlerDelegate.java   
@Override
public boolean canMove(DataContext dataContext) {
  if (CommonDataKeys.PSI_FILE.getData(dataContext) != null) {
    return false;
  }
  IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
  if (view == null) {
    return false;
  }
  final PsiDirectory[] directories = view.getDirectories();
  if (directories.length == 0 || directories.length > 1) {
    return false;
  }

  final PsiDirectory sourceDirectory = directories[0];
  return isTaskDir(sourceDirectory);
}
项目:RIBs    文件:GenerateAction.java   
/**
 * Checked whether or not this action can be enabled.
 *
 * <p>Requirements to be enabled: * User must be in a Java source folder.
 *
 * @param dataContext to figure out where the user is.
 * @return {@code true} when the action is available, {@code false} when the action is not
 *     available.
 */
private boolean isAvailable(DataContext dataContext) {
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return false;
  }

  final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
  if (view == null || view.getDirectories().length == 0) {
    return false;
  }

  ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  for (PsiDirectory dir : view.getDirectories()) {
    if (projectFileIndex.isUnderSourceRootOfType(
            dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES)
        && checkPackageExists(dir)) {
      return true;
    }
  }

  return false;
}
项目:lua-for-idea    文件:GenerateLuaListingAction.java   
@Override
public void update(AnActionEvent e) {
    e.getPresentation().setVisible(false);
    e.getPresentation().setEnabled(false);
    Project project = e.getData(LangDataKeys.PROJECT);
    if (project != null) {
        for (Module module : ModuleManager.getInstance(project).getModules()) {
            e.getPresentation().setVisible(true);
            Sdk luaSdk = LuaSdkType.findLuaSdk(module);
            if (luaSdk == null) continue;

            final String homePath = luaSdk.getHomePath();
            if (homePath == null) continue;

            if (LuaSdkType.getByteCodeCompilerExecutable(homePath).exists()) {
                e.getPresentation().setEnabled(true);
                break;
            }
        }
    }
}
项目:catberry-idea-plugin    文件:CreateCatberryComponentAction.java   
private static boolean isEnabled(AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);

  final IdeView ideView = e.getData(LangDataKeys.IDE_VIEW);
  if (project == null || ideView == null)
    return false;

  CatberryProjectConfigurationManager configurationManager = CatberryProjectConfigurationManager.getInstance(project);
  if (!configurationManager.isCatberryEnabled())
    return false;

  final PsiDirectory[] directories = ideView.getDirectories();
  if(directories.length != 1)
    return false;
  final String selectedPath = directories[0].getVirtualFile().getPath();

  for(PsiDirectory dir : configurationManager.getComponentsDirectories()) {
    if(selectedPath.startsWith(dir.getVirtualFile().getPath()))
      return true;
  }
  return false;
}
项目:intellij-ce-playground    文件:CleanPycAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
  final PsiElement[] elements = e.getData(LangDataKeys.PSI_ELEMENT_ARRAY);
  if (elements == null) return;
  final List<File> pycFiles = new ArrayList<File>();
  ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
    @Override
    public void run() {
      for (PsiElement element : elements) {
        PsiDirectory dir = (PsiDirectory) element;
        collectPycFiles(new File(dir.getVirtualFile().getPath()), pycFiles);
      }
      FileUtil.asyncDelete(pycFiles);
    }
  }, "Cleaning up .pyc files...", false, e.getProject());
  final StatusBar statusBar = WindowManager.getInstance().getIdeFrame(e.getProject()).getStatusBar();
  statusBar.setInfo("Deleted " + pycFiles.size() + " bytecode file" + (pycFiles.size() != 1 ? "s" : ""));
}
项目:DaggerHelper    文件:NewProjectDirAction.java   
@NotNull
@Override
protected void invokeDialog(AnActionEvent e,Project project, PsiDirectory dir) {
    BaseDialog dialog = new BaseDialog("请输入基类前缀:",project);
    dialog.show();
    if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        String prefix = dialog.getClassNamePrefix();
        if(prefix != null && !prefix.isEmpty()){
            Application application = ApplicationManager.getApplication();
            application.runWriteAction(() -> {
                PsiElement[] elements = createProjectDir(dir,prefix);
                final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
                if(view != null){
                    for (PsiElement element : elements) {
                        view.selectElement(element);
                    }
                }
            });
        }
    }
}
项目:DaggerHelper    文件:BaseAction.java   
@Override
public void update(AnActionEvent e) {
    super.update(e);
    final Presentation presentation = e.getPresentation();
    if(presentation.isEnabled()) {
        final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
        final Project project = e.getProject();
        if (view != null && project != null) {
            ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
            PsiDirectory[] dirs = view.getDirectories();
            for (PsiDirectory dir : dirs) {
                if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
                        JavaDirectoryService.getInstance().getPackage(dir) != null && isValidForClass(project,dir)) {
                    return;
                }
            }
        }
        presentation.setEnabled(false);
        presentation.setVisible(false);
    }
}
项目:idea-php-spryker-plugin    文件:AbstractClassTypeAction.java   
@Override
protected boolean isAvailable(DataContext dataContext) {
    IdeView view = (IdeView) LangDataKeys.IDE_VIEW.getData(dataContext);

    if (view == null) {
        return false;
    }

    PsiDirectory dir = view.getOrChooseDirectory();

    if (dir == null) {
        return false;
    }

    return this.classTypeMatchesDir(dir);
}
项目:Androud-Studio-Plugin---CodeGenerator    文件:FindViewByMeGenerator.java   
public PsiFile getXmlPisFile(AnActionEvent event) {
    PsiFile psiFile = event.getData(LangDataKeys.PSI_FILE);
    if (null == psiFile) {
        return null;
    }
    String xmlFileName = ActionUtils.getSelection(event);
    if (xmlFileName != null) {
        String classFilePath = psiFile.getContainingDirectory().toString().replace("PsiDirectory:", "");
        String xmlFilePath = classFilePath.substring(0, classFilePath.indexOf("java")) + "res\\layout\\" + xmlFileName + ".xml";
        System.out.println(xmlFilePath);
        File file = new File(xmlFilePath);
        if (file.exists()) {
            VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
            if (virtualFile == null) {
                return psiFile;
            }
            return  PsiManager.getInstance(event.getProject()).findFile(virtualFile);
        }
    }
    return  psiFile;
}
项目:dimenify    文件:BulkGenerateAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
    super.actionPerformed(e);
    psiFile = e.getData(LangDataKeys.PSI_FILE);

    if (psiFile.getFileType() == StdFileTypes.XML) {
        xmlFile = (XmlFile) psiFile;
        String folderName = psiFile.getParent().getName();
        String bucket = null;
        if (folderName.startsWith(VALUES_PREFIX)) {
            bucket = folderName.substring(VALUES_PREFIX.length());
        } else if (folderName.equalsIgnoreCase(VALUES_PREFIX.substring(0, VALUES_PREFIX.length() - 1))) {
            bucket = Constants.MDPI;
        }


        if (bucket != null) {
            currentBucketIndex = getBucketIndex(psiFile);
            showScaleDialog(bucket, currentBucketIndex != -1);

        }
    }

}
项目:intellij-ce-playground    文件:MoveClassToModuleFix.java   
private void moveClass(Project project, Editor editor, PsiFile file, PsiClass aClass) {
  RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler();
  DataManager dataManager = DataManager.getInstance();
  DataContext dataContext = dataManager.getDataContext();
  final String fqName = aClass.getQualifiedName();
  LOG.assertTrue(fqName != null);
  PsiDirectory directory = PackageUtil
    .findOrCreateDirectoryForPackage(myCurrentModule, StringUtil.getPackageName(fqName), mySourceRoot, true);
  DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory, dataContext);

  moveHandler.invoke(project, new PsiElement[]{aClass}, context);
  PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
  PsiClass newClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.moduleScope(myCurrentModule));
  if (reference != null && newClass != null) {
    final QuestionAction action = new AddImportAction(project, reference, editor, newClass);
    action.execute();
  }
}
项目:intellij-ce-playground    文件:AnalysisScopeRule.java   
@Override
public Object getData(final DataProvider dataProvider) {
  final Object psiFile = dataProvider.getData(CommonDataKeys.PSI_FILE.getName());
  if (psiFile instanceof PsiJavaFile) {
    return new JavaAnalysisScope((PsiJavaFile)psiFile);
  }
  Object psiTarget = dataProvider.getData(CommonDataKeys.PSI_ELEMENT.getName());
  if (psiTarget instanceof PsiPackage) {
    PsiPackage pack = (PsiPackage)psiTarget;
    PsiManager manager = pack.getManager();
    if (!manager.isInProject(pack)) return null;
    PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(manager.getProject()));
    if (dirs.length == 0) return null;
    return new JavaAnalysisScope(pack, (Module)dataProvider.getData(LangDataKeys.MODULE.getName()));
  }
  return null;
}
项目:intellij-ce-playground    文件:MoveInnerToUpperOrMembersHandler.java   
public boolean tryToMove(final PsiElement element, final Project project, final DataContext dataContext, final PsiReference reference,
                         final Editor editor) {
  if (isStaticInnerClass(element) && !JavaMoveClassesOrPackagesHandler.isReferenceInAnonymousClass(reference)) {
    FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.move.moveInner");
    final PsiElement targetContainer = LangDataKeys.TARGET_PSI_ELEMENT.getData(dataContext);
    PsiClass aClass = (PsiClass)element;
    SelectInnerOrMembersRefactoringDialog dialog = new SelectInnerOrMembersRefactoringDialog(aClass, project);
    if (dialog.showAndGet()) {
      final MoveHandlerDelegate moveHandlerDelegate = dialog.getRefactoringHandler();
      if (moveHandlerDelegate != null) {
        moveHandlerDelegate.doMove(project, new PsiElement[]{aClass}, targetContainer, null);
      }
    }
    return true;
  }
  return false;
}
项目:intellij-ce-playground    文件:MoveInnerToUpperHandler.java   
public boolean tryToMove(final PsiElement element, final Project project, final DataContext dataContext, final PsiReference reference,
                         final Editor editor) {
  if (isNonStaticInnerClass(element) && !JavaMoveClassesOrPackagesHandler.isReferenceInAnonymousClass(reference)) {
    PsiClass aClass = (PsiClass) element;
    FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.move.moveInner");
    final PsiClass containingClass = aClass.getContainingClass();
    if (containingClass instanceof JspClass) {
      CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.message("move.nonstatic.class.from.jsp.not.supported"),
                                          RefactoringBundle.message("move.title"), null);
      return true;
    }
    MoveInnerImpl.doMove(project, new PsiElement[]{aClass}, null, LangDataKeys.TARGET_PSI_ELEMENT.getData(dataContext));
    return true;
  }
  return false;
}
项目:intellij-ce-playground    文件:NewLibraryChooser.java   
@Nullable
public Library createLibrary() {
  final NewLibraryConfiguration configuration =
    CreateNewLibraryAction.createNewLibraryConfiguration(myLibraryType, myParentComponent, myProject);
  if (configuration == null) return null;

  final NewLibraryEditor libraryEditor = new NewLibraryEditor(configuration.getLibraryType(), configuration.getProperties());
  libraryEditor.setName(configuration.getDefaultLibraryName());
  configuration.addRoots(libraryEditor);

  final LibraryTablesRegistrar registrar = LibraryTablesRegistrar.getInstance();
  List<LibraryTable> tables = Arrays.asList(myRootModel.getModuleLibraryTable(),
                                            registrar.getLibraryTable(myProject),
                                            registrar.getLibraryTable());

  CreateNewLibraryDialog dialog = new CreateNewLibraryDialog(myParentComponent, myContext, libraryEditor, tables, 1);
  final Module contextModule = LangDataKeys.MODULE_CONTEXT.getData(DataManager.getInstance().getDataContext(myParentComponent));
  dialog.setContextModule(contextModule);
  if (dialog.showAndGet()) {
    return dialog.createLibrary();
  }
  return null;
}
项目:intellij-ce-playground    文件:OpenModuleSettingsAction.java   
protected static boolean isModuleInProjectViewPopup(AnActionEvent e) {
  if (ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace())) {
    final Project project = getEventProject(e);
    final Module module = LangDataKeys.MODULE.getData(e.getDataContext());
    if (project != null && module != null) {
      final VirtualFile moduleFolder = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
      if (moduleFolder == null) {
        return false;
      }
      if (ProjectRootsUtil.isModuleContentRoot(moduleFolder, project) || ProjectRootsUtil.isModuleSourceRoot(moduleFolder, project)) {
        return true;
      }
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:JarFileSystemTest.java   
private void checkMove(File jar, VirtualFile vFile, final PsiFile file) {
  VirtualFile jarRoot;
  File libDir = new File(jar.getParent(), "lib");
  assertTrue(libDir.mkdir());
  final VirtualFile vLibDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libDir);
  assertNotNull(vLibDir);

  jarRoot = findByPath(vFile.getPath() + JarFileSystem.JAR_SEPARATOR);
  assertTrue(jarRoot.isValid());
  PsiDirectory directory = getPsiManager().findDirectory(vLibDir);
  final DataContext
    psiDataContext = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory);
  new WriteCommandAction.Simple(myProject) {

    @Override
    protected void run() throws Throwable {
      new MoveHandler().invoke(myProject, new PsiElement[] {file}, psiDataContext);
    }
  }.execute();
  assertFalse(jarRoot.isValid());

  jarRoot = findByPath(vFile.getPath() + JarFileSystem.JAR_SEPARATOR);
  assertTrue(jarRoot.isValid());
  rename(directory, "lib2");
  assertFalse(jarRoot.isValid());
}
项目:intellij-ce-playground    文件:ConfigurationContext.java   
private ConfigurationContext(final DataContext dataContext) {
  myRuntimeConfiguration = RunConfiguration.DATA_KEY.getData(dataContext);
  myContextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
  myModule = LangDataKeys.MODULE.getData(dataContext);
  @SuppressWarnings({"unchecked"})
  final Location<PsiElement> location = (Location<PsiElement>)Location.DATA_KEY.getData(dataContext);
  if (location != null) {
    myLocation = location;
    return;
  }
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    myLocation = null;
    return;
  }
  final PsiElement element = getSelectedPsiElement(dataContext, project);
  if (element == null) {
    myLocation = null;
    return;
  }
  myLocation = new PsiLocation<PsiElement>(project, myModule, element);
}
项目:intellij-ce-playground    文件:ConfigurationContext.java   
@Nullable
private static PsiElement getSelectedPsiElement(final DataContext dataContext, final Project project) {
  PsiElement element = null;
  final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  if (editor != null){
    final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (psiFile != null) {
      final int offset = editor.getCaretModel().getOffset();
      element = psiFile.findElementAt(offset);
      if (element == null && offset > 0 && offset == psiFile.getTextLength()) {
        element = psiFile.findElementAt(offset-1);
      }
    }
  }
  if (element == null) {
    final PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
    element = elements != null && elements.length > 0 ? elements[0] : null;
  }
  if (element == null) {
    final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
    if (files != null && files.length > 0) {
      element = PsiManager.getInstance(project).findFile(files[0]);
    }
  }
  return element;
}
项目:intellij-ce-playground    文件:CCPushLesson.java   
@Override
public void update(@NotNull AnActionEvent e) {
  e.getPresentation().setEnabledAndVisible(false);
  final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (view == null || project == null) {
    return;
  }
  final Course course = CCProjectService.getInstance(project).getCourse();
  if (course == null) {
    return;
  }
  PsiDirectory lessonDir = DirectoryChooserUtil.getOrChooseDirectory(view);
  if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
    return;
  }
  final Lesson lesson = course.getLesson(lessonDir.getName());
  if (lesson != null && lesson.id > 0) {
    e.getPresentation().setEnabledAndVisible(true);
  }
}
项目:intellij-ce-playground    文件:GotoModuleDirectory.java   
@Nullable
private static VirtualFile getModuleDir(final AnActionEvent e) {
  Module module = e.getData(LangDataKeys.MODULE_CONTEXT);
  if (module == null) {
    module = e.getData(LangDataKeys.MODULE);
  }

  if (module != null && !module.isDisposed()) {
    final VirtualFile moduleFile = module.getModuleFile();
    if (moduleFile != null && moduleFile.isValid()) {
      final VirtualFile moduleDir = moduleFile.getParent();
      if (moduleDir != null && moduleDir.isValid()) {
        return moduleDir;
      }
    }
  }

  return null;
}
项目:intellij-ce-playground    文件:AndroidBaseXmlRefactoringAction.java   
@Override
public void update(AnActionEvent e) {
  final DataContext context = e.getDataContext();

  final DataContext patchedContext = new DataContext() {
    @Override
    public Object getData(@NonNls String dataId) {
      final Object data = context.getData(dataId);
      if (data != null) {
        return data;
      }
      if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        final XmlTag[] tags = getXmlTagsFromExternalContext(context);
        return tags.length == 1 ? tags[0] : null;
      }
      else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        return getXmlTagsFromExternalContext(context);
      }
      return null;
    }
  };
  super.update(new AnActionEvent(e.getInputEvent(), patchedContext, e.getPlace(), e.getPresentation(),
                                 e.getActionManager(), e.getModifiers()));
}
项目:intellij-ce-playground    文件:MacroAwareTextBrowseFolderListener.java   
@NotNull
@Override
protected String expandPath(@NotNull String path) {
  Project project = getProject();
  if (project != null) {
    path = PathMacroManager.getInstance(project).expandPath(path);
  }

  Module module = myFileChooserDescriptor.getUserData(LangDataKeys.MODULE_CONTEXT);
  if (module == null) {
    module = myFileChooserDescriptor.getUserData(LangDataKeys.MODULE);
  }
  if (module != null) {
    path = PathMacroManager.getInstance(module).expandPath(path);
  }

  return super.expandPath(path);
}
项目:intellij-ce-playground    文件:DissociateResourceBundleAction.java   
@NotNull
private static Collection<ResourceBundle> extractResourceBundles(final AnActionEvent event) {
  final Set<ResourceBundle> targetResourceBundles = new HashSet<ResourceBundle>();
  final ResourceBundle[] chosenResourceBundles = event.getData(ResourceBundle.ARRAY_DATA_KEY);
  if (chosenResourceBundles != null) {
    for (ResourceBundle resourceBundle : chosenResourceBundles) {
      if (resourceBundle.getPropertiesFiles().size() > 1) {
        targetResourceBundles.add(resourceBundle);
      }
    }
  }
  final PsiElement[] psiElements = event.getData(LangDataKeys.PSI_ELEMENT_ARRAY);
  if (psiElements != null) {
    for (PsiElement element : psiElements) {
      final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(element);
      if (propertiesFile != null) {
        final ResourceBundle bundle = propertiesFile.getResourceBundle();
        if (bundle.getPropertiesFiles().size() > 1) {
          targetResourceBundles.add(bundle);
        }
      }
    }
  }
  return targetResourceBundles;
}
项目:intellij-ce-playground    文件:NewElementToolbarAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
  if (e.getData(LangDataKeys.IDE_VIEW) == null) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final PsiFileSystemItem psiFile = e.getData(CommonDataKeys.PSI_FILE).getParent();
    ProjectViewImpl.getInstance(project).selectCB(psiFile, psiFile.getVirtualFile(), true).doWhenDone(new Runnable() {
      @Override
      public void run() {
        showPopup(DataManager.getInstance().getDataContext());
      }
    });
  }
  else {
    super.actionPerformed(e);
  }
}
项目:intellij-ce-playground    文件:CreateSetupPyAction.java   
private static String getPackageDirs(DataContext dataContext) {
  final Module module = LangDataKeys.MODULE.getData(dataContext);
  if (module != null) {
    final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots();
    if (sourceRoots.length > 0) {
      for (VirtualFile sourceRoot : sourceRoots) {
        // TODO notify if we have multiple source roots and can't build mapping automatically
        final VirtualFile contentRoot = ProjectFileIndex.SERVICE.getInstance(module.getProject()).getContentRootForFile(sourceRoot);
        if (contentRoot != null && !Comparing.equal(contentRoot, sourceRoot)) {
          final String relativePath = VfsUtilCore.getRelativePath(sourceRoot, contentRoot, '/');
          return "\n    package_dir={'': '" + relativePath + "'},";
        }
      }
    }
  }
  return "";
}
项目:intellij-ce-playground    文件:CreateTemplateInPackageAction.java   
@Override
protected boolean isAvailable(final DataContext dataContext) {
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
  if (project == null || view == null || view.getDirectories().length == 0) {
    return false;
  }

  if (mySourceRootTypes == null) {
    return true;
  }

  ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  for (PsiDirectory dir : view.getDirectories()) {
    if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), mySourceRootTypes) && checkPackageExists(dir)) {
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:JavaSourceAction.java   
protected static boolean isAvailable(DataContext dataContext) {
  final Module module = LangDataKeys.MODULE.getData(dataContext);
  final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);

  if (module == null ||
      view == null ||
      view.getDirectories().length == 0 ||
      AndroidFacet.getInstance(module) == null) {
    return false;
  }
  final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
  final JavaDirectoryService dirService = JavaDirectoryService.getInstance();

  for (PsiDirectory dir : view.getDirectories()) {
    if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
        dirService.getPackage(dir) != null &&
        !dirService.getPackage(dir).getQualifiedName().isEmpty()) {
      return true;
    }
  }
  return false;
}
项目:intellij    文件:TestMethodSelectionUtil.java   
/**
 * Get all test methods directly selected in the given context. This includes, for example,
 * methods selected from the Structure panel. It does not include methods the context location is
 * inside of. Note that methods may belong to different classes (possible if methods are selected
 * from the Project panel with "Show Members" checked), and methods in abstract classes are not
 * returned.
 *
 * @param context The context to get selected test methods from.
 * @param allMustMatch If true, will return null if any selected elements are not test methods.
 * @return A list of test methods (possibly empty), or null if:
 *     <ul>
 *     <li>There is no selection
 *     <li>{@code allMustMatch} is true, but elements other than test methods are selected
 *     </ul>
 */
@Nullable
public static List<PsiMethod> getDirectlySelectedMethods(
    @NotNull ConfigurationContext context, boolean allMustMatch) {
  final DataContext dataContext = context.getDataContext();
  PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
  if (elements == null) {
    return null;
  }
  List<PsiMethod> methods = new ArrayList<>();
  for (PsiElement element : elements) {
    if (element instanceof PsiMethod) {
      PsiMethod method = (PsiMethod) element;
      if (JUnitUtil.isTestMethod(PsiLocation.fromPsiElement(method))) {
        methods.add(method);
      } else if (allMustMatch) {
        return null;
      }
    } else if (allMustMatch) {
      return null;
    }
  }
  return methods;
}
项目:intellij-ce-playground    文件:RestPythonUtil.java   
public static Presentation updateSphinxQuickStartRequiredAction(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();

  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (project != null) {
    Module module = e.getData(LangDataKeys.MODULE);
    if (module == null) {
      Module[] modules = ModuleManager.getInstance(project).getModules();
      module = modules.length == 0 ? null : modules [0];
    }
    if (module != null) {
      Sdk sdk = PythonSdkType.findPythonSdk(module);
      if (sdk != null) {
        PyPackageManager manager = PyPackageManager.getInstance(sdk);
        try {
          final PyPackage sphinx = manager.findPackage("Sphinx", false);
          presentation.setEnabled(sphinx != null);
        }
        catch (ExecutionException ignored) {
        }
      }
    }
  }
  return presentation;
}
项目:OkHttpParamsGet    文件:GetParamsAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
    // TODO: insert action logic here
    PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
    Project project = e.getProject();
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    TypePickDialog dialog = new TypePickDialog();
    dialog.setListener(type -> {build(type, psiFile, project, editor);});
    dialog.pack();
    dialog.setVisible(true);
}