@Override public boolean canImport(@Nonnull JComponent comp, @Nonnull DataFlavor[] transferFlavors) { Editor editor = getEditor(comp); final EditorDropHandler dropHandler = ((EditorImpl)editor).getDropHandler(); if (dropHandler != null && dropHandler.canHandleDrop(transferFlavors)) { return true; } //should be used a better representation class if (Registry.is("debugger.click.disable.breakpoints") && ArrayUtil.contains(GutterDraggableObject.flavor, transferFlavors)) { return true; } if (editor.isViewer()) return false; int offset = editor.getCaretModel().getOffset(); if (editor.getDocument().getRangeGuard(offset, offset) != null) return false; return ArrayUtil.contains(DataFlavor.stringFlavor, transferFlavors); }
@Nullable protected GutterDraggableObject createBreakpointDraggableObject() { return null; }
@Override public GutterDraggableObject getDraggableObject() { return createBreakpointDraggableObject(); }
static boolean handleDrop(@Nonnull EditorImpl editor, @Nonnull 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, String.valueOf(pasteHandler)); ((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; }