Java 类com.intellij.openapi.editor.actions.PasteAction 实例源码

项目:intellij-ce-playground    文件:PasteReferenceProvider.java   
@Nullable
private static String getCopiedFqn(final DataContext context) {
  Producer<Transferable> producer = PasteAction.TRANSFERABLE_PROVIDER.getData(context);

  if (producer != null) {
    Transferable transferable = producer.produce();
    if (transferable != null) {
      try {
        return (String)transferable.getTransferData(CopyReferenceAction.ourFlavor);
      }
      catch (Exception ignored) { }
    }
    return null;
  }

  return CopyPasteManager.getInstance().getContents(CopyReferenceAction.ourFlavor);
}
项目:consulo    文件:PasteReferenceProvider.java   
@Nullable
private static String getCopiedFqn(final DataContext context) {
  Producer<Transferable> producer = context.getData(PasteAction.TRANSFERABLE_PROVIDER);

  if (producer != null) {
    Transferable transferable = producer.produce();
    if (transferable != null) {
      try {
        return (String)transferable.getTransferData(CopyReferenceAction.ourFlavor);
      }
      catch (Exception ignored) { }
    }
    return null;
  }

  return CopyPasteManager.getInstance().getContents(CopyReferenceAction.ourFlavor);
}
项目:MissingInActions    文件:ClipboardCaretContent.java   
@Nullable
public static Transferable getTransferable(final @NotNull Editor editor, DataContext dataContext) {
    try {
        Producer<Transferable> producer = PasteAction.TRANSFERABLE_PROVIDER.getData(dataContext);
        //noinspection UnnecessaryLocalVariable
        Transferable transferable = EditorModificationUtil.getContentsToPasteToEditor(producer);
        return transferable;
    } catch (Throwable e) {
        logger.error("error", e);
    }
    return null;
}
项目:intellij-ce-playground    文件:PasteHandler.java   
@Override
public void execute(final Editor editor, final DataContext dataContext, @Nullable final Producer<Transferable> producer) {
  final Transferable transferable = EditorModificationUtil.getContentsToPasteToEditor(producer);
  if (transferable == null) return;

  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;

  final Document document = editor.getDocument();
  if (!FileDocumentManager.getInstance().requestWriting(document, CommonDataKeys.PROJECT.getData(dataContext))) {
    return;
  }

  DataContext context = new DataContext() {
    @Override
    public Object getData(@NonNls String dataId) {
      return PasteAction.TRANSFERABLE_PROVIDER.is(dataId) ? new Producer<Transferable>() {
        @Nullable
        @Override
        public Transferable produce() {
          return transferable;
        }
      } : dataContext.getData(dataId);
    }
  };

  final Project project = editor.getProject();
  if (project == null || editor.isColumnMode() || editor.getCaretModel().getCaretCount() > 1) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, null, context);
    }
    return;
  }

  final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
  if (file == null) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, null, context);
    }
    return;
  }

  DumbService.getInstance(project).setAlternativeResolveEnabled(true);
  document.startGuardedBlockChecking();
  try {
    for (PasteProvider provider : Extensions.getExtensions(EP_NAME)) {
      if (provider.isPasteEnabled(context)) {
        provider.performPaste(context);
        return;
      }
    }
    doPaste(editor, project, file, document, transferable);
  }
  catch (ReadOnlyFragmentModificationException e) {
    EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
  }
  finally {
    document.stopGuardedBlockChecking();
    DumbService.getInstance(project).setAlternativeResolveEnabled(false);
  }
}
项目:consulo    文件:PasteHandler.java   
@Override
public void execute(final Editor editor, final DataContext dataContext, @Nullable final Producer<Transferable> producer) {
  final Transferable transferable = EditorModificationUtil.getContentsToPasteToEditor(producer);
  if (transferable == null) return;

  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;

  final Document document = editor.getDocument();
  if (!FileDocumentManager.getInstance().requestWriting(document, dataContext.getData(CommonDataKeys.PROJECT))) {
    return;
  }

  DataContext context = new DataContext() {
    @Override
    public Object getData(@NonNls Key dataId) {
      return PasteAction.TRANSFERABLE_PROVIDER == dataId ? new Producer<Transferable>() {
        @Nullable
        @Override
        public Transferable produce() {
          return transferable;
        }
      } : dataContext.getData(dataId);
    }
  };

  final Project project = editor.getProject();
  if (project == null || editor.isColumnMode() || editor.getCaretModel().getCaretCount() > 1) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, null, context);
    }
    return;
  }

  final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
  if (file == null) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, null, context);
    }
    return;
  }

  DumbService.getInstance(project).setAlternativeResolveEnabled(true);
  document.startGuardedBlockChecking();
  try {
    for (PasteProvider provider : Extensions.getExtensions(EP_NAME)) {
      if (provider.isPasteEnabled(context)) {
        provider.performPaste(context);
        return;
      }
    }
    doPaste(editor, project, file, document, transferable);
  }
  catch (ReadOnlyFragmentModificationException e) {
    EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
  }
  finally {
    document.stopGuardedBlockChecking();
    DumbService.getInstance(project).setAlternativeResolveEnabled(false);
  }
}