X-Git-Url: http://git.phpeclipse.com 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..76da3b3 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 @@ -14,6 +14,7 @@ import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation; +import org.eclipse.core.resources.IProject; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; @@ -27,7 +28,8 @@ 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 IProject fProject; private final TemplateContext fContext; private final PHPIdentifierLocation fLocation; @@ -36,10 +38,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 +50,19 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp * @param image the icon of the proposal. */ public DeclarationProposal( - String template, + IProject project, + String identifierName, PHPIdentifierLocation location, TemplateContext context, IRegion region, ITextViewer viewer) { - super(viewer); + super(viewer); // Image image_fun, // Image image_var) { - fTemplate = template; + fProject = project; + fIdentifierName = identifierName; fLocation = location; fContext = context; -// fViewer = viewer; - // fImage_fun = image_fun; - // fImage_var = image_var; fRegion = region; } @@ -76,9 +77,20 @@ 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.CONSTRUCTOR : + 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 +109,20 @@ 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.CONSTRUCTOR : + 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(); @@ -118,10 +142,18 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp */ public String getAdditionalProposalInfo() { StringBuffer hoverInfoBuffer = new StringBuffer(); - String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString(); +// String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString(); + String workspaceLocation; + if (fProject!=null) { + workspaceLocation = fProject.getLocation().toString()+'/'; + } else { + // should never happen? + workspaceLocation = PHPeclipsePlugin.getWorkspace() + .getRoot().getLocation().toString(); + } String filename = workspaceLocation + fLocation.getFilename(); PHPDocUtil.appendPHPDoc(hoverInfoBuffer, filename, fLocation); - return textToHTML(hoverInfoBuffer.toString()); + return hoverInfoBuffer.toString(); } /* @@ -135,8 +167,17 @@ 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 fTemplate.getName() + ObfuscatorMessages.getString("TemplateProposal.delimiter") + fTemplate.getDescription(); // $NON-NLS-1$ //$NON-NLS-1$ +// String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString(); + String workspaceLocation; + if (fProject!=null) { + workspaceLocation = fProject.getLocation().toString()+'/'; + } else { + // should never happen? + workspaceLocation = PHPeclipsePlugin.getWorkspace() + .getRoot().getLocation().toString(); + } + String filename = workspaceLocation + fLocation.getFilename(); + return fIdentifierName + TemplateMessages.getString("TemplateProposal.delimiter") + PHPDocUtil.getUsage(filename, fLocation) + TemplateMessages.getString("TemplateProposal.delimiter") + filename; // $NON-NLS-1$ //$NON-NLS-1$ } /* @@ -146,14 +187,18 @@ 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.CONSTRUCTOR : + 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.GLOBAL_VARIABLE : + return PHPUiImages.get(PHPUiImages.IMG_VAR); } return PHPUiImages.get(PHPUiImages.IMG_FUN); } @@ -172,7 +217,9 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp case '\n' : case '\t' : return 90; - + case '>' : // -> + case ':' : // :: + return 95; default : return 0; } @@ -181,5 +228,4 @@ public class DeclarationProposal extends AbstractProposal {//implements IPHPComp } } - } \ No newline at end of file