From 0d5859173ed68bed1ffa9350473056d165a58f98 Mon Sep 17 00:00:00 2001 From: axelcl Date: Thu, 18 Aug 2005 21:10:28 +0000 Subject: [PATCH] Improved ${cursor} handling in HTML and TPL (smarty) files --- .../corext/template/php/HTMLContextType.java | 41 +++++++++++++------- 1 files changed, 27 insertions(+), 14 deletions(-) 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..a5ee3d4 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 @@ -7,8 +7,12 @@ package net.sourceforge.phpdt.internal.corext.template.php; //import net.sourceforge.phpdt.core.ICompilationUnit; import net.sourceforge.phpdt.core.ICompilationUnit; +import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType.File; 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. @@ -22,21 +26,16 @@ public class HTMLContextType extends CompilationUnitContextType { 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()); + 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()); - // 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 File()); } /* @@ -51,4 +50,18 @@ public class HTMLContextType extends CompilationUnitContextType { // 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$ + } + } + } + } } -- 1.7.1