Saturday, February 20, 2010

CopyTo...Pastebin (and others) Plug-In for Eclipse

The situation

Do you hang out in IRC channels often? And do you use or other services to show the users snippets of your source code that illustrates a problem you have? Then you no longer need to switch between your Eclipse IDE, a webbrowser and the IRC chat window.

A small solution that can save time

I have finished today the first alpha version of a small Eclipse Plugin that adds a new menu and toolbar button to the Eclipse Workbench.

In its basic version it allows you to click any resource in the Package/Project Explorer and copies the content of the resource to the pastebin service of your choice. I have created some default configurations for the most used ones. The one working most stable is "". "" is experimental and "" returns invalid URLs in its JSON response. I have contacted the author of the service already. They merely serve as samples and I am sure most users will just use "". And if you choose to only install one "Target", like "" then there will be no submenu but you can directly select "Copy to" as shown below:

The targets are configurable in the preferences and are persisted in your Eclipse configuration location. That means you do not have to re-configure the targets for each workspace (a feature I would wish for a lot of Eclipse options to be the default).

You can also install the "CopyTo JDT" feature which allows you to copy Java methods or classes from the Outline view, the source editor or the Package Explorer. For "" this will also enable Java syntax highlighting. Since the whole plugin code is available at github others could contribute specialized modules for Ruby, PHP, etc.

After the selected content was sent to the target and the target returned a valid redirection URL (or JSON response, that contains a URL) there are several actions possible. The default action is the "Copy to clipboard" action which is supplied by default.

You can install additional "PasteTo" actions like for direct pasting into your favorite IRC client.
I have implemented support for Eclipse ECF (IRC) Chats (newest ECF 3.2 required) and some experimental for my favorite IRC client that comes with Miranda-IM for Windows. You can see that in action in the video below:

Of course having many actions will slow down your workflow so there will be a mechanism to select a default action and display the dialog only if you hold down the "CTRL" key. If there is only one action available, then no dialog will be displayed. And for the "Copy to clipboard" action you can disable the initial warning it gives you when the clipboard contains (probably) valuable data.

Unfortunately there is no way to get the "CopyTo" menu at a consistent place in popups and main menu. That's because some popup menus do not provide anchors or group-markers. And sometimes the group marker is below the seperator (Text editor popup). If anyone has an idea how to solve that placement problem he can say or change the source :)

Test it out

I am already using the plugin in my daily Eclipse life and if you want to give it a test run you can add the Update URL to your Eclipse Installation. Don't forget to select at least the main feature and the " target". The update manager will warn you that the features are not signed but you can safely ignore the message (if you trust my code :) You need to restart the workbench to get the configuration visible to "CopyTo". That's currently an known issue.

I would like to hear from you, especially if you have suggestions for the workflow.


  1. I've tried it out and it works very well, both for resources and the editor selection.

    I have a question about the preferences: I tried to create a new target by copying and pasting an existing entry, and then changing the target name and url from to, which is the pastebin for my Java course. After doing this, I had to targets. However, when trying it, it seemed I had actually overwritten the existing entry, since only was available in the menu. Opening the preferences revealed only one entry, the one I had entered.

    I think it makes great sense to add a variant of an existing target, where only the url need to change for it to work (since the response should be handled in the same way). I this planned or was it just wishful thinking ;-)

  2. Thanks Hallvard for trying out. The behaviour you are describing is due to a bug in the copy/paste code. What it does, it copies the entire object, including its ID. When you paste you essentially have the "same" object in the list twice. I will change the copy or paste code so that it always creates a new ID. I will update that and report back here.

  3. Philipp, this is another reason to use the selection service instead of clipboard tracking. You would have got features like copying from the outline view for free without developing specific extensions. Also, it would be much handier to have some kind of declarative UI-driven configuration of "pastebin" servics, so one won't have to develop a dedicated plugin for each of them. Just my 2c

  4. Eugene, no clipboard tracking involved here ;) The outline selection is specific to the provider of the content outline so you have to know who is providing it. Using a simple adapter one can convert from JDT models to Copyable. Check out the source code, its pretty simple.

    As for UI driven configuration: You can already do that. Just hit the the "New..." button in the preferences page. Enter whatever you like, if you know the services params. The provided sample plugins do nothing more than filling out that for you automatically. You do not need them. Furthermore you could paste this (between the dashes):
    into the preferences page of CopyTo :)

    You are welcome to try it out (or modify the source as you see fit)

  5. @Hallvard: I have fixed the paste code. You can update the plugin and test your workflow again.

  6. So was this abandoned 2 days after it was posted ? Or is it still maintained elsewhere ?

    1. Feel free to extend it, its open source :) I no longer maintain it. It was more of an exercise for me, and I provided it so others could use/learn from it.
      Do you have any particular questions?

  7. Really nothing beyond 'how to get it to work' - trying to install it on my Kepler with ADT it asks me to uninstall a long list of stuff I'm pretty sure I need, and informs me that even if I do, it won't install any of the packages I selected.

    1. Well, I cannot help with that, as I have never tried to run it under Kepler. But you can probably just load the projects into the Kepler IDE and update the dependencies quickly.