public class CodeTemplateManager
extends java.lang.Object
All methods in this class are synchronized for thread safety, but as a
best practice, you should probably only modify the templates known to a
CodeTemplateManager on the EDT. Modifying a
CodeTemplate retrieved from a CodeTemplateManager
while not on the EDT could cause problems.
For more flexible boilerplate code insertion, consider using the TemplateCompletion class in the AutoComplete add-on library.
| Constructor and Description |
|---|
CodeTemplateManager()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addTemplate(CodeTemplate template)
Registers the specified template with this template manager.
|
CodeTemplate |
getTemplate(RSyntaxTextArea textArea)
Returns the template that should be inserted at the current caret
position, assuming the trigger character was pressed.
|
int |
getTemplateCount()
Returns the number of templates this manager knows about.
|
CodeTemplate[] |
getTemplates()
Returns the templates currently available.
|
static boolean |
isValidChar(char ch)
Returns whether the specified character is a valid character for a
CodeTemplate id. |
boolean |
removeTemplate(CodeTemplate template)
Returns the specified code template.
|
CodeTemplate |
removeTemplate(java.lang.String id)
Returns the code template with the specified id.
|
void |
replaceTemplates(CodeTemplate[] newTemplates)
Replaces the current set of available templates with the ones
specified.
|
boolean |
saveTemplates()
Saves all templates as XML files in the current template directory.
|
int |
setTemplateDirectory(java.io.File dir)
Sets the directory in which to look for templates.
|
public void addTemplate(CodeTemplate template)
template - The template to register.java.lang.IllegalArgumentException - If template is
null.removeTemplate(CodeTemplate),
removeTemplate(String)public CodeTemplate getTemplate(RSyntaxTextArea textArea)
textArea - The text area that's getting text inserted into it.null if no template should be inserted.public int getTemplateCount()
public CodeTemplate[] getTemplates()
public static final boolean isValidChar(char ch)
CodeTemplate id.ch - The character to check.public boolean removeTemplate(CodeTemplate template)
template - The template to remove.true if the template was removed, false
if the template was not in this template manager.java.lang.IllegalArgumentException - If template is
null.removeTemplate(String),
addTemplate(CodeTemplate)public CodeTemplate removeTemplate(java.lang.String id)
id - The id to check for.null if
there was no template with the specified ID.java.lang.IllegalArgumentException - If id is null.removeTemplate(CodeTemplate),
addTemplate(CodeTemplate)public void replaceTemplates(CodeTemplate[] newTemplates)
newTemplates - The new set of templates. Note that we will
be taking a shallow copy of these and sorting them.public boolean saveTemplates()
public int setTemplateDirectory(java.io.File dir)
dir - The new directory in which to look for templates.-1 if the specified directory does not exist.