Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ease-dev] Code example to comment out a line in an editor (SOLVED)

Here is one solution to running all this code on the UI thread that now seems obvious in retrospect as a way to have the least JavaScript code in text. There may still be a better way to do this, but I just put the code to run on the UI thread in a function and then just called the function on the UI thread. Here is the revised example:

// ********************************************************************************
// name : Comment Out Line EASE Test Improved
// popup : enableFor(java.lang.Object)
// ********************************************************************************
// From: http://codeandme.blogspot.com/2014/08/ease-eclipse-advanced-scripting.html
loadModule('/System/UI');

// Modified from: http://stackoverflow.com/questions/1233102/replace-selected-code-from-eclipse-editor-thru-plugin-command
function commentOutSelection() {
    var editor = getActiveEditor(); 
    var dp = editor.getDocumentProvider(); 
    var doc = dp.getDocument(editor.getEditorInput());
    var textSel = editor.getSelectionProvider().getSelection();
    var newText = '/*' + textSel.getText() + '*/';
    doc.replace(textSel.getOffset(), textSel.getLength(), newText);
}

executeUI("commentOutSelection()");
// End of sample code

--Paul Fernhout
http://www.pdfernhout.net/
====
The biggest challenge of the 21st century is the irony of technologies of abundance in the hands of those still thinking in terms of scarcity. 


Back to the top