当前位置: 首页>>代码示例>>Java>>正文


Java FileEditorManager.openFile方法代码示例

本文整理汇总了Java中com.intellij.openapi.fileEditor.FileEditorManager.openFile方法的典型用法代码示例。如果您正苦于以下问题:Java FileEditorManager.openFile方法的具体用法?Java FileEditorManager.openFile怎么用?Java FileEditorManager.openFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.fileEditor.FileEditorManager的用法示例。


在下文中一共展示了FileEditorManager.openFile方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dotest

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
private void dotest(CheckAction checkAction) throws Exception {
  final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
  final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
  final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
  FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
  final FileEditor fileEditor = fileEditors[0];
  try {
    final StructureViewComponent structureViewComponent =
      (StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);

    checkAction.testClassStructure(structureViewComponent);
    Disposer.dispose(structureViewComponent);

  }
  finally {
    fileEditorManager.closeFile(virtualFile);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:JavaTreeStructureTest.java

示例2: actionPerformed

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
public void actionPerformed(AnActionEvent e) {
    ThumbnailView view = ThumbnailViewActionUtil.getVisibleThumbnailView(e);
    if (view != null) {
        VirtualFile[] selection = view.getSelection();
        if (selection.length == 1 && selection[0].isDirectory()) {
            view.setRoot(selection[0]);
        } else if (selection.length > 0) {
            FileEditorManager fileEditorManager = FileEditorManager.getInstance(view.getProject());
            ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
            for (VirtualFile file : selection) {
                if (typeManager.isImage(file)) {
                    fileEditorManager.openFile(file, false);
                }
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:EnterAction.java

示例3: updateOpenedTestFiles

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
private static void updateOpenedTestFiles(@NotNull Project project,
                                          @NotNull VirtualFile taskDir,
                                          int fromTaskNumber,
                                          int toSubtaskNumber) {
  String fromSubtaskTestName = getTestFileName(project, fromTaskNumber);
  String toSubtaskTestName = getTestFileName(project, toSubtaskNumber);
  if (fromSubtaskTestName == null || toSubtaskTestName == null) {
    return;
  }
  VirtualFile fromTest = taskDir.findChild(fromSubtaskTestName);
  VirtualFile toTest = taskDir.findChild(toSubtaskTestName);
  if (fromTest == null || toTest == null) {
    return;
  }
  FileEditorManager editorManager = FileEditorManager.getInstance(project);
  if (editorManager.isFileOpen(fromTest)) {
    VirtualFile[] selectedFiles = editorManager.getSelectedFiles();
    boolean isSelected = ArrayUtil.contains(fromTest, selectedFiles);
    editorManager.closeFile(fromTest);
    editorManager.openFile(toTest, isSelected);
    if (!isSelected) {
      for (VirtualFile file : selectedFiles) {
        editorManager.openFile(file, true);
      }
    }
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:28,代码来源:StudySubtaskUtils.java

示例4: openFiles

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
/**
 * open mvp's java file.
 *
 * @param project
 */
private static void openFiles(Project project, PsiClass... psiClasses) {
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    for (PsiClass psiClass :
            psiClasses) {
        fileEditorManager.openFile(psiClass.getContainingFile().getVirtualFile(), true, true);
    }
}
 
开发者ID:xujiaji,项目名称:MVPManager,代码行数:13,代码来源:ClassHelper.java

示例5: testExpandElementWithExitingName

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
public void testExpandElementWithExitingName() throws InterruptedException {

    final VirtualFile xmlVirtualFile = getContentRoot().findFileByRelativePath("test.xml");
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    FileEditor[] fileEditors = fileEditorManager.openFile(xmlVirtualFile, false);
    final FileEditor fileEditor = fileEditors[0];
    try {
      final StructureViewComponent structureViewComponent =
        (StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);

      final JTree tree = structureViewComponent.getTree();
      PlatformTestUtil.assertTreeEqual(tree, "-test.xml\n" +
                                             " -test\n" +
                                             "  +level1\n" +
                                             "  +level1\n" +
                                             "  +level1\n" +
                                             "  +level1\n");

      tree.expandPath(tree.getPathForRow(3));

      PlatformTestUtil.waitForAlarm(600);


      PlatformTestUtil.assertTreeEqual(tree,
                                       "-test.xml\n" +
                                       " -test\n" +
                                       "  +level1\n" +
                                       "  -level1\n" +
                                       "   +level2\n" +
                                       "  +level1\n" +
                                       "  +level1\n");

      Disposer.dispose(structureViewComponent);
    }
    finally {
      fileEditorManager.closeFile(xmlVirtualFile);
    }

  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:StructureViewUpdatingTest.java

示例6: activatePsiElementIfOpen

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
private static boolean activatePsiElementIfOpen(@NotNull PsiElement elt, boolean searchForOpen, boolean requestFocus) {
  if (!elt.isValid()) return false;
  elt = elt.getNavigationElement();
  final PsiFile file = elt.getContainingFile();
  if (file == null || !file.isValid()) return false;

  VirtualFile vFile = file.getVirtualFile();
  if (vFile == null) return false;

  if (!EditorHistoryManager.getInstance(elt.getProject()).hasBeenOpen(vFile)) return false;

  final FileEditorManager fem = FileEditorManager.getInstance(elt.getProject());
  if (!fem.isFileOpen(vFile)) {
    fem.openFile(vFile, requestFocus, searchForOpen);
  }

  final TextRange range = elt.getTextRange();
  if (range == null) return false;

  final FileEditor[] editors = fem.getEditors(vFile);
  for (FileEditor editor : editors) {
    if (editor instanceof TextEditor) {
      final Editor text = ((TextEditor)editor).getEditor();
      final int offset = text.getCaretModel().getOffset();

      if (range.containsOffset(offset)) {
        // select the file
        fem.openFile(vFile, requestFocus, searchForOpen);
        return true;
      }
    }
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:NavigationUtil.java

示例7: addDependency

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
@Override
public void addDependency(Module module, String artifact) {
  Project project = module.getProject();
  BlazeProjectData blazeProjectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (blazeProjectData == null) {
    return;
  }
  AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
  TargetIdeInfo targetIdeInfo = blazeProjectData.targetMap.get(registry.getTargetKey(module));
  if (targetIdeInfo == null || targetIdeInfo.buildFile == 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.key.label);
  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.
    File buildIoFile = blazeProjectData.artifactLocationDecoder.decode(targetIdeInfo.buildFile);
    VirtualFile buildVirtualFile =
        VirtualFileSystemProvider.findFileByIoFileRefreshIfNeeded(buildIoFile);
    if (buildVirtualFile != null) {
      fileEditorManager.openFile(buildVirtualFile, true);
    }
  }
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:40,代码来源:BlazeBuildSystemService.java

示例8: testJavaClassStructure

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
public void testJavaClassStructure() throws Exception {
  final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
  final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
  final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
  FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
  final FileEditor fileEditor = fileEditors[0];
  try {
    final StructureViewComponent structureViewComponent =
      (StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
    final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile());
    structureViewComponent.setActionActive(InheritedMembersNodeProvider.ID, true);
    PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(),
                                     "-Class1.java\n" +
                                     " -Class1\n" +
                                     "  getValue(): int\n" +
                                     "  getClass(): Class<? extends Object>\n" +
                                     "  hashCode(): int\n" +
                                     "  equals(Object): boolean\n" +
                                     "  clone(): Object\n" +
                                     "  toString(): String\n" +
                                     "  notify(): void\n" +
                                     "  notifyAll(): void\n" +
                                     "  wait(long): void\n" +
                                     "  wait(long, int): void\n" +
                                     "  wait(): void\n" +
                                     "  finalize(): void\n" +
                                     "  myField1: boolean\n" +
                                     "  myField2: boolean\n");

    new WriteCommandAction.Simple(getProject()) {
      @Override
      protected void run() throws Throwable {
        final int offset = document.getLineStartOffset(5);
        document.insertString(offset, "    boolean myNewField = false;\n");
      }
    }.execute().throwException();


    PsiDocumentManager.getInstance(myProject).commitDocument(document);

    PlatformTestUtil.waitForAlarm(600);

    //TreeUtil.expand(structureViewComponent.getTree(), 3);

    PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" +
                                                                       " -Class1\n" + "  getValue(): int\n" +
                                                                       "  getClass(): Class<? extends Object>\n" +
                                                                       "  hashCode(): int\n" +
                                                                       "  equals(Object): boolean\n" +
                                                                       "  clone(): Object\n" +
                                                                       "  toString(): String\n" +
                                                                       "  notify(): void\n" +
                                                                       "  notifyAll(): void\n" +
                                                                       "  wait(long): void\n" +
                                                                       "  wait(long, int): void\n" +
                                                                       "  wait(): void\n" +
                                                                       "  finalize(): void\n" +
                                                                       "  myField1: boolean\n" +
                                                                       "  myField2: boolean\n" +
                                                                       "  myNewField: boolean = false\n");

    Disposer.dispose(structureViewComponent);

  }
  finally {
    fileEditorManager.closeFile(virtualFile);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:69,代码来源:StructureViewUpdatingTest.java

示例9: testShowClassMembers

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
public void testShowClassMembers() throws Exception {
  final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
  final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
  final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
  FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
  final FileEditor fileEditor = fileEditors[0];
  final StructureViewComponent structureViewComponent =
    (StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
  try {
    PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
                                                                       " -Class2\n" +
                                                                       "  +InnerClass1\n" +
                                                                       "  +InnerClass2\n" +
                                                                       "  getValue(): int\n" +
                                                                       "  myField1: boolean\n" +
                                                                       "  myField2: boolean\n" +
                                                                       "  myField3: boolean\n" +
                                                                       "  myField4: boolean\n");

    final PsiField innerClassField = psiClass.getInnerClasses()[0].getFields()[0];

    structureViewComponent.select(innerClassField, true);

    PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
                                                                       " -Class2\n" +
                                                                       "  -InnerClass1\n" +
                                                                       "   +InnerClass12\n" +
                                                                       "   myInnerClassField: int\n" +
                                                                       "  +InnerClass2\n" +
                                                                       "  getValue(): int\n" +
                                                                       "  myField1: boolean\n" +
                                                                       "  myField2: boolean\n" +
                                                                       "  myField3: boolean\n" +
                                                                       "  myField4: boolean\n");

    CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
      @Override
      public void run() {

        WriteCommandAction.runWriteCommandAction(null, new Runnable() {
          @Override
          public void run() {
            try {
              innerClassField.delete();
            }
            catch (IncorrectOperationException e) {
              fail(e.getLocalizedMessage());
            }
          }
        });
      }
    }, null, null);

    PlatformTestUtil.waitForAlarm(600);

    PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
                                                                       " -Class2\n" +
                                                                       "  -InnerClass1\n" +
                                                                       "   +InnerClass12\n" +
                                                                       "  +InnerClass2\n" +
                                                                       "  getValue(): int\n" +
                                                                       "  myField1: boolean\n" +
                                                                       "  myField2: boolean\n" +
                                                                       "  myField3: boolean\n" +
                                                                       "  myField4: boolean\n");

  }
  finally {
    Disposer.dispose(structureViewComponent);
    fileEditorManager.closeFile(virtualFile);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:73,代码来源:StructureViewUpdatingTest.java

示例10: mouseClicked

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
public void mouseClicked(MouseEvent e) {
    Point point = e.getPoint();
    int index = list.locationToIndex(point);
    if (index != -1) {
        Rectangle cellBounds = list.getCellBounds(index, index);
        if (!cellBounds.contains(point) && (KeyEvent.CTRL_DOWN_MASK & e.getModifiersEx()) != KeyEvent.CTRL_DOWN_MASK) {
            index = -1;
            list.clearSelection();
        }
    }
    if (index != -1) {
        if (MouseEvent.BUTTON1 == e.getButton() && e.getClickCount() == 2) {
            // Double click
            list.setSelectedIndex(index);
            VirtualFile selected = (VirtualFile) list.getSelectedValue();
            if (selected != null) {
                if (selected.isDirectory()) {
                    thumbnailView.setRoot(selected);
                } else {
                    FileEditorManager fileEditorManager = FileEditorManager.getInstance(thumbnailView.getProject());
                    fileEditorManager.openFile(selected, true);
                }
                e.consume();
            }
        }
        if (MouseEvent.BUTTON3 == e.getButton() && e.getClickCount() == 1) {
            // Ensure that we have selection
            if ((KeyEvent.CTRL_DOWN_MASK & e.getModifiersEx()) != KeyEvent.CTRL_DOWN_MASK) {
                // Ctrl is not pressed
                list.setSelectedIndex(index);
            } else {
                // Ctrl is pressed
                list.getSelectionModel().addSelectionInterval(index, index);
            }
            // Single right click
            ActionManager actionManager = ActionManager.getInstance();
            ActionGroup actionGroup = (ActionGroup) actionManager.getAction(ThumbnailViewActions.GROUP_POPUP);
            ActionPopupMenu menu = actionManager.createActionPopupMenu(ThumbnailViewActions.ACTION_PLACE, actionGroup);
            JPopupMenu popupMenu = menu.getComponent();
            popupMenu.pack();
            popupMenu.show(e.getComponent(), e.getX(), e.getY());

            e.consume();
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:47,代码来源:ThumbnailViewUI.java

示例11: navigate

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
public void navigate(boolean requestFocus) {
    if (file != null) {
        FileEditorManager manager = FileEditorManager.getInstance(thumbnailView.getProject());
        manager.openFile(file, true);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:ThumbnailViewUI.java


注:本文中的com.intellij.openapi.fileEditor.FileEditorManager.openFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。