Search in sources :

Example 1 with PasteProvider

use of com.intellij.ide.PasteProvider in project intellij-community by JetBrains.

the class PasteAction method update.

public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    DataContext dataContext = event.getDataContext();
    PasteProvider provider = PlatformDataKeys.PASTE_PROVIDER.getData(dataContext);
    presentation.setEnabled(provider != null && provider.isPastePossible(dataContext));
    if (event.getPlace().equals(ActionPlaces.EDITOR_POPUP) && provider != null) {
        presentation.setVisible(presentation.isEnabled());
    } else {
        presentation.setVisible(true);
    }
}
Also used : PasteProvider(com.intellij.ide.PasteProvider)

Example 2 with PasteProvider

use of com.intellij.ide.PasteProvider in project intellij-community by JetBrains.

the class PasteAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    PasteProvider provider = PlatformDataKeys.PASTE_PROVIDER.getData(dataContext);
    if (provider != null && provider.isPasteEnabled(dataContext)) {
        provider.performPaste(dataContext);
    }
}
Also used : PasteProvider(com.intellij.ide.PasteProvider)

Example 3 with PasteProvider

use of com.intellij.ide.PasteProvider in project intellij-community by JetBrains.

the class PasteHandler method execute.

@Override
public void execute(final Editor editor, final DataContext dataContext, @Nullable final Producer<Transferable> producer) {
    final Transferable transferable = EditorModificationUtil.getContentsToPasteToEditor(producer);
    if (transferable == null)
        return;
    if (!EditorModificationUtil.checkModificationAllowed(editor))
        return;
    final Document document = editor.getDocument();
    if (!EditorModificationUtil.requestWriting(editor)) {
        return;
    }
    DataContext context = new DataContext() {

        @Override
        public Object getData(@NonNls String dataId) {
            return PasteAction.TRANSFERABLE_PROVIDER.is(dataId) ? (Producer<Transferable>) () -> transferable : dataContext.getData(dataId);
        }
    };
    final Project project = editor.getProject();
    if (project == null || editor.isColumnMode() || editor.getCaretModel().getCaretCount() > 1) {
        if (myOriginalHandler != null) {
            myOriginalHandler.execute(editor, null, context);
        }
        return;
    }
    final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
    if (file == null) {
        if (myOriginalHandler != null) {
            myOriginalHandler.execute(editor, null, context);
        }
        return;
    }
    DumbService.getInstance(project).setAlternativeResolveEnabled(true);
    document.startGuardedBlockChecking();
    try {
        for (PasteProvider provider : Extensions.getExtensions(EP_NAME)) {
            if (provider.isPasteEnabled(context)) {
                provider.performPaste(context);
                return;
            }
        }
        doPaste(editor, project, file, document, transferable);
    } catch (ReadOnlyFragmentModificationException e) {
        EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
    } finally {
        document.stopGuardedBlockChecking();
        DumbService.getInstance(project).setAlternativeResolveEnabled(false);
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) PasteProvider(com.intellij.ide.PasteProvider) Transferable(java.awt.datatransfer.Transferable) PsiFile(com.intellij.psi.PsiFile)

Aggregations

PasteProvider (com.intellij.ide.PasteProvider)3 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Project (com.intellij.openapi.project.Project)1 PsiFile (com.intellij.psi.PsiFile)1 Transferable (java.awt.datatransfer.Transferable)1 NonNls (org.jetbrains.annotations.NonNls)1