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);
}
}
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);
}
}
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);
}
}
Aggregations