com.intellij.openapi.ide.CopyPasteManager Java Examples

The following examples show how to use com.intellij.openapi.ide.CopyPasteManager. 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: DeleteSelectionHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredWriteAction
@Override
public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) {
  if (caret == null ? editor.getSelectionModel().hasSelection(true) : caret.hasSelection()) {
    EditorUIUtil.hideCursorInEditor(editor);
    CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP);
    CopyPasteManager.getInstance().stopKillRings();
    CaretAction action = c -> EditorModificationUtil.deleteSelectedText(editor);
    if (caret == null) {
      editor.getCaretModel().runForEachCaret(action);
    }
    else {
      action.perform(caret);
    }
  }
  else {
    myOriginalHandler.execute(editor, caret, dataContext);
  }
}
 
Example #2
Source File: DeleteToWordEndAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredWriteAction
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
  CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP);
  CopyPasteManager.getInstance().stopKillRings();

  int lineNumber = editor.getCaretModel().getLogicalPosition().line;
  if (editor.isColumnMode() && editor.getCaretModel().supportsMultipleCarets()
      && editor.getCaretModel().getOffset() == editor.getDocument().getLineEndOffset(lineNumber)) {
    return;
  }

  boolean camelMode = editor.getSettings().isCamelWords();
  if (myNegateCamelMode) {
    camelMode = !camelMode;
  }
  deleteToWordEnd(editor, camelMode);
}
 
Example #3
Source File: DeleteInColumnModeHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredWriteAction
@Override
public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) {
  if (editor.isColumnMode() && caret == null && editor.getCaretModel().getCaretCount() > 1) {
    EditorUIUtil.hideCursorInEditor(editor);
    CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP);
    CopyPasteManager.getInstance().stopKillRings();

    editor.getCaretModel().runForEachCaret(c -> {
      int offset = c.getOffset();
      int lineEndOffset = DocumentUtil.getLineEndOffset(offset, editor.getDocument());
      if (offset < lineEndOffset) myOriginalHandler.execute(editor, c, dataContext);
    });
  }
  else {
    myOriginalHandler.execute(editor, caret, dataContext);
  }
}
 
Example #4
Source File: DesktopCaretImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
CaretEvent moveToLogicalPosition(@Nonnull LogicalPosition pos, boolean locateBeforeSoftWrap, @Nullable StringBuilder debugBuffer, boolean adjustForInlays, boolean fireListeners) {
  if (mySkipChangeRequests) {
    return null;
  }
  if (myReportCaretMoves) {
    LOG.error("Unexpected caret move request");
  }
  if (!myEditor.isStickySelection() && !myEditor.getDocument().isInEventsHandling() && !pos.equals(myLogicalCaret)) {
    CopyPasteManager.getInstance().stopKillRings();
  }

  myReportCaretMoves = true;
  try {
    return doMoveToLogicalPosition(pos, locateBeforeSoftWrap, debugBuffer, adjustForInlays, fireListeners);
  }
  finally {
    myReportCaretMoves = false;
  }
}
 
Example #5
Source File: PasteReferenceProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #6
Source File: CopyReferenceAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean doCopy(List<PsiElement> elements, @Nullable final Project project, @Nullable Editor editor) {
  if (elements.isEmpty()) return false;

  List<String> fqns = ContainerUtil.newArrayList();
  for (PsiElement element : elements) {
    String fqn = elementToFqn(element, editor);
    if (fqn == null) return false;

    fqns.add(fqn);
  }

  String toCopy = StringUtil.join(fqns, "\n");

  CopyPasteManager.getInstance().setContents(new MyTransferable(toCopy));

  setStatusBarText(project, IdeBundle.message("message.reference.to.fqn.has.been.copied", toCopy));
  return true;
}
 
Example #7
Source File: UndoManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void undoOrRedo(final FileEditor editor, final boolean isUndo) {
  myCurrentOperationState = isUndo ? OperationState.UNDO : OperationState.REDO;

  final RuntimeException[] exception = new RuntimeException[1];
  Runnable executeUndoOrRedoAction = () -> {
    try {
      if (myProject != null) {
        PsiDocumentManager.getInstance(myProject).commitAllDocuments();
      }
      CopyPasteManager.getInstance().stopKillRings();
      myMerger.undoOrRedo(editor, isUndo);
    }
    catch (RuntimeException ex) {
      exception[0] = ex;
    }
    finally {
      myCurrentOperationState = OperationState.NONE;
    }
  };

  String name = getUndoOrRedoActionNameAndDescription(editor, isUndoInProgress()).second;
  CommandProcessor.getInstance()
          .executeCommand(myProject, executeUndoOrRedoAction, name, null, myMerger.getUndoConfirmationPolicy());
  if (exception[0] != null) throw exception[0];
}
 
