Java Code Examples for com.intellij.openapi.actionSystem.CommonDataKeys#VIRTUAL_FILE

The following examples show how to use com.intellij.openapi.actionSystem.CommonDataKeys#VIRTUAL_FILE . 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: DesktopEditorComposite.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public final Object getData(@Nonnull Key<?> dataId) {
  if (PlatformDataKeys.FILE_EDITOR == dataId) {
    return getSelectedEditor();
  }
  else if (CommonDataKeys.VIRTUAL_FILE == dataId) {
    return myFile.isValid() ? myFile : null;
  }
  else if (CommonDataKeys.VIRTUAL_FILE_ARRAY == dataId) {
    return myFile.isValid() ? new VirtualFile[]{myFile} : null;
  }
  else {
    JComponent component = getPreferredFocusedComponent();
    if (component instanceof DataProvider && component != this) {
      return ((DataProvider)component).getData(dataId);
    }
    return null;
  }
}
 
Example 2
Source File: TextEditorComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getData(@Nonnull final Key<?> dataId) {
  final Editor e = validateCurrentEditor();
  if (e == null || e.isDisposed()) return null;

  // There's no FileEditorManager for default project (which is used in diff command-line application)
  if (!myProject.isDisposed() && !myProject.isDefault()) {
    final Object o = FileEditorManager.getInstance(myProject).getData(dataId, e, e.getCaretModel().getCurrentCaret());
    if (o != null) return o;
  }

  if (CommonDataKeys.EDITOR == dataId) {
    return e;
  }
  if (CommonDataKeys.VIRTUAL_FILE == dataId) {
    return myFile.isValid() ? myFile : null;  // fix for SCR 40329
  }
  return null;
}
 
Example 3
Source File: OnesideDiffViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (CommonDataKeys.VIRTUAL_FILE == dataId) {
    return DiffUtil.getVirtualFile(myRequest, mySide);
  }
  else if (DiffDataKeys.CURRENT_CONTENT == dataId) {
    return getContent();
  }
  return super.getData(dataId);
}
 
Example 4
Source File: TwosideDiffViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (CommonDataKeys.VIRTUAL_FILE == dataId) {
    return DiffUtil.getVirtualFile(myRequest, getCurrentSide());
  }
  else if (DiffDataKeys.CURRENT_CONTENT == dataId) {
    return getCurrentSide().select(myRequest.getContents());
  }
  return super.getData(dataId);
}
 
Example 5
Source File: ThreesideDiffViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (CommonDataKeys.VIRTUAL_FILE == dataId) {
    return DiffUtil.getVirtualFile(myRequest, getCurrentSide());
  }
  else if (DiffDataKeys.CURRENT_CONTENT == dataId) {
    return getCurrentSide().select(myRequest.getContents());
  }
  return super.getData(dataId);
}
 
Example 6
Source File: FileGroupingRule.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void calcData(final Key<?> key, final DataSink sink) {
  if (!isValid()) return;
  if (key == CommonDataKeys.VIRTUAL_FILE) {
    sink.put(CommonDataKeys.VIRTUAL_FILE, myFile);
  }
  if (key == CommonDataKeys.PSI_ELEMENT) {
    sink.put(CommonDataKeys.PSI_ELEMENT, getPsiFile());
  }
}
 
Example 7
Source File: DesktopEditorWindow.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object getData(@Nonnull Key<?> dataId) {
  if (CommonDataKeys.VIRTUAL_FILE == dataId) {
    final VirtualFile virtualFile = myEditor.getFile();
    return virtualFile.isValid() ? virtualFile : null;
  }
  if (CommonDataKeys.PROJECT == dataId) {
    return myEditor.getFileEditorManager().getProject();
  }
  return null;
}
 
Example 8
Source File: XVariablesView.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object getData(@Nonnull Key<?> dataId) {
  if (CommonDataKeys.VIRTUAL_FILE == dataId) {
    return getCurrentFile(getTree());
  }
  return null;
}
 
Example 9
Source File: VirtualFileRule.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<VirtualFile> getKey() {
  return CommonDataKeys.VIRTUAL_FILE;
}