Java Code Examples for com.intellij.openapi.fileEditor.FileEditorManager#openTextEditor()

The following examples show how to use com.intellij.openapi.fileEditor.FileEditorManager#openTextEditor() . 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: PantsHighlightingIntegrationTest.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
protected Editor createEditor(@NotNull VirtualFile file) {
  final FileEditorManager instance = FileEditorManager.getInstance(myProject);
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  Editor editor = instance.openTextEditor(new OpenFileDescriptor(myProject, file), false);
  if (editor != null) {
    editor.getCaretModel().moveToOffset(0);
    DaemonCodeAnalyzer.getInstance(myProject).restart();
  }
  return editor;
}
 
Example 2
Source File: FoldingTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private String getFoldingDescription(@Nonnull String content, @Nonnull String fileName, boolean doCheckCollapseStatus) {
  FileType fileTypeByFileName = FileTypeManager.getInstance().getFileTypeByFileName(fileName);

  PsiFile file = createFile(fileName, fileTypeByFileName, content);

  final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);

  Editor editor = fileEditorManager.openTextEditor(new OpenFileDescriptor(myProject, file.getVirtualFile()), false);

  CodeFoldingManager.getInstance(myProject).buildInitialFoldings(editor);

  final FoldingModel model = editor.getFoldingModel();
  final FoldRegion[] foldingRegions = model.getAllFoldRegions();
  final List<Border> borders = new LinkedList<Border>();

  for (FoldRegion region : foldingRegions) {
    borders.add(new Border(Border.LEFT, region.getStartOffset(), region.getPlaceholderText(), region.isExpanded()));
    borders.add(new Border(Border.RIGHT, region.getEndOffset(), "", region.isExpanded()));
  }
  Collections.sort(borders);

  StringBuilder result = new StringBuilder(editor.getDocument().getText());
  for (Border border : borders) {
    result.insert(border.getOffset(), border.isSide() == Border.LEFT ? "<fold text=\'" + border.getText() + "\'" +
                                                                       (doCheckCollapseStatus ? " expand=\'" +
                                                                                                border.isExpanded() +
                                                                                                "\'" : "") +
                                                                       ">" : END_FOLD);
  }

  return result.toString();
}
 
Example 3
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Editor createEditor(VirtualFile file) {
  final Project project = getProject();
  final FileEditorManager instance = FileEditorManager.getInstance(project);
  if (file.getFileType().isBinary()) {
    return null;
  }
  return instance.openTextEditor(new OpenFileDescriptor(project, file, 0), false);
}
 
Example 4
Source File: BlazeModuleSystem.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public void registerDependency(GradleCoordinate coordinate, DependencyType type) {
  if (type != DependencyType.IMPLEMENTATION) {
    throw new UnsupportedOperationException("Unsupported dependency type in Blaze: " + type);
  }
  BlazeProjectData blazeProjectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (blazeProjectData == null) {
    return;
  }
  AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
  TargetIdeInfo targetIdeInfo =
      blazeProjectData.getTargetMap().get(registry.getTargetKey(module));
  if (targetIdeInfo == null || targetIdeInfo.getBuildFile() == null) {
    return;
  }

  // TODO: automagically edit deps instead of just opening the BUILD file?
  // Need to translate Gradle coordinates into blaze targets.
  // Will probably need to hardcode for each dependency.
  FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
  PsiElement buildTargetPsi =
      BuildReferenceManager.getInstance(project).resolveLabel(targetIdeInfo.getKey().getLabel());
  if (buildTargetPsi != null) {
    // If we can find a PSI for the target,
    // then we can jump straight to the target in the build file.
    fileEditorManager.openTextEditor(
        new OpenFileDescriptor(
            project,
            buildTargetPsi.getContainingFile().getVirtualFile(),
            buildTargetPsi.getTextOffset()),
        true);
  } else {
    // If not, just the build file is good enough.
    ArtifactLocation buildFile = targetIdeInfo.getBuildFile();
    File buildIoFile =
        Preconditions.checkNotNull(
            OutputArtifactResolver.resolve(
                project, blazeProjectData.getArtifactLocationDecoder(), buildFile),
            "Fail to find file %s",
            buildFile.getRelativePath());
    VirtualFile buildVirtualFile =
        VfsUtils.resolveVirtualFile(buildIoFile, /* refreshIfNeeded= */ true);
    if (buildVirtualFile != null) {
      fileEditorManager.openFile(buildVirtualFile, true);
    }
  }
}