From: bananeweizen Date: Mon, 23 Jan 2006 22:15:02 +0000 (+0000) Subject: shortened display text of variable proposal in content assist X-Git-Url: http://git.phpeclipse.com shortened display text of variable proposal in content assist --- 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 9723320..fe0e1da 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 @@ -34,7 +34,7 @@ public class DeclarationProposal extends AbstractProposal { //implements IPHPCom private final PHPIdentifierLocation fLocation; //private TemplateBuffer fTemplateBuffer; - private String fOldText; + // private String fOldText; // private final Image fImage_fun; // private final Image fImage_var; private final IRegion fRegion; @@ -50,157 +50,164 @@ public class DeclarationProposal extends AbstractProposal { //implements IPHPCom * @param image the icon of the proposal. */ public DeclarationProposal( - IProject project, - String identifierName, - PHPIdentifierLocation location, - TemplateContext context, - IRegion region, - ITextViewer viewer) { - super(viewer); - // Image image_fun, - // Image image_var) { - fProject = project; - fIdentifierName = identifierName; - fLocation = location; - fContext = context; - fRegion = region; + IProject project, + String identifierName, + PHPIdentifierLocation location, + TemplateContext context, + IRegion region, + ITextViewer viewer) { + super(viewer); + // Image image_fun, + // Image image_var) { + fProject = project; + fIdentifierName = identifierName; + fLocation = location; + fContext = context; + fRegion = region; } /* * @see ICompletionProposal#apply(IDocument) */ public void apply(IDocument document) { - try { - // if (fTemplateBuffer == null) - // fTemplateBuffer= fContext.evaluate(fTemplate); - - int start = fRegion.getOffset(); - int end = fRegion.getOffset() + fRegion.getLength(); - - 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); - // TemplatePosition[] variables= fTemplateBuffer.getVariables(); - // for (int i= 0; i != variables.length; i++) { - // TemplatePosition variable= variables[i]; - // - // if (variable.isResolved()) - // continue; - // - // int[] offsets= variable.getOffsets(); - // int length= variable.getLength(); - // - // for (int j= 0; j != offsets.length; j++) - // manager.addPosition(offsets[j] + start, length); - // } - - LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager); - 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(); - - } catch (BadLocationException e) { - PHPeclipsePlugin.log(e); - openErrorDialog(e); - - } - // catch (CoreException e) { - // handleException(e); - // } + try { + // if (fTemplateBuffer == null) + // fTemplateBuffer= fContext.evaluate(fTemplate); + + int start = fRegion.getOffset(); + int end = fRegion.getOffset() + fRegion.getLength(); + + 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); + // TemplatePosition[] variables= fTemplateBuffer.getVariables(); + // for (int i= 0; i != variables.length; i++) { + // TemplatePosition variable= variables[i]; + // + // if (variable.isResolved()) + // continue; + // + // int[] offsets= variable.getOffsets(); + // int length= variable.getLength(); + // + // for (int j= 0; j != offsets.length; j++) + // manager.addPosition(offsets[j] + start, length); + // } + + LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager); + 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(); + + } catch (BadLocationException e) { + PHPeclipsePlugin.log(e); + openErrorDialog(e); + + } + // catch (CoreException e) { + // handleException(e); + // } } /* * @see ICompletionProposal#getAdditionalProposalInfo() */ public String getAdditionalProposalInfo() { - StringBuffer hoverInfoBuffer = new StringBuffer(); + StringBuffer hoverInfoBuffer = new StringBuffer(); // 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 hoverInfoBuffer.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 hoverInfoBuffer.toString(); } /* * @see ICompletionProposal#getContextInformation() */ public IContextInformation getContextInformation() { - return null; + return null; } /* - * @see ICompletionProposal#getDisplayString() - */ - public String getDisplayString() { -// 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$ - } + * @see ICompletionProposal#getDisplayString() + */ + public String getDisplayString() { + String workspaceLocation; + if (fProject != null) { + workspaceLocation = fProject.getName().toString() + '/'; + } else { + // should never happen? + workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot() + .getLocation().toString(); + } + String filename = workspaceLocation + fLocation.getFilename(); + String usage = PHPDocUtil.getUsage(filename, fLocation); + String result = fIdentifierName + + TemplateMessages.getString("TemplateProposal.delimiter"); + if (usage.length() > 0) { + result += usage + + TemplateMessages.getString("TemplateProposal.delimiter"); + } + result += filename; + return result; + } /* * @see ICompletionProposal#getImage() */ public Image getImage() { - switch (fLocation.getType()) { - case PHPIdentifierLocation.FUNCTION : - return PHPUiImages.get(PHPUiImages.IMG_FUN); - 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); + switch (fLocation.getType()) { + case PHPIdentifierLocation.FUNCTION : + return PHPUiImages.get(PHPUiImages.IMG_FUN); + 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); } /* @@ -208,24 +215,24 @@ public class DeclarationProposal extends AbstractProposal { //implements IPHPCom */ public int getRelevance() { - if (fContext instanceof JavaContext) { - JavaContext context = (JavaContext) fContext; - switch (context.getCharacterBeforeStart()) { - // high relevance after whitespace - case ' ' : - case '\r' : - case '\n' : - case '\t' : - return 80; - case '>' : // -> - case ':' : // :: - return 85; - default : - return 0; - } - } else { - return 80; - } + if (fContext instanceof JavaContext) { + JavaContext context = (JavaContext) fContext; + switch (context.getCharacterBeforeStart()) { + // high relevance after whitespace + case ' ' : + case '\r' : + case '\n' : + case '\t' : + return 80; + case '>' : // -> + case ':' : // :: + return 85; + default : + return 0; + } + } else { + return 80; + } } } \ No newline at end of file