use of java.awt.datatransfer.StringSelection in project zaproxy by zaproxy.
the class ExtensionStdMenus method setClipboardContents.
private void setClipboardContents(String str) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(str), this);
}
use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.
the class LiveTemplateTree method performCopy.
@Override
public void performCopy(@NotNull DataContext dataContext) {
final Set<TemplateImpl> templates = myConfigurable.getSelectedTemplates().keySet();
TemplateSettings templateSettings = TemplateSettings.getInstance();
CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(templates, template -> JDOMUtil.writeElement(TemplateSettings.serializeTemplate(template, templateSettings.getDefaultTemplate(template), TemplateContext.getIdToType())), SystemProperties.getLineSeparator())));
}
use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.
the class CopyReferenceAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
Project project = CommonDataKeys.PROJECT.getData(dataContext);
List<PsiElement> elements = getElementsToCopy(editor, dataContext);
if (!doCopy(elements, project, editor) && editor != null && project != null) {
Document document = editor.getDocument();
PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document);
if (file != null) {
String toCopy = getFileFqn(file) + ":" + (editor.getCaretModel().getLogicalPosition().line + 1);
CopyPasteManager.getInstance().setContents(new StringSelection(toCopy));
setStatusBarText(project, toCopy + " has been copied");
}
return;
}
HighlightManager highlightManager = HighlightManager.getInstance(project);
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
if (elements.size() == 1 && editor != null && project != null) {
PsiElement element = elements.get(0);
PsiElement nameIdentifier = IdentifierUtil.getNameIdentifier(element);
if (nameIdentifier != null) {
highlightManager.addOccurrenceHighlights(editor, new PsiElement[] { nameIdentifier }, attributes, true, null);
} else {
PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
if (reference != null) {
highlightManager.addOccurrenceHighlights(editor, new PsiReference[] { reference }, attributes, true, null);
} else if (element != PsiDocumentManager.getInstance(project).getCachedPsiFile(editor.getDocument())) {
highlightManager.addOccurrenceHighlights(editor, new PsiElement[] { element }, attributes, true, null);
}
}
}
}
use of java.awt.datatransfer.StringSelection in project ACS by ACS-Community.
the class ClipboardHelper method setClipboardContents.
/**
* Place a String on the clipboard, and make this class the
* owner of the Clipboard's contents.
*/
public void setClipboardContents(String str) {
StringSelection stringSelection = new StringSelection(str);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
try {
clipboard.setContents(stringSelection, stringSelection);
} catch (IllegalStateException e) {
// This exception may be returned in some cases
// It is a temporary situation: we do nothing here
// and the user will retry again or most likely
// submit an SPR ;-)
e.printStackTrace();
}
}
use of java.awt.datatransfer.StringSelection in project kotlin by JetBrains.
the class CopyAsDiagnosticTestAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Editor editor = e.getData(CommonDataKeys.EDITOR);
PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
assert editor != null && psiFile != null;
BindingContext bindingContext = ResolutionUtils.analyzeFully((KtFile) psiFile);
List<CheckerTestUtil.ActualDiagnostic> diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile, false, null, null);
String result = CheckerTestUtil.addDiagnosticMarkersToText(psiFile, diagnostics).toString();
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(result), new ClipboardOwner() {
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
}
});
}
Aggregations