Example #8
Source File: ProjectListBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ProjectListBuilder(final Project project,
                          final CommanderPanel panel,
                          final AbstractTreeStructure treeStructure,
                          final Comparator comparator,
                          final boolean showRoot) {
  super(project, panel.getList(), panel.getModel(), treeStructure, comparator, showRoot);

  myList.setCellRenderer(new ColoredCommanderRenderer(panel));
  myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, myProject);

  myPsiTreeChangeListener = new MyPsiTreeChangeListener();
  PsiManager.getInstance(myProject).addPsiTreeChangeListener(myPsiTreeChangeListener);
  myFileStatusListener = new MyFileStatusListener();
  FileStatusManager.getInstance(myProject).addFileStatusListener(myFileStatusListener);
  myCopyPasteListener = new MyCopyPasteListener();
  CopyPasteManager.getInstance().addContentChangedListener(myCopyPasteListener);
  buildRoot();
}
 
Example #9
Source File: PsiViewerDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected Action[] createActions() {
  AbstractAction copyPsi = new AbstractAction("Cop&y PSI") {
    @Override
    public void actionPerformed(ActionEvent e) {
      PsiElement element = parseText(myEditor.getDocument().getText());
      List<PsiElement> allToParse = new ArrayList<PsiElement>();
      if (element instanceof PsiFile) {
        allToParse.addAll(((PsiFile)element).getViewProvider().getAllFiles());
      }
      else if (element != null) {
        allToParse.add(element);
      }
      String data = "";
      for (PsiElement psiElement : allToParse) {
        data += DebugUtil.psiToString(psiElement, !myShowWhiteSpacesBox.isSelected(), true);
      }
      CopyPasteManager.getInstance().setContents(new StringSelection(data));
    }
  };
  return ArrayUtil.mergeArrays(new Action[]{copyPsi}, super.createActions());
}
 
Example #10
Source File: ChangesBrowserNodeCopyProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void performCopy(@Nonnull DataContext dataContext) {
  List<TreePath> paths = ContainerUtil.sorted(Arrays.asList(ObjectUtils.assertNotNull(myTree.getSelectionPaths())),
                                              TreeUtil.getDisplayOrderComparator(myTree));
  CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(paths, new Function<TreePath, String>() {
    @Override
    public String fun(TreePath path) {
      Object node = path.getLastPathComponent();
      if (node instanceof ChangesBrowserNode) {
        return ((ChangesBrowserNode)node).getTextPresentation();
      }
      else {
        return node.toString();
      }
    }
  }, "\n")));
}
 
Example #11
Source File: CopyRevisionNumberAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  VcsRevisionNumber revision = e.getData(VcsDataKeys.VCS_REVISION_NUMBER);
  if (revision == null) {
    VcsFileRevision fileRevision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
    if (fileRevision != null) {
      revision = fileRevision.getRevisionNumber();
    }
  }
  if (revision == null) {
    return;
  }

  String rev = revision instanceof ShortVcsRevisionNumber ? ((ShortVcsRevisionNumber)revision).toShortString() : revision.asString();
  CopyPasteManager.getInstance().setContents(new StringSelection(rev));
}
 
Example #12
Source File: CopyRevisionNumberFromAnnotateAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  if (myLineNumber < 0) return;
  final VcsRevisionNumber revisionNumber = myAnnotation.getLineRevisionNumber(myLineNumber);
  if (revisionNumber != null) {
    final String revision = revisionNumber.asString();
    CopyPasteManager.getInstance().setContents(new TextTransferable(revision));
  }
}
 
Example #13
Source File: Copy.java    From sourcegraph-jetbrains with Apache License 2.0 5 votes vote down vote up
@Override
void handleFileUri(String uri) {
    // Copy file uri to clipboard
    CopyPasteManager.getInstance().setContents(new StringSelection(uri));

    // Display bubble
    Notification notification = new Notification("Sourcegraph", "Sourcegraph",
            "File URL copied to clipboard.", NotificationType.INFORMATION);
    Notifications.Bus.notify(notification);
}
 
