X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLContextType.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLContextType.java index 4205ed6..b187c3d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLContextType.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLContextType.java @@ -4,15 +4,18 @@ */ package net.sourceforge.phpdt.internal.corext.template.php; -//import net.sourceforge.phpdt.core.ICompilationUnit; +// import net.sourceforge.phpdt.core.ICompilationUnit; import net.sourceforge.phpdt.core.ICompilationUnit; import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.templates.GlobalTemplateVariables; +import org.eclipse.jface.text.templates.TemplateException; +import org.eclipse.jface.text.templates.TemplateVariable; /** * A context type for javadoc. - */ + */ public class HTMLContextType extends CompilationUnitContextType { /** @@ -20,35 +23,57 @@ public class HTMLContextType extends CompilationUnitContextType { */ public HTMLContextType() { super("html"); //$NON-NLS-1$ - + // global -// addVariable(new GlobalVariables.Cursor()); -// addVariable(new GlobalVariables.Dollar()); -// addVariable(new GlobalVariables.Date()); -// addVariable(new GlobalVariables.Year()); -// addVariable(new GlobalVariables.Time()); -// addVariable(new GlobalVariables.User()); - - // compilation unit - /* addVariable(new File()); - addVariable(new Method()); - addVariable(new ReturnType()); - addVariable(new Arguments()); - addVariable(new Type()); - addVariable(new Package()); - addVariable(new Project());*/ + addResolver(new GlobalTemplateVariables.Cursor()); + addResolver(new GlobalTemplateVariables.WordSelection()); + addResolver(new GlobalTemplateVariables.LineSelection()); + addResolver(new GlobalTemplateVariables.Dollar()); + addResolver(new GlobalTemplateVariables.Date()); + addResolver(new GlobalTemplateVariables.Year()); + addResolver(new GlobalTemplateVariables.Time()); + addResolver(new GlobalTemplateVariables.User()); + + addResolver(new File()); } - + /* * @see ContextType#createContext() - */ - public CompilationUnitContext createContext(IDocument document, int offset, int length, ICompilationUnit compilationUnit) { - return new HTMLUnitContext(this, document, offset, length, compilationUnit); + */ + public CompilationUnitContext createContext(IDocument document, int offset, + int length, ICompilationUnit compilationUnit) { + return new HTMLUnitContext(this, document, offset, length, + compilationUnit); } - /* (non-Javadoc) - * @see net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContextType#createContext(org.eclipse.jface.text.IDocument, int, int, net.sourceforge.phpdt.core.ICompilationUnit) + + /* + * (non-Javadoc) + * + * @see net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContextType#createContext(org.eclipse.jface.text.IDocument, + * int, int, net.sourceforge.phpdt.core.ICompilationUnit) */ -// public CompilationUnitContext createContext(IDocument document, int offset, int length, ICompilationUnit compilationUnit) { -// return new JavaDocContext(this, document, offset, length, compilationUnit); -// } + // public CompilationUnitContext createContext(IDocument document, int + // offset, int length, ICompilationUnit compilationUnit) { + // return new JavaDocContext(this, document, offset, length, + // compilationUnit); + // } + /* + * (non-Javadoc) + * + * @see net.sourceforge.phpdt.internal.corext.template.ContextType#validateVariables(net.sourceforge.phpdt.internal.corext.template.TemplateVariable[]) + */ + protected void validateVariables(TemplateVariable[] variables) + throws TemplateException { + // check for multiple cursor variables + for (int i = 0; i < variables.length; i++) { + TemplateVariable var = variables[i]; + if (var.getType().equals(GlobalTemplateVariables.Cursor.NAME)) { + if (var.getOffsets().length > 1) { + throw new TemplateException( + JavaTemplateMessages + .getString("ContextType.error.multiple.cursor.variables")); //$NON-NLS-1$ + } + } + } + } }