content assist fix for backport
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java index 7a56061..d9f5b09 100644 --- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java +++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2008 GEBIT Gesellschaft fuer EDV-Beratung + * Copyright (c) 2002, 2009 GEBIT Gesellschaft fuer EDV-Beratung * und Informatik-Technologien mbH, * Berlin, Duesseldorf, Frankfurt (Germany) and others. * All rights reserved. This program and the accompanying materials @@ -45,35 +45,21 @@ import org.eclipse.ant.internal.ui.model.AntProjectNode; import org.eclipse.ant.internal.ui.model.IAntModelListener; import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; - -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.ShellAdapter; -import org.eclipse.swt.events.ShellEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; - +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; - -import org.eclipse.core.resources.IFile; - +import org.eclipse.debug.ui.actions.IRunToLineTarget; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jface.viewers.IPostSelectionProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; - import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IAutoEditStrategy; @@ -94,12 +80,25 @@ import org.eclipse.jface.text.source.IAnnotationModelExtension; import org.eclipse.jface.text.source.IOverviewRuler; import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.ISourceViewerExtension4; import org.eclipse.jface.text.source.IVerticalRuler; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.text.source.projection.IProjectionListener; import org.eclipse.jface.text.source.projection.ProjectionSupport; import org.eclipse.jface.text.source.projection.ProjectionViewer; - +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.IPostSelectionProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPartService; @@ -107,24 +106,19 @@ import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.ide.IDE; import org.eclipse.ui.part.IShowInTargetList; -import org.eclipse.ui.views.contentoutline.ContentOutline; -import org.eclipse.ui.views.contentoutline.IContentOutlinePage; - import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; +import org.eclipse.ui.texteditor.ContentAssistAction; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IEditorStatusLine; import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; +import org.eclipse.ui.texteditor.KeyBindingSupportForAssistant; import org.eclipse.ui.texteditor.TextOperationAction; - -import org.eclipse.ui.editors.text.TextEditor; - -import org.eclipse.debug.ui.actions.IRunToLineTarget; -import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; - -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds; +import org.eclipse.ui.views.contentoutline.ContentOutline; +import org.eclipse.ui.views.contentoutline.IContentOutlinePage; /** * The actual editor implementation for Eclipse's Ant integration. @@ -494,6 +488,11 @@ private AntModel fAntModel; + /** + * Key binding support for the content assistant. + * @since 3.4 + */ + private KeyBindingSupportForAssistant fKeyBindingSupportForAssistant; /* (non-Javadoc) * @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions() @@ -502,8 +501,18 @@ super.createActions(); ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.ant.internal.ui.editor.AntEditorMessages"); //$NON-NLS-1$ + IAction action = new ContentAssistAction(bundle, "ContentAssistProposal.", this); //$NON-NLS-1$ - IAction action= new TextOperationAction(bundle, "ContentFormat.", this, ISourceViewer.FORMAT); //$NON-NLS-1$ + ISourceViewer sourceViewer = getSourceViewer(); + if (sourceViewer instanceof ISourceViewerExtension4) { + fKeyBindingSupportForAssistant= new KeyBindingSupportForAssistant(((ISourceViewerExtension4) sourceViewer).getContentAssistantFacade()); + } + + // This action definition is associated with the accelerator Ctrl+Space + action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + setAction("ContentAssistProposal", action); //$NON-NLS-1$ + + action = new TextOperationAction(bundle, "ContentFormat.", this, ISourceViewer.FORMAT); //$NON-NLS-1$ action.setActionDefinitionId(IJavaEditorActionDefinitionIds.FORMAT); setAction("ContentFormat", action); //$NON-NLS-1$ @@ -873,7 +882,6 @@ if (node == null) { String path= model.getPath(text, region.getOffset()); if (path != null) { - path = model.getProjectNode().getProject().replaceProperties(path); return path; } @@ -1025,7 +1033,12 @@ AntModelCore.getDefault().removeAntModelListener(fAntModelListener); fAntModel= null; - + + if (fKeyBindingSupportForAssistant != null) { + fKeyBindingSupportForAssistant.dispose(); + fKeyBindingSupportForAssistant = null; + } + super.dispose(); }
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorCompletionProcessor.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorCompletionProcessor.java index d31247b..dce1741 100644 --- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorCompletionProcessor.java +++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorCompletionProcessor.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2008 GEBIT Gesellschaft fuer EDV-Beratung + * Copyright (c) 2002, 2009 GEBIT Gesellschaft fuer EDV-Beratung * und Informatik-Technologien mbH, * Berlin, Duesseldorf, Frankfurt (Germany) and others. * All rights reserved. This program and the accompanying materials @@ -12,7 +12,6 @@ * IBM Corporation - bug fixes * John-Mason P. Shackelford (john-mason.shackelford@pearson.com) - bug 49383, 56299, 59024 * Brock Janiczak (brockj_eclipse@ihug.com.au ) - bug 78028, 78030 - * Remy Chi Jian Suen - bug 277587 *******************************************************************************/ package org.eclipse.ant.internal.ui.editor; @@ -80,6 +79,7 @@ import org.eclipse.jface.text.contentassist.ContentAssistEvent; import org.eclipse.jface.text.contentassist.ICompletionListener; import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.contentassist.IContentAssistant; import org.eclipse.jface.text.contentassist.IContentAssistantExtension2; import org.eclipse.jface.text.contentassist.IContextInformation; @@ -109,7 +109,7 @@ /** * The completion processor for the Ant Editor. */ -public class AntEditorCompletionProcessor extends TemplateCompletionProcessor implements ICompletionListener { +public class AntEditorCompletionProcessor extends TemplateCompletionProcessor implements IContentAssistProcessor, ICompletionListener { private static final class ProposalComparator implements Comparator { public int compare(Object o1, Object o2) { @@ -513,7 +513,7 @@ target = (Target) itr.next(); targetName= target.getName(); if (targetName.toLowerCase().startsWith(prefix) && targetName.length() > 0) { - defaultProposals.add(new AntCompletionProposal(targetName, cursorPosition - prefix.length(), prefix.length(), targetName.length(), getTargetImage(targetName), targetName, target.getDescription(), AntCompletionProposal.TASK_PROPOSAL)); + defaultProposals.add(new AntCompletionProposal(targetName, cursorPosition - prefix.length(), prefix.length(), targetName.length(), null, targetName, target.getDescription(), AntCompletionProposal.TASK_PROPOSAL)); } } @@ -592,34 +592,13 @@ continue; } if (targetName.toLowerCase().startsWith(prefix) && targetName.length() > 0){ - ICompletionProposal proposal = new AntCompletionProposal(targetName, cursorPosition - prefix.length(), prefix.length(), targetName.length(), getTargetImage(targetName), targetName, ((Target)targets.get(targetName)).getDescription(), AntCompletionProposal.TASK_PROPOSAL); + ICompletionProposal proposal = new AntCompletionProposal(targetName, cursorPosition - prefix.length(), prefix.length(), targetName.length(), null, targetName, ((Target)targets.get(targetName)).getDescription(), AntCompletionProposal.TASK_PROPOSAL); proposals.add(proposal); index++; } } return (ICompletionProposal[])proposals.toArray(new ICompletionProposal[proposals.size()]); } - - /** - * Retrieves the representative image of a target of the given name. If the - * target cannot be found, <code>null</code> will be returned. - * - * @param targetName the target's name - * @return an image suitable for representating the target, or <code>null</code> if the target cannot be found - * @since 3.6 - */ - private Image getTargetImage(String targetName) { - AntTargetNode targetNode = antModel.getTargetNode(targetName); - if (targetNode == null) { - return null; - } else if (targetNode.isInternal()) { - return AntUIImages.getImage(IAntUIConstants.IMG_ANT_TARGET_INTERNAL); - } else if (targetNode.isDefaultTarget()) { - return AntUIImages.getImage(IAntUIConstants.IMG_ANT_DEFAULT_TARGET); - } else { - return AntUIImages.getImage(IAntUIConstants.IMG_ANT_TARGET); - } - } private ICompletionProposal[] getDependsValueProposals(IDocument document, String prefix) { List possibleDependencies = new ArrayList(); @@ -654,7 +633,7 @@ int i= 0; for (Iterator iter = possibleDependencies.iterator(); iter.hasNext(); i++) { String targetName = (String) iter.next(); - ICompletionProposal proposal = new AntCompletionProposal(targetName, cursorPosition - prefix.length(), prefix.length(), targetName.length(), getTargetImage(targetName), targetName, ((Target)targets.get(targetName)).getDescription(), AntCompletionProposal.TASK_PROPOSAL); + ICompletionProposal proposal = new AntCompletionProposal(targetName, cursorPosition - prefix.length(), prefix.length(), targetName.length(), null, targetName, ((Target)targets.get(targetName)).getDescription(), AntCompletionProposal.TASK_PROPOSAL); proposals[i]= proposal; } return proposals;