Example #14
Source File: FileListPasteProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void performPaste(@Nonnull DataContext dataContext) {
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  final IdeView ideView = dataContext.getData(LangDataKeys.IDE_VIEW);
  if (project == null || ideView == null) return;

  if (!FileCopyPasteUtil.isFileListFlavorAvailable()) return;

  final Transferable contents = CopyPasteManager.getInstance().getContents();
  if (contents == null) return;
  final List<File> fileList = FileCopyPasteUtil.getFileList(contents);
  if (fileList == null) return;

  final List<PsiElement> elements = new ArrayList<PsiElement>();
  for (File file : fileList) {
    final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
    if (vFile != null) {
      final PsiManager instance = PsiManager.getInstance(project);
      PsiFileSystemItem item = vFile.isDirectory() ? instance.findDirectory(vFile) : instance.findFile(vFile);
      if (item != null) {
        elements.add(item);
      }
    }
  }

  if (elements.size() > 0) {
    final PsiDirectory dir = ideView.getOrChooseDirectory();
    if (dir != null) {
      final boolean move = LinuxDragAndDropSupport.isMoveOperation(contents);
      if (move) {
        new MoveFilesOrDirectoriesHandler().doMove(PsiUtilCore.toPsiElementArray(elements), dir);
      }
      else {
        new CopyFilesOrDirectoriesHandler().doCopy(PsiUtilCore.toPsiElementArray(elements), dir);
      }
    }
  }
}
 
Example #15
Source File: ScopeTreeViewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  Font font = UIUtil.getTreeFont();
  setFont(font.deriveFont(font.getSize() + JBUI.scale(1f)));

  if (value instanceof PackageDependenciesNode) {
    PackageDependenciesNode node = (PackageDependenciesNode)value;
    try {
      setIcon(node.getIcon());
    }
    catch (IndexNotReadyException ignore) {
    }
    final SimpleTextAttributes regularAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    TextAttributes textAttributes = regularAttributes.toTextAttributes();
    if (node instanceof BasePsiNode && ((BasePsiNode)node).isDeprecated()) {
      textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES).clone();
    }
    final PsiElement psiElement = node.getPsiElement();
    textAttributes.setForegroundColor(CopyPasteManager.getInstance().isCutElement(psiElement) ? CopyPasteManager.CUT_COLOR : node.getColor());
    append(node.toString(), SimpleTextAttributes.fromTextAttributes(textAttributes));

    String oldToString = toString();
    if (!myProject.isDisposed()) {
      for (ProjectViewNodeDecorator decorator : Extensions.getExtensions(ProjectViewNodeDecorator.EP_NAME, myProject)) {
        decorator.decorate(node, this);
      }
    }
    if (toString().equals(oldToString)) {   // nothing was decorated
      final String locationString = node.getComment();
      if (locationString != null && locationString.length() > 0) {
        append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
      }
    }
  }
}
 
Example #16
Source File: PsiCopyPasteManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public PsiCopyPasteManager(Application application, CopyPasteManager copyPasteManager) {
  myCopyPasteManager = (CopyPasteManagerEx) copyPasteManager;
  application.getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
    @Override
    public void projectClosing(@Nonnull Project project) {
      if (myRecentData != null && myRecentData.getProject() == project) {
        myRecentData = null;
      }
    }
  });
}
 
Example #17
Source File: SmartElementDescriptor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public boolean update() {
  PsiElement element = mySmartPointer.getElement();
  if (element == null) return true;
  int flags = Iconable.ICON_FLAG_VISIBILITY;
  if (isMarkReadOnly()){
    flags |= Iconable.ICON_FLAG_READ_STATUS;
  }
  consulo.ui.image.Image icon = null;
  try {
    icon = IconDescriptorUpdaters.getIcon(element, flags);
  }
  catch (IndexNotReadyException ignored) {
  }
  Color color = null;

  if (isMarkModified() ){
    VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
    if (virtualFile != null) {
      color = FileStatusManager.getInstance(myProject).getStatus(virtualFile).getColor();
    }
  }
  if (CopyPasteManager.getInstance().isCutElement(element)) {
    color = CopyPasteManager.CUT_COLOR;
  }

  boolean changes = !Comparing.equal(icon, getIcon()) || !Comparing.equal(color, myColor);
  setIcon(icon);
  myColor = color;
  return changes;
}
 
