X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/contentassist/TemplateProposal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/contentassist/TemplateProposal.java index 4ca7d17..57e4b4a 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/contentassist/TemplateProposal.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/contentassist/TemplateProposal.java @@ -1,10 +1,10 @@ /******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials + * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -54,7 +54,6 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.texteditor.link.EditorLinkedModeUI; - /** * A template proposal. */ @@ -68,27 +67,27 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp private IRegion fSelectedRegion; // initialized by apply() private String fDisplayString; - + /** * Creates a template proposal with a template and its context. - * + * * @param template the template * @param context the context in which the template was requested * @param region the region this proposal applies to * @param image the icon of the proposal - */ + */ public TemplateProposal(Template template, TemplateContext context, IRegion region, Image image) { Assert.isNotNull(template); Assert.isNotNull(context); Assert.isNotNull(region); - + fTemplate= template; fContext= context; fImage= image; fRegion= region; - + fDisplayString= null; - + if (context instanceof JavaContext) { switch (((JavaContext) context).getCharacterBeforeStart()) { // high relevance after whitespace @@ -102,8 +101,8 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp fRelevance= 0; } } else { - fRelevance= 90; - } + fRelevance= 90; + } } /* @@ -112,14 +111,14 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp public final void apply(IDocument document) { // not called anymore } - + /* * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int) */ public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { try { - + fContext.setReadOnly(false); TemplateBuffer templateBuffer; try { @@ -128,34 +127,34 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp fSelectedRegion= fRegion; return; } - + int start= getReplaceOffset(); int end= getReplaceEndOffset(); end= Math.max(end, offset); - + // insert template string IDocument document= viewer.getDocument(); - String templateString= templateBuffer.getString(); - document.replace(start, end - start, templateString); - + String templateString= templateBuffer.getString(); + document.replace(start, end - start, templateString); + // translate positions LinkedModeModel model= new LinkedModeModel(); TemplateVariable[] variables= templateBuffer.getVariables(); - + MultiVariableGuess guess= fContext instanceof CompilationUnitContext ? ((CompilationUnitContext) fContext).getMultiVariableGuess() : null; - + boolean hasPositions= false; for (int i= 0; i != variables.length; i++) { TemplateVariable variable= variables[i]; if (variable.isUnambiguous()) continue; - + LinkedPositionGroup group= new LinkedPositionGroup(); - + int[] offsets= variable.getOffsets(); int length= variable.getLength(); - + LinkedPosition first; if (guess != null && variable instanceof MultiVariable) { first= new VariablePosition(document, offsets[0] + start, length, guess, (MultiVariable) variable); @@ -169,54 +168,54 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp document.addPosition(getCategory(), pos); proposals[j]= new PositionBasedCompletionProposal(values[j], pos, length); } - + if (proposals.length > 1) first= new ProposalPosition(document, offsets[0] + start, length, proposals); else first= new LinkedPosition(document, offsets[0] + start, length); } - + for (int j= 0; j != offsets.length; j++) if (j == 0) group.addPosition(first); else group.addPosition(new LinkedPosition(document, offsets[j] + start, length)); - + model.addGroup(group); hasPositions= true; } - + if (hasPositions) { model.forceInstall(); PHPEditor editor= getJavaEditor(); if (editor != null) { model.addLinkingListener(new EditorHighlightingSynchronizer(editor)); } - + LinkedModeUI ui= new EditorLinkedModeUI(model, viewer); ui.setExitPosition(viewer, getCaretOffset(templateBuffer) + start, 0, Integer.MAX_VALUE); ui.enter(); - + fSelectedRegion= ui.getSelectedRegion(); } else fSelectedRegion= new Region(getCaretOffset(templateBuffer) + start, 0); - + } catch (BadLocationException e) { PHPeclipsePlugin.log(e); - openErrorDialog(viewer.getTextWidget().getShell(), e); + openErrorDialog(viewer.getTextWidget().getShell(), e); fSelectedRegion= fRegion; } catch (BadPositionCategoryException e) { PHPeclipsePlugin.log(e); - openErrorDialog(viewer.getTextWidget().getShell(), e); + openErrorDialog(viewer.getTextWidget().getShell(), e); fSelectedRegion= fRegion; } - } - + } + /** - * Returns the currently active java editor, or null if it + * Returns the currently active java editor, or null if it * cannot be determined. - * + * * @return the currently active java editor, or null */ private PHPEditor getJavaEditor() { @@ -230,7 +229,7 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp /** * Returns the offset of the range in the document that will be replaced by * applying this template. - * + * * @return the offset of the range in the document that will be replaced by * applying this template */ @@ -248,7 +247,7 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp /** * Returns the end offset of the range in the document that will be replaced * by applying this template. - * + * * @return the end offset of the range in the document that will be replaced * by applying this template */ @@ -268,7 +267,7 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp document.addPositionCategory(getCategory()); final InclusivePositionUpdater updater= new InclusivePositionUpdater(getCategory()); document.addPositionUpdater(updater); - + model.addLinkingListener(new ILinkedModeListener() { /* @@ -294,7 +293,7 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp } private int getCaretOffset(TemplateBuffer buffer) { - + TemplateVariable[] variables= buffer.getVariables(); for (int i= 0; i != variables.length; i++) { TemplateVariable variable= variables[i]; @@ -304,7 +303,7 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp return buffer.getString().length(); } - + /* * @see ICompletionProposal#getSelection(IDocument) */ @@ -342,10 +341,10 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp } return fDisplayString; } - + public void setDisplayString(String displayString) { fDisplayString= displayString; - } + } /* * @see ICompletionProposal#getImage() @@ -379,7 +378,7 @@ public class TemplateProposal implements IPHPCompletionProposal, ICompletionProp public void setRelevance(int relevance) { fRelevance= relevance; } - + public Template getTemplate() { return fTemplate; }