Java Code Examples for com.intellij.openapi.fileEditor.OpenFileDescriptor#NAVIGATE_IN_EDITOR

The following examples show how to use com.intellij.openapi.fileEditor.OpenFileDescriptor#NAVIGATE_IN_EDITOR . 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: TestDataProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object getData(@Nonnull Key<?> dataId) {
  if (myProject.isDisposed()) {
    throw new RuntimeException("TestDataProvider is already disposed for " + myProject + "\n" +
                               "If you closed a project in test, please reset IdeaTestApplication.setDataProvider.");
  }

  if (CommonDataKeys.PROJECT == dataId) {
    return myProject;
  }
  else if (PlatformDataKeys.EDITOR == dataId || OpenFileDescriptor.NAVIGATE_IN_EDITOR == dataId) {
    return FileEditorManager.getInstance(myProject).getSelectedTextEditor();
  }
  else {
    Editor editor = (Editor)getData(PlatformDataKeys.EDITOR);
    if (editor != null) {
      FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(myProject);
      Object managerData = manager.getData(dataId, editor, editor.getCaretModel().getCurrentCaret());
      if (managerData != null) {
        return managerData;
      }
      JComponent component = editor.getContentComponent();
      if (component instanceof EditorComponentImpl) {
        return ((EditorComponentImpl)component).getData(dataId);
      }
    }
    return null;
  }
}
 
Example 2
Source File: BookmarkManagerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object getData(@Nonnull Key dataId) {
  if (OpenFileDescriptor.NAVIGATE_IN_EDITOR == dataId) {
    return myEditor;
  }
  return super.getData(dataId);
}
 
Example 3
Source File: LanguageConsoleImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
protected Object getEditorData(@Nonnull EditorEx editor, Key dataId) {
  if (OpenFileDescriptor.NAVIGATE_IN_EDITOR == dataId) {
    return editor;
  }
  else if (project.isInitialized()) {
    Caret caret = editor.getCaretModel().getCurrentCaret();
    return FileEditorManagerEx.getInstanceEx(project).getData(dataId, editor, caret);
  }
  return null;
}
 
Example 4
Source File: FileStructureDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object getData(@Nonnull Key dataId) {
  Object selectedElement = myCommanderPanel.getSelectedValue();

  if (selectedElement instanceof TreeElement) selectedElement = ((StructureViewTreeElement)selectedElement).getValue();

  if (PlatformDataKeys.NAVIGATABLE == dataId) {
    return selectedElement instanceof Navigatable ? selectedElement : myNavigatable;
  }

  if (OpenFileDescriptor.NAVIGATE_IN_EDITOR == dataId) return myEditor;

  return getDataImpl(dataId);
}
 
Example 5
Source File: HeavyIdeaTestFixtureImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (CommonDataKeys.PROJECT == dataId) {
    return myProject;
  }
  else if (PlatformDataKeys.EDITOR == dataId || OpenFileDescriptor.NAVIGATE_IN_EDITOR == dataId) {
    if (myProject == null) return null;
    return FileEditorManager.getInstance(myProject).getSelectedTextEditor();
  }
  else {
    Editor editor = (Editor)getData(PlatformDataKeys.EDITOR);
    if (editor != null) {
      FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(myProject);
      return manager.getData(dataId, editor, editor.getCaretModel().getCurrentCaret());
    }
    else if (LangDataKeys.IDE_VIEW == dataId) {
      VirtualFile[] contentRoots = ProjectRootManager.getInstance(myProject).getContentRoots();
      final PsiDirectory psiDirectory = PsiManager.getInstance(myProject).findDirectory(contentRoots[0]);
      if (contentRoots.length > 0) {
        return new IdeView() {
          @Override
          public void selectElement(PsiElement element) {

          }

          @Override
          public PsiDirectory[] getDirectories() {
            return new PsiDirectory[] {psiDirectory};
          }

          @Override
          public PsiDirectory getOrChooseDirectory() {
            return psiDirectory;
          }
        };
      }
    }
    return null;
  }
}