/* * Menu: Examples > Uppercase Text * Script-Path: /website.howardism/datafiles/howardism/Technical/Eclipse/uppercase_text.gm * Kudos: Howard Abrams (http://www.howardism.org) * License: EPL 1.0 * Job: UIJob * Exec-Mode: Foreground * DOM: http://groovy-monkey.sourceforge.net/update/plugins/net.sf.groovyMonkey.dom */ // Oh sure, you could just do a Control-Shift-X to uppercase // the selected text (and Control-Shift-Y to lowercase it), // but this is an example of altering text in Eclipse using // the Groovy Monkey def editor = window.activePage.activeEditor def source = editor.sourceViewer.document // To get all of the text: source.get() def range = window.activePage.selection // If no text is actually selected, range.length=0, // but range.offset is the cursor position def text = source.get( range.offset, range.length ) if ( text =~ /^[A-Z]/ ) text = text.toLowerCase() else text = text.toUpperCase() // The replace method will replace the selected text... source.replace(range.offset, range.length, text );