These are the default Groovy macros of the application.
Open a file in the editor (or a URL in the default Web browser)
import javax.swing.*
import java.awt.Desktop
import java.net.URL
import java.io.File
def fileName = app.getSelectedText()
if (fileName==null || fileName.length()==0) {
JOptionPane.showMessageDialog(app,
"Couldn't open the file: No selection.\n" +
"A path (or a URL) must be selected in the active editor to open a file (or a Web site).",
"Error", JOptionPane.ERROR_MESSAGE);
} else {
def isUrl = fileName.startsWith("http://");
def file = new File(fileName);
// If this is a URL, open it in a browser
if (isUrl) {
Desktop.getDesktop().browse(new URL(fileName).toURI());
}
else if (file.isFile()) {
app.openFile(file.absolutePath)
}
else {
JOptionPane.showMessageDialog(app,
"File does not exist:\n" + file.absolutePath, "Error",
JOptionPane.ERROR_MESSAGE)
}
}
Order the lines
final def removeDuplicates = false // Change to "true" if you want to delete duplicates
// Note: You'll want to consider wrapping your scripts inside calls to
// beginAtomicEdit() and endAtomicEdit(), so the actions they perform can
// be undone with a single Undo action.
textArea.beginAtomicEdit()
try {
def lines = textArea.text.split("\n")
if (removeDuplicates) {
def ts = new TreeSet()
lines.each {
ts.add(it)
}
lines = ts.toArray()
}
Arrays.sort(lines)
textArea.text = lines.join("\n")
} finally {
textArea.endAtomicEdit()
}
Order the lines (and remove duplicates)
final def removeDuplicates = true // Change to "false" if you want to keep duplicates
// Note: You'll want to consider wrapping your scripts inside calls to
// beginAtomicEdit() and endAtomicEdit(), so the actions they perform can
// be undone with a single Undo action.
textArea.beginAtomicEdit()
try {
def lines = textArea.text.split("\n")
if (removeDuplicates) {
def ts = new TreeSet()
lines.each {
ts.add(it)
}
lines = ts.toArray()
}
Arrays.sort(lines)
textArea.text = lines.join("\n")
} finally {
textArea.endAtomicEdit()
}