You might want to take a look at my [Insert APT Link](http://stackapps.com/questions/2405/insert-apt-link-making-it-easy-to-insert-an-apt-link-into-your-question-answ) UserScript, which demonstrates how to add a button to the toolbar and associate an action with it. It also demonstrates how to interact with the editor itself.