Example #18
Source File: ProjectTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ProjectTreeBuilder(@Nonnull Project project,
                          @Nonnull JTree tree,
                          @Nonnull DefaultTreeModel treeModel,
                          @Nullable Comparator<NodeDescriptor> comparator,
                          @Nonnull ProjectAbstractTreeStructureBase treeStructure) {
  super(project, tree, treeModel, treeStructure, comparator);

  final MessageBusConnection connection = project.getMessageBus().connect(this);

  connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
    @Override
    public void rootsChanged(ModuleRootEvent event) {
      queueUpdate();
    }
  });

  connection.subscribe(BookmarksListener.TOPIC, new MyBookmarksListener());

  PsiManager.getInstance(project).addPsiTreeChangeListener(createPsiTreeChangeListener(project), this);
  FileStatusManager.getInstance(project).addFileStatusListener(new MyFileStatusListener(), this);
  CopyPasteManager.getInstance().addContentChangedListener(new CopyPasteUtil.DefaultCopyPasteListener(getUpdater()), this);

  connection.subscribe(ProblemListener.TOPIC, new MyProblemListener());

  setCanYieldUpdate(true);

  initRootNode();
}
 
Example #19
Source File: FocusTracesDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Action getCopyStackTraceAction() {
  return new AbstractAction("&Copy stacktrace") {
    @Override
    public void actionPerformed(ActionEvent e) {
      CopyPasteManager.getInstance().setContents(new StringSelection(myStacktrace.getText()));
    }
  };
}
 
Example #20
Source File: CopyQuickDocAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  String selected = e.getData(DocumentationManager.SELECTED_QUICK_DOC_TEXT);
  if (selected == null || selected.isEmpty()) {
    return;
  }

  CopyPasteManager.getInstance().setContents(new StringSelection(selected));
}
 
Example #21
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(@Nonnull final ConsoleViewImpl consoleView, @Nonnull final DataContext context) {
  String text = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
  if (text == null) return;
  Editor editor = consoleView.myEditor;
  consoleView.type(editor, text);
}
 
Example #22
Source File: CopyReferenceAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  Editor editor = dataContext.getData(CommonDataKeys.EDITOR);
  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  List<PsiElement> elements = getElementsToCopy(editor, dataContext);

  if (!doCopy(elements, project, editor) && editor != null && project != null) {
    Document document = editor.getDocument();
    PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document);
    if (file != null) {
      String toCopy = getFileFqn(file) + ":" + (editor.getCaretModel().getLogicalPosition().line + 1);
      CopyPasteManager.getInstance().setContents(new StringSelection(toCopy));
      setStatusBarText(project, toCopy + " has been copied");
    }
    return;
  }

  HighlightManager highlightManager = HighlightManager.getInstance(project);
  EditorColorsManager manager = EditorColorsManager.getInstance();
  TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
  if (elements.size() == 1 && editor != null && project != null) {
    PsiElement element = elements.get(0);
    PsiElement nameIdentifier = IdentifierUtil.getNameIdentifier(element);
    if (nameIdentifier != null) {
      highlightManager.addOccurrenceHighlights(editor, new PsiElement[]{nameIdentifier}, attributes, true, null);
    } else {
      PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
      if (reference != null) {
        highlightManager.addOccurrenceHighlights(editor, new PsiReference[]{reference}, attributes, true, null);
      } else if (element != PsiDocumentManager.getInstance(project).getCachedPsiFile(editor.getDocument())) {
        highlightManager.addOccurrenceHighlights(editor, new PsiElement[]{element}, attributes, true, null);
      }
    }
  }
}
 
Example #23
Source File: SearchWebAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  CopyProvider provider = dataContext.getData(PlatformDataKeys.COPY_PROVIDER);
  if (provider == null) {
    return;
  }
  provider.performCopy(dataContext);
  String content = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
  if (StringUtil.isNotEmpty(content)) {
    WebSearchEngine engine = myWebSearchOptions.getEngine();
    BrowserUtil.browse(BundleBase.format(engine.getUrlTemplate(), URLUtil.encodeURIComponent(content)));
  }
}
 
Example #24
Source File: NewErrorTreeViewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void performCopy(@Nonnull DataContext dataContext) {
  final ErrorTreeNodeDescriptor descriptor = getSelectedNodeDescriptor();
  if (descriptor != null) {
    final String[] lines = descriptor.getElement().getText();
    CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(lines, "\n")));
  }
}
 
Example #25
Source File: KillRingUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Copies target region from the given offset to the kill ring, i.e. combines it with the previously
 * copied/cut adjacent text if necessary and puts to the clipboard.
 *
 * @param editor      target editor
 * @param startOffset start offset of the target region within the given editor
 * @param endOffset   end offset of the target region within the given editor
 * @param cut         flag that identifies if target text region will be cut from the given editor
 */
public static void copyToKillRing(@Nonnull final Editor editor, int startOffset, int endOffset, boolean cut) {
  Document document = editor.getDocument();
  String s = document.getCharsSequence().subSequence(startOffset, endOffset).toString();
  s = StringUtil.convertLineSeparators(s);
  CopyPasteManager.getInstance().setContents(new KillRingTransferable(s, document, startOffset, endOffset, cut));
  if (editor instanceof EditorEx) {
    EditorEx ex = (EditorEx)editor;
    if (ex.isStickySelection()) {
      ex.setStickySelection(false);
    }
  }
}
 
Example #26
Source File: ListPopupImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void replacePasteAction() {
  if (myStep.isSpeedSearchEnabled()) {
    getList().getActionMap().put(TransferHandler.getPasteAction().getValue(Action.NAME), new AbstractAction() {
      @Override
      public void actionPerformed(ActionEvent e) {
        getSpeedSearch().type(CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor));
        getSpeedSearch().update();
      }
    });
  }
}
 
Example #27
Source File: EditorCopyPasteHelperImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public TextRange[] pasteFromClipboard(@Nonnull Editor editor) {
  CopyPasteManager manager = CopyPasteManager.getInstance();
  if (manager.areDataFlavorsAvailable(DataFlavor.stringFlavor)) {
    Transferable clipboardContents = manager.getContents();
    if (clipboardContents != null) {
      return pasteTransferable(editor, clipboardContents);
    }
  }
  return null;
}
 
Example #28
Source File: EditorCopyPasteHelperImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void copySelectionToClipboard(@Nonnull Editor editor) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  List<TextBlockTransferableData> extraData = new ArrayList<TextBlockTransferableData>();
  String s = editor.getCaretModel().supportsMultipleCarets() ? getSelectedTextForClipboard(editor, extraData)
                                                             : editor.getSelectionModel().getSelectedText();
  if (s == null) return;

  s = TextBlockTransferable.convertLineSeparators(s, "\n", extraData);
  Transferable contents = editor.getCaretModel().supportsMultipleCarets() ? new TextBlockTransferable(s, extraData, null) : new StringSelection(s);
  CopyPasteManager.getInstance().setContents(contents);
}
 
Example #29
Source File: DeleteAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredWriteAction
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
  EditorUIUtil.hideCursorInEditor(editor);
  CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP);
  CopyPasteManager.getInstance().stopKillRings();
  if (editor.getInlayModel().hasInlineElementAt(editor.getCaretModel().getVisualPosition())) {
    editor.getCaretModel().moveCaretRelatively(1, 0, false, false, EditorUtil.isCurrentCaretPrimary(editor));
  }
  else {
    deleteCharAtCaret(editor);
  }
}
 
Example #30
Source File: AboutNewDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public Couple<JComponent> createSplitterComponents(JPanel rootPanel) {
  JTextArea area = new JTextArea();
  area.setEditable(false);
  area.setText(buildAboutInfo());

  setOKButtonText(CommonBundle.getCloseButtonText());

  JButton okButton = createJButtonForAction(getOKAction());

  JPanel eastPanel = new JPanel(new VerticalFlowLayout());
  eastPanel.add(okButton);

  JButton copyToClipboard = new JButton("Copy to clipboard");
  copyToClipboard.addActionListener(e -> {
    CopyPasteManager.getInstance().setContents(new TextTransferable(area.getText(), area.getText()));

    copyToClipboard.setEnabled(false);

    JobScheduler.getScheduler().schedule(() -> UIUtil.invokeLaterIfNeeded(() -> copyToClipboard.setEnabled(true)), 2, TimeUnit.SECONDS);
  });

  eastPanel.add(copyToClipboard);

  return Couple.of(ScrollPaneFactory.createScrollPane(area, true), eastPanel);
}