Search in sources :

Example 1 with GutterDraggableObject

use of com.intellij.openapi.editor.markup.GutterDraggableObject in project intellij-community by JetBrains.

the class EditorImpl method handleDrop.

static boolean handleDrop(@NotNull EditorImpl editor, @NotNull final Transferable t, int dropAction) {
    final EditorDropHandler dropHandler = editor.getDropHandler();
    if (Registry.is("debugger.click.disable.breakpoints")) {
        try {
            if (t.isDataFlavorSupported(GutterDraggableObject.flavor)) {
                Object attachedObject = t.getTransferData(GutterDraggableObject.flavor);
                if (attachedObject instanceof GutterIconRenderer) {
                    GutterDraggableObject object = ((GutterIconRenderer) attachedObject).getDraggableObject();
                    if (object != null) {
                        object.remove();
                        Point mouseLocationOnScreen = MouseInfo.getPointerInfo().getLocation();
                        JComponent editorComponent = editor.getComponent();
                        Point editorComponentLocationOnScreen = editorComponent.getLocationOnScreen();
                        IdeGlassPaneUtil.installPainter(editorComponent, new ExplosionPainter(new Point(mouseLocationOnScreen.x - editorComponentLocationOnScreen.x, mouseLocationOnScreen.y - editorComponentLocationOnScreen.y), editor.getGutterComponentEx().getDragImage((GutterIconRenderer) attachedObject)), editor.getDisposable());
                        return true;
                    }
                }
            }
        } catch (UnsupportedFlavorException | IOException e) {
            LOG.warn(e);
        }
    }
    if (dropHandler != null && dropHandler.canHandleDrop(t.getTransferDataFlavors())) {
        dropHandler.handleDrop(t, editor.getProject(), null, dropAction);
        return true;
    }
    final int caretOffset = editor.getCaretModel().getOffset();
    if (editor.myDraggedRange != null && editor.myDraggedRange.getStartOffset() <= caretOffset && caretOffset < editor.myDraggedRange.getEndOffset()) {
        return false;
    }
    if (editor.myDraggedRange != null) {
        editor.getCaretModel().moveToOffset(editor.mySavedCaretOffsetForDNDUndoHack);
    }
    CommandProcessor.getInstance().executeCommand(editor.myProject, () -> {
        try {
            editor.getSelectionModel().removeSelection();
            final int offset;
            if (editor.myDraggedRange != null) {
                editor.getCaretModel().moveToOffset(caretOffset);
                offset = caretOffset;
            } else {
                offset = editor.getCaretModel().getOffset();
            }
            if (editor.getDocument().getRangeGuard(offset, offset) != null) {
                return;
            }
            editor.putUserData(LAST_PASTED_REGION, null);
            EditorActionHandler pasteHandler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_PASTE);
            LOG.assertTrue(pasteHandler instanceof EditorTextInsertHandler);
            ((EditorTextInsertHandler) pasteHandler).execute(editor, editor.getDataContext(), () -> t);
            TextRange range = editor.getUserData(LAST_PASTED_REGION);
            if (range != null) {
                editor.getCaretModel().moveToOffset(range.getStartOffset());
                editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
            }
        } catch (Exception exception) {
            LOG.error(exception);
        }
    }, EditorBundle.message("paste.command.name"), DND_COMMAND_KEY, UndoConfirmationPolicy.DEFAULT, editor.getDocument());
    return true;
}
Also used : GutterDraggableObject(com.intellij.openapi.editor.markup.GutterDraggableObject) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) GutterDraggableObject(com.intellij.openapi.editor.markup.GutterDraggableObject) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer)

Aggregations

GutterDraggableObject (com.intellij.openapi.editor.markup.GutterDraggableObject)1 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1