Eclipse: selection autocopy to clipboard

前端 未结 2 919
攒了一身酷
攒了一身酷 2021-01-14 01:55

I love an Emacs feature to copy selection to clipboard automatically. Is it possible to do the same on Eclipse?

Environment: Windows XP, Helios

相关标签:
2条回答
  • 2021-01-14 02:16

    You can try this plugin. Along with auto copy points mentioned in Eclipse show number of lines and/or file size also addressed.

    0 讨论(0)
  • 2021-01-14 02:26

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

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

    edit to answer a question: You can set up your own MouseAdapater and attach it to buttons, text fields or whateer you like. Here's an example for 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, too, you can just add MouseListenerinstead of the Adapter. The only advantage of the Adapter is, that you don't have to override the other methods of the interface.

    Since the original question was to automatically get the selection of the text of an editor: the way to get the selection from an editor is explained here.

    0 讨论(0)
提交回复
热议问题