From: khartlage Date: Sun, 21 Sep 2003 18:01:20 +0000 (+0000) Subject: Code Completion inserts the brackets after functions now X-Git-Url: http://secure.phpeclipse.com Code Completion inserts the brackets after functions now --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java index f66e38e..147001f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java @@ -35,10 +35,10 @@ public class BuiltInProposal extends AbstractProposal { // implements IPHPComple // private final Image fImage_builtin; private final IRegion fRegion; -// private IRegion fSelectedRegion; // initialized by apply() + // private IRegion fSelectedRegion; // initialized by apply() private final String fBuiltinFunctionName; -// private final ITextViewer fViewer; + // private final ITextViewer fViewer; /** * Creates a template proposal with a template and its context. @@ -51,7 +51,7 @@ public class BuiltInProposal extends AbstractProposal { // implements IPHPComple fBuiltinFunctionName = functionName; fFunction = function; fContext = context; -// fViewer = viewer; + // fViewer = viewer; fRegion = region; } @@ -68,7 +68,7 @@ public class BuiltInProposal extends AbstractProposal { // implements IPHPComple // insert template string // String templateString = fTemplate; // fTemplateBuffer.getString(); - document.replace(start, end - start, fBuiltinFunctionName); + document.replace(start, end - start, fBuiltinFunctionName + "()"); // translate positions LinkedPositionManager manager = new LinkedPositionManager(document); @@ -87,7 +87,7 @@ public class BuiltInProposal extends AbstractProposal { // implements IPHPComple // } LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager); - editor.setFinalCaretOffset(fBuiltinFunctionName.length() + start); + editor.setFinalCaretOffset(fBuiltinFunctionName.length() + start + 1); // editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start); editor.enter(); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/DeclarationProposal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/DeclarationProposal.java index 4d95555..83b3253 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/DeclarationProposal.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/DeclarationProposal.java @@ -27,7 +27,7 @@ import org.eclipse.swt.graphics.Image; /** * A PHP identifier proposal. */ -public class DeclarationProposal extends AbstractProposal {//implements IPHPCompletionProposal { +public class DeclarationProposal extends AbstractProposal { //implements IPHPCompletionProposal { private final TemplateContext fContext; private final PHPIdentifierLocation fLocation; @@ -36,10 +36,10 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp // private final Image fImage_fun; // private final Image fImage_var; private final IRegion fRegion; -// private IRegion fSelectedRegion; // initialized by apply() + // private IRegion fSelectedRegion; // initialized by apply() - private final String fTemplate; -// private final ITextViewer fViewer; + private final String fIdentifierName; + // private final ITextViewer fViewer; /** * Creates a template proposal with a template and its context. @@ -48,20 +48,17 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp * @param image the icon of the proposal. */ public DeclarationProposal( - String template, + String identifierName, PHPIdentifierLocation location, TemplateContext context, IRegion region, ITextViewer viewer) { - super(viewer); + super(viewer); // Image image_fun, // Image image_var) { - fTemplate = template; + fIdentifierName = identifierName; fLocation = location; fContext = context; -// fViewer = viewer; - // fImage_fun = image_fun; - // fImage_var = image_var; fRegion = region; } @@ -76,9 +73,18 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp int start = fRegion.getOffset(); int end = fRegion.getOffset() + fRegion.getLength(); - // insert template string - // String templateString = fTemplate; // fTemplateBuffer.getString(); - document.replace(start, end - start, fTemplate); + switch (fLocation.getType()) { + case PHPIdentifierLocation.FUNCTION : + document.replace(start, end - start, fIdentifierName + "()"); + break; + + case PHPIdentifierLocation.METHOD : + document.replace(start, end - start, fIdentifierName + "()"); + break; + + default : + document.replace(start, end - start, fIdentifierName); + } // translate positions LinkedPositionManager manager = new LinkedPositionManager(document); @@ -97,8 +103,18 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp // } LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager); - editor.setFinalCaretOffset(fTemplate.length() + start); - // editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start); + switch (fLocation.getType()) { + case PHPIdentifierLocation.FUNCTION : + editor.setFinalCaretOffset(fIdentifierName.length() + start + 1); + break; + + case PHPIdentifierLocation.METHOD : + editor.setFinalCaretOffset(fIdentifierName.length() + start + 1); + break; + + default : + editor.setFinalCaretOffset(fIdentifierName.length() + start); + } editor.enter(); fSelectedRegion = editor.getSelectedRegion(); @@ -135,7 +151,7 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp * @see ICompletionProposal#getDisplayString() */ public String getDisplayString() { - return fTemplate + TemplateMessages.getString("TemplateProposal.delimiter") + fTemplate; // $NON-NLS-1$ //$NON-NLS-1$ + return fIdentifierName + TemplateMessages.getString("TemplateProposal.delimiter") + fIdentifierName; // $NON-NLS-1$ //$NON-NLS-1$ // return fTemplate.getName() + ObfuscatorMessages.getString("TemplateProposal.delimiter") + fTemplate.getDescription(); // $NON-NLS-1$ //$NON-NLS-1$ } @@ -146,14 +162,14 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp switch (fLocation.getType()) { case PHPIdentifierLocation.FUNCTION : return PHPUiImages.get(PHPUiImages.IMG_FUN); - case PHPIdentifierLocation.CLASS : - return PHPUiImages.get(PHPUiImages.IMG_CLASS); - case PHPIdentifierLocation.METHOD : - return PHPUiImages.get(PHPUiImages.IMG_FUN); - case PHPIdentifierLocation.DEFINE : - return PHPUiImages.get(PHPUiImages.IMG_DEFINE); - case PHPIdentifierLocation.VARIABLE : - return PHPUiImages.get(PHPUiImages.IMG_VAR); + case PHPIdentifierLocation.CLASS : + return PHPUiImages.get(PHPUiImages.IMG_CLASS); + case PHPIdentifierLocation.METHOD : + return PHPUiImages.get(PHPUiImages.IMG_FUN); + case PHPIdentifierLocation.DEFINE : + return PHPUiImages.get(PHPUiImages.IMG_DEFINE); + case PHPIdentifierLocation.VARIABLE : + return PHPUiImages.get(PHPUiImages.IMG_VAR); } return PHPUiImages.get(PHPUiImages.IMG_FUN); } @@ -181,5 +197,4 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp } } - } \ No newline at end of file