Eclipse: Select Auto Copy to Clipboard

I like the Emacs feature to automatically copy the selection to the clipboard. Can I do the same on Eclipse?

Environment: Windows XP, Helios

+4
source share
2 answers

To copy a string from Eclipse to the clipboard, you can use

void copyToClipboard (String toClipboard, Display display){ String toClipboard = "my String"; Clipboard clipboard = new Clipboard(display); TextTransfer [] textTransfer = {TextTransfer.getInstance()}; clipboard.setContents(new Object [] {toClipboard}, textTransfer); clipboard.dispose(); } 

You can then call this method from the MouseAdapter or KeyAdapter , depending on where you want to get your string from. In your case, it could be a MouseAdapter that listens for doubleclicks, gets the current cursor position in the text, marks the word, and then adds String to the clipboard.

edit to answer the question: you can customize your own MouseAdapater and attach it to buttons, text fields, or you like. Here is an example of a button:

  Button btnGo1 = new Button(parent, SWT.NONE); btnGo1.setText("Go"); btnGo1.addMouseListener(new MouseAdapter() { @Override public void mouseDoubleClick(MouseEvent e) { //do what you want to do in here } }); 

If you want to implement mouseUp and mouseDown events, you can simply add MouseListener instead of an adapter. The only advantage of the adapter is that you do not need to override other interface methods.

Since the original question was to automatically get the editorโ€™s text selection: the way to get the selection from the editor is explained here .

+1
source

You can try plugin . Along with the autocopy dots specified in Eclipse, the number of lines and / or file size also addressed are shown.

0
source

All Articles