com.intellij.ide.actions.OpenFileAction Java Examples

The following examples show how to use com.intellij.ide.actions.OpenFileAction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenCorrespondingBuildFile.java    From intellij with Apache License 2.0 6 votes vote down vote up
/** Returns true if a target or BUILD file could be found and navigated to. */
private static void navigateToTargetOrFile(Project project, VirtualFile vf) {
  // First, find the parent BUILD file. We don't want to navigate to labels in other packages
  BlazePackage parentPackage = BuildFileUtils.getBuildFile(project, vf);
  if (parentPackage == null) {
    return;
  }
  // first, look for a specific target which includes this source file
  PsiElement target =
      BuildFileUtils.findBuildTarget(project, parentPackage, new File(vf.getPath()));
  if (target instanceof NavigatablePsiElement) {
    ((NavigatablePsiElement) target).navigate(true);
    return;
  }
  OpenFileAction.openFile(parentPackage.buildFile.getFile().getPath(), project);
}
 
Example #2
Source File: SwitchContext.java    From phpstorm-plugin with MIT License 5 votes vote down vote up
public void actionPerformed(final AnActionEvent e) {
    PhpClass testedClass = getSwitchClass(e);
    if (null == testedClass) {
        return;
    }

    OpenFileAction.openFile(testedClass.getContainingFile().getVirtualFile().getPath(), e.getProject());
}
 
Example #3
Source File: NewBlazePackageAction.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent event) {
  IdeView view = event.getData(LangDataKeys.IDE_VIEW);
  if (view == null) {
    return;
  }
  PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
  if (directory == null) {
    return;
  }
  CreateDirectoryOrPackageHandler validator =
      new CreateDirectoryOrPackageHandler(project, directory, false, ".") {
        @Override
        protected void createDirectories(String subDirName) {
          super.createDirectories(subDirName);
          PsiFileSystemItem element = getCreatedElement();
          if (element instanceof PsiDirectory) {
            createBuildFile(project, (PsiDirectory) element);
          }
        }
      };
  Messages.showInputDialog(
      project,
      "Enter new package name:",
      String.format("New %s Package", Blaze.buildSystemName(project)),
      Messages.getQuestionIcon(),
      "",
      validator);
  PsiDirectory newDir = (PsiDirectory) validator.getCreatedElement();
  if (newDir != null) {
    PsiFile buildFile = findBuildFile(project, newDir);
    if (buildFile != null) {
      view.selectElement(buildFile);
      OpenFileAction.openFile(buildFile.getViewProvider().getVirtualFile(), project);
    }
  }
}
 
Example #4
Source File: OpenTypeFromVariableAction.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e)
{
	PsiElement psiElement = e.getData(CommonDataKeys.PSI_ELEMENT);
	if(!(psiElement instanceof DotNetVariable))
	{
		return;
	}

	DotNetTypeRef typeRef = ((DotNetVariable) psiElement).toTypeRef(true);

	DotNetTypeResolveResult typeResolveResult = typeRef.resolve();

	PsiElement element = typeResolveResult.getElement();
	if(!(element instanceof DotNetNamedElement))
	{
		return;
	}

	DotNetNamedElement extract = GenericUnwrapTool.extract((DotNetNamedElement) element, typeResolveResult.getGenericExtractor());

	List<StubBlock> stubBlocks = CSharpStubBuilderVisitor.buildBlocks(extract);

	CharSequence text = StubBlockUtil.buildText(stubBlocks);

	LightVirtualFile lightVirtualFile = new LightVirtualFile("dummy.cs", CSharpFileType.INSTANCE, text);

	OpenFileAction.openFile(lightVirtualFile, psiElement.getProject());
}
 
Example #5
Source File: OpenAndroidModule.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static void openOrImportProject(@NotNull VirtualFile projectFile,
                                        @Nullable Project project,
                                        @Nullable VirtualFile sourceFile,
                                        boolean forceOpenInNewFrame) {
  // This is very similar to AndroidOpenFileAction.openOrImportProject().
  if (canImportAsGradleProject(projectFile)) {
    VirtualFile target = findGradleTarget(projectFile);
    if (target != null) {
      Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
      if (openProjects.length > 0) {
        int exitCode = forceOpenInNewFrame ? GeneralSettings.OPEN_PROJECT_NEW_WINDOW : confirmOpenNewProject(false);
        if (exitCode == GeneralSettings.OPEN_PROJECT_SAME_WINDOW) {
          Project toClose = ((project != null) && !project.isDefault()) ? project : openProjects[openProjects.length - 1];
          if (!closeAndDispose(toClose)) {
            return;
          }
        }
        else if (exitCode != GeneralSettings.OPEN_PROJECT_NEW_WINDOW) {
          return;
        }
      }

      GradleProjectImporter gradleImporter = GradleProjectImporter.getInstance();
      gradleImporter.importAndOpenProjectCore(null, true, projectFile);
      for (Project proj : ProjectManager.getInstance().getOpenProjects()) {
        if (projectFile.equals(proj.getBaseDir()) || projectFile.equals(proj.getProjectFile())) {
          if (sourceFile != null && !sourceFile.isDirectory()) {
            OpenFileAction.openFile(sourceFile, proj);
          }
          break;
        }
      }
      return;
    }
  }
  Project newProject = openOrImport(projectFile.getPath(), project, false);
  if (newProject != null) {
    setLastOpenedFile(newProject, projectFile);
    if (sourceFile != null && !sourceFile.isDirectory()) {
      OpenFileAction.openFile(sourceFile, newProject);
    }
  }
}
 
Example #6
Source File: OpenAndroidModule.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static void openOrImportProject(@NotNull VirtualFile projectFile,
                                        @Nullable Project project,
                                        @Nullable VirtualFile sourceFile,
                                        boolean forceOpenInNewFrame) {
  // This is very similar to AndroidOpenFileAction.openOrImportProject().
  if (canImportAsGradleProject(projectFile)) {
    VirtualFile target = findGradleTarget(projectFile);
    if (target != null) {
      Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
      if (openProjects.length > 0) {
        int exitCode = forceOpenInNewFrame ? GeneralSettings.OPEN_PROJECT_NEW_WINDOW : confirmOpenNewProject(false);
        if (exitCode == GeneralSettings.OPEN_PROJECT_SAME_WINDOW) {
          Project toClose = ((project != null) && !project.isDefault()) ? project : openProjects[openProjects.length - 1];
          if (!closeAndDispose(toClose)) {
            return;
          }
        }
        else if (exitCode != GeneralSettings.OPEN_PROJECT_NEW_WINDOW) {
          return;
        }
      }

      GradleProjectImporter gradleImporter = GradleProjectImporter.getInstance();
      gradleImporter.importAndOpenProjectCore(null, true, projectFile);
      for (Project proj : ProjectManager.getInstance().getOpenProjects()) {
        if (projectFile.equals(proj.getBaseDir()) || projectFile.equals(proj.getProjectFile())) {
          if (sourceFile != null && !sourceFile.isDirectory()) {
            OpenFileAction.openFile(sourceFile, proj);
          }
          break;
        }
      }
      return;
    }
  }
  Project newProject = openOrImport(projectFile.getPath(), project, false);
  if (newProject != null) {
    setLastOpenedFile(newProject, projectFile);
    if (sourceFile != null && !sourceFile.isDirectory()) {
      OpenFileAction.openFile(sourceFile, newProject);
    }
  }
}
 
Example #7
Source File: OpenBlazeWorkspaceFileAction.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
protected void doOKAction() {
  OpenFileAction.openFile(fileTextField.getSelectedFile(), project);
  super.doOKAction();
}