From 5808a1db3cfdc4ab02642b38d3816cc0e87c2303 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Thu, 2 Mar 2017 18:08:06 +0300 Subject: [PATCH] make an additional requirement for editor paste handler more obvious for plugin developers (to avoid exceptions similar to EA-98045) --- .../actionSystem/EditorTextInsertHandler.java | 5 ++++- .../openapi/editor/actions/PasteAction.java | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorTextInsertHandler.java b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorTextInsertHandler.java index 043701a0c097..35ccfb42da80 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorTextInsertHandler.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorTextInsertHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,9 @@ import com.intellij.util.Producer; import java.awt.datatransfer.Transferable; /** + * {@link EditorActionHandler Handlers} for {@link com.intellij.openapi.actionSystem.IdeActions#ACTION_EDITOR_PASTE EditorPaste} action + * should implement this interface (it's required for text drag-n-drop functionality in editor). + * * @author pegov */ public interface EditorTextInsertHandler { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java index 7de5d0b5e3c9..e892e72c2386 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,13 @@ package com.intellij.openapi.editor.actions; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.DataKey; +import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorCopyPasteHelper; +import com.intellij.openapi.editor.actionSystem.EditorTextInsertHandler; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.util.TextRange; import com.intellij.util.Producer; @@ -31,12 +35,22 @@ import java.awt.datatransfer.Transferable; * @since May 13, 2002 */ public class PasteAction extends TextComponentEditorAction { + private static final Logger LOG = Logger.getInstance(PasteAction.class); + public static final DataKey> TRANSFERABLE_PROVIDER = DataKey.create("PasteTransferableProvider"); public PasteAction() { super(new Handler()); } + @Override + public void update(Editor editor, Presentation presentation, DataContext dataContext) { + if (!(getHandler() instanceof EditorTextInsertHandler)) { + LOG.error("Handler for " + IdeActions.ACTION_EDITOR_PASTE + + " action should implement com.intellij.openapi.editor.actionSystem.EditorTextInsertHandler"); + } + } + private static class Handler extends BasePasteHandler { @Override public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {