The previous article saw us complete the File menu, making use of XPCOM to handle some of the more complex behaviors. This article will go on to discuss adding behavior to the two remaining menus, the Edit and Help menus.
Back to XUL: Completing the JavaScript Logic - Defining a Function (Page 2 of 6 )
Next, we need to define a function that will allow us to retrieve data from the clipboard and paste it into the document. Because you don’t need to get a selection, there is even less code than the previous function:
function pasteFromClip() {
var editor = document.getElementById('mainContent'); editor = editor.getEditor(editor.contentWindow).QueryInterface (Components.interfaces.nsIPlaintextEditor); editor.paste(1);
}
You can just get the editor into the nsIPlaintextEditor interface in the same way as before, and call the paste() method on it instead. The 1 value is just a flag for the type of text on the clipboard, in this case eEditorPlaintextMask.
The cutfunction is almost identical to the copy function, you just call the cut() method instead of the copy() method:
function cutToClip() {
var editor = document.getElementById('mainContent'); var selected = editor.contentDocument.getSelection(); editor = editor.getEditor(editor.contentWindow).QueryInterface (Components.interfaces.nsIPlaintextEditor); editor.cut(selected);