com.intellij.openapi.editor.RawText Java Examples

The following examples show how to use com.intellij.openapi.editor.RawText. 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: TextBlockTransferable.java    From consulo with Apache License 2.0 6 votes vote down vote up
public TextBlockTransferable(@Nonnull String text, @Nonnull Collection<TextBlockTransferableData> extraData, @Nullable RawText rawText) {
  myText = cleanFromNullsIfNeeded(text);
  myExtraData = extraData;
  myRawText = rawText;

  List<DataFlavor> dataFlavors = new ArrayList<DataFlavor>();
  Collections.addAll(dataFlavors, DataFlavor.stringFlavor, DataFlavor.plainTextFlavor);
  final DataFlavor flavor = RawText.getDataFlavor();
  if (myRawText != null && flavor != null) {
    dataFlavors.add(flavor);
  }
  for(TextBlockTransferableData data: extraData) {
    final DataFlavor blockFlavor = data.getFlavor();
    if (blockFlavor != null) {
      dataFlavors.add(blockFlavor);
    }
  }
  myTransferDataFlavors = dataFlavors.toArray(new DataFlavor[dataFlavors.size()]);
}
 
Example #2
Source File: TextBlockTransferable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
  try {
    for(TextBlockTransferableData data: myExtraData) {
      if (Comparing.equal(data.getFlavor(), flavor)) {
        return data;
      }
    }
    if (myRawText != null && Comparing.equal(RawText.getDataFlavor(), flavor)) {
      return myRawText;
    }
    else if (DataFlavor.stringFlavor.equals(flavor)) {
      return myText;
    }
    else if (DataFlavor.plainTextFlavor.equals(flavor)) {
      return new StringReader(myText);
    }
  }
  catch(NoClassDefFoundError e) {
    // ignore
  }
  throw new UnsupportedFlavorException(flavor);
}
 
Example #3
Source File: BuckCopyPasteProcessor.java    From Buck-IntelliJ-Plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public String preprocessOnPaste(
    Project project, PsiFile psiFile, Editor editor, String text, RawText rawText) {
  if (!(psiFile instanceof BuckFile)) {
    return text;
  }
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  final SelectionModel selectionModel = editor.getSelectionModel();

  // Pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor.
  final int selectionStart = selectionModel.getSelectionStart();
  final PsiElement element = psiFile.findElementAt(selectionStart);
  if (element == null) {
    return text;
  }

  if (BuckPsiUtils.hasElementType(
      element.getNode(),
      TokenType.WHITE_SPACE,
      BuckTypes.SINGLE_QUOTED_STRING,
      BuckTypes.DOUBLE_QUOTED_STRING)) {
    PsiElement property = BuckPsiUtils.findAncestorWithType(element, BuckTypes.PROPERTY);
    if (checkPropertyName(property)) {
      text = buildBuckDependencyPath(element, project, text);
    }
  }
  return text;
}
 
Example #4
Source File: DebuggerCopyPastePreprocessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
  if (editor.getUserData(REMOVE_NEWLINES_ON_PASTE) != null) {
    return StringUtil.convertLineSeparators(text, " ");
  }
  return text;
}
 
Example #5
Source File: BuckCopyPasteProcessor.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public String preprocessOnPaste(
    Project project, PsiFile psiFile, Editor editor, String text, RawText rawText) {
  if (!(psiFile instanceof BuckFile)) {
    return text;
  }
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  final SelectionModel selectionModel = editor.getSelectionModel();

  // Pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor.
  final int selectionStart = selectionModel.getSelectionStart();
  final PsiElement element = psiFile.findElementAt(selectionStart);
  if (element == null) {
    return text;
  }

  ASTNode elementNode = element.getNode();
  // A simple test of the element type
  boolean isQuotedString =
      BuckPsiUtils.hasElementType(
          elementNode, BuckTypes.QUOTED_STRING, BuckTypes.APOSTROPHED_STRING);
  // isQuotedString will be true if the caret is under the left quote, the right quote,
  // or anywhere in between. But pasting with caret under the left quote acts differently than
  // pasting in other isQuotedString positions: Text will be inserted before the quotes, not
  // inside them
  boolean inQuotedString = false;
  if (isQuotedString) {
    inQuotedString =
        element instanceof TreeElement
            && ((TreeElement) element).getStartOffset() < selectionStart;
  }
  if (isQuotedString || BuckPsiUtils.hasElementType(elementNode, TokenType.WHITE_SPACE)) {
    if (inQuotedString) {
      // We want to impose the additional requirement that the string is currently empty. That is,
      // if you are pasting into an existing target, we don't want to process the paste text.
      String elementText = elementNode.getText().trim();
      if (!(elementText.equals("''") || elementText.equals("\"\""))) {
        return text;
      }
    }

    BuckArgument buckArgument = PsiTreeUtil.getParentOfType(element, BuckArgument.class);
    if (checkArgumentName(buckArgument)) {
      return formatPasteText(text, element, project, inQuotedString);
    }
  }
  return text;
}
 
Example #6
Source File: TextWithMarkupProcessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
  return text;
}
 
Example #7
Source File: CopyPastePreProcessor.java    From consulo with Apache License 2.0 votes vote down vote up
String preprocessOnPaste(final Project project, final PsiFile file, final Editor editor, String text, final RawText rawText);