diff options
author | Dani Megert | 2003-10-03 15:45:45 +0000 |
---|---|---|
committer | Dani Megert | 2003-10-03 15:45:45 +0000 |
commit | 2c06991068e3748cc3d2bc3b9e6980a83eaf50a7 (patch) | |
tree | 83c1fb37c9352e3a7ad4755f4b58be6bca52a1d0 /org.eclipse.jface.text/src/org/eclipse/jface/text | |
parent | 55556245428057377066735c8aa4b8363e342868 (diff) | |
download | eclipse.platform.text-2c06991068e3748cc3d2bc3b9e6980a83eaf50a7.tar.gz eclipse.platform.text-2c06991068e3748cc3d2bc3b9e6980a83eaf50a7.tar.xz eclipse.platform.text-2c06991068e3748cc3d2bc3b9e6980a83eaf50a7.zip |
First cut of regex content assist (contd.)
Diffstat (limited to 'org.eclipse.jface.text/src/org/eclipse/jface/text')
4 files changed, 175 insertions, 49 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java index a458c38f81b..1f26a86e308 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java @@ -24,6 +24,9 @@ import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.VerifyEvent; @@ -198,7 +201,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt * detected, will wait the indicated delay interval before * activating the content assistant. */ - class AutoAssistListener implements VerifyKeyListener, Runnable { + class AutoAssistListener extends KeyAdapter implements KeyListener, Runnable { private Thread fThread; private boolean fIsReset= false; @@ -260,7 +263,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt return false; } - public void verifyKey(VerifyEvent e) { + public void keyPressed(KeyEvent e) { // Only act on typed characters and ignore modifier-only events if (e.character == 0 && (e.keyCode & SWT.KEYCODE_BIT) == 0) return; @@ -269,18 +272,12 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt int pos= fContentAssistRequestorAdapter.getSelectedRange().x; char[] activation; - if (fContentAssistRequestor != null) - activation= getCompletionProposalAutoActivationCharacters(fContentAssistRequestor, pos); - else - activation= getCompletionProposalAutoActivationCharacters(fViewer, pos); + activation= fContentAssistRequestorAdapter.getCompletionProposalAutoActivationCharacters(ContentAssistant.this, pos); if (contains(activation, e.character) && !fProposalPopup.isActive()) showStyle= SHOW_PROPOSALS; else { - if (fContentAssistRequestor != null) - activation= getContextInformationAutoActivationCharacters(fContentAssistRequestor, pos); - else - activation= getContextInformationAutoActivationCharacters(fViewer, pos); + activation= fContentAssistRequestorAdapter.getContextInformationAutoActivationCharacters(ContentAssistant.this, pos); if (contains(activation, e.character) && fContextInfoPopup != null && !fContextInfoPopup.isActive()) showStyle= SHOW_CONTEXT_INFO; else { @@ -608,7 +605,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt } } if (fAutoAssistListener != null) - fAutoAssistListener.verifyKey(e); + fAutoAssistListener.keyPressed(e); } /* @@ -790,15 +787,13 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt private void manageAutoActivation(boolean start) { if (start) { - if ((fViewer != null || fContentAssistRequestor != null) && fAutoAssistListener == null) { + if ((fContentAssistRequestorAdapter != null) && fAutoAssistListener == null) { fAutoAssistListener= new AutoAssistListener(); - if (!fContentAssistRequestorAdapter.appendVerifyKeyListener(fAutoAssistListener)) { - fAutoAssistListener= null; - } + fContentAssistRequestorAdapter.addKeyListener(fAutoAssistListener); } } else if (fAutoAssistListener != null) { - fContentAssistRequestorAdapter.removeVerifyKeyListener(fAutoAssistListener); + fContentAssistRequestorAdapter.removeKeyListener(fAutoAssistListener); fAutoAssistListener= null; } } @@ -988,7 +983,6 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt * @see IContentAssistantExtension#install(IContentAssistRequestor) */ public void install(IContentAssistRequestor contentAssistRequestor) { - Assert.isNotNull(contentAssistRequestor); fContentAssistRequestor= contentAssistRequestor; fContentAssistRequestorAdapter= new ContentAssistRequestorAdapter(fContentAssistRequestor); install(); @@ -998,9 +992,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt * @see IContentAssist#install */ public void install(ITextViewer textViewer) { - Assert.isNotNull(textViewer); fViewer= textViewer; - fContextInfoPopup= new ContextInformationPopup(this, fViewer); fContentAssistRequestorAdapter= new ContentAssistRequestorAdapter(fViewer); install(); } @@ -1019,10 +1011,8 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt controller= new AdditionalInfoController(fInformationControlCreator, delay); } - if (fContentAssistRequestor != null) - fProposalPopup= new CompletionProposalPopup(this, fContentAssistRequestor, controller); - else - fProposalPopup= new CompletionProposalPopup(this, fViewer, controller); + fContextInfoPopup= fContentAssistRequestorAdapter.createContextInfoPopup(this); + fProposalPopup= fContentAssistRequestorAdapter.createCompletionProposalPopup(this, controller); manageAutoActivation(fIsAutoActivated); } @@ -1420,6 +1410,31 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt return result; } + + /** + * Returns an array of context information objects computed based + * on the specified document position. The position is used to determine + * the appropriate content assist processor to invoke. + * + * @param contentAssistRequestor the content assit requestor + * @param position a document position + * @return an array of context information objects + * + * @see IContentAssistProcessor#computeContextInformation + */ + IContextInformation[] computeContextInformation(IContentAssistRequestor contentAssistRequestor, int position) { + fLastErrorMessage= null; + + IContextInformation[] result= null; + + IContentAssistProcessor p= getProcessor(contentAssistRequestor, position); + if (p instanceof IContentAssistProcessorExtension) { + result= ((IContentAssistProcessorExtension)p).computeContextInformation(contentAssistRequestor, position); + fLastErrorMessage= p.getErrorMessage(); + } + + return result; + } /** * Returns the context information validator that should be used to @@ -1444,11 +1459,11 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt * be dismissed. The position is used to determine the appropriate * content assist processor to invoke. * - * @param viewer the text viewer + * @param contentAssistRequestor the content assist requestor * @param offset a document offset * @return an validator - * * @see IContentAssistProcessor#getContextInformationValidator + * @since 3.0 */ IContextInformationValidator getContextInformationValidator(IContentAssistRequestor contentAssistRequestor, int offset) { IContentAssistProcessor p= getProcessor(contentAssistRequestor, offset); @@ -1473,6 +1488,23 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt } /** + * Returns the context information presenter that should be used to + * display context information. The position is used to determine the appropriate + * content assist processor to invoke. + * + * @param contentAssistRequestor the content assist requestor + * @param offset a document offset + * @return a presenter + * @since 3.0 + */ + IContextInformationPresenter getContextInformationPresenter(IContentAssistRequestor contentAssistRequestor, int offset) { + IContextInformationValidator validator= getContextInformationValidator(contentAssistRequestor, offset); + if (validator instanceof IContextInformationPresenter) + return (IContextInformationPresenter) validator; + return null; + } + + /** * Returns the characters which when typed by the user should automatically * initiate proposing completions. The position is used to determine the * appropriate content assist processor to invoke. @@ -1483,7 +1515,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters * @since 3.0 */ - private char[] getCompletionProposalAutoActivationCharacters(IContentAssistRequestor contentAssistRequestor, int offset) { + char[] getCompletionProposalAutoActivationCharacters(IContentAssistRequestor contentAssistRequestor, int offset) { IContentAssistProcessor p= getProcessor(contentAssistRequestor, offset); return p != null ? p.getCompletionProposalAutoActivationCharacters() : null; } @@ -1499,7 +1531,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt * * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters */ - private char[] getCompletionProposalAutoActivationCharacters(ITextViewer viewer, int offset) { + char[] getCompletionProposalAutoActivationCharacters(ITextViewer viewer, int offset) { IContentAssistProcessor p= getProcessor(viewer, offset); return p != null ? p.getCompletionProposalAutoActivationCharacters() : null; } @@ -1515,7 +1547,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt * * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters */ - private char[] getContextInformationAutoActivationCharacters(ITextViewer viewer, int offset) { + char[] getContextInformationAutoActivationCharacters(ITextViewer viewer, int offset) { IContentAssistProcessor p= getProcessor(viewer, offset); return p != null ? p.getContextInformationAutoActivationCharacters() : null; } @@ -1531,7 +1563,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt * * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters */ - private char[] getContextInformationAutoActivationCharacters(IContentAssistRequestor contentAssistRequestor, int offset) { + char[] getContextInformationAutoActivationCharacters(IContentAssistRequestor contentAssistRequestor, int offset) { IContentAssistProcessor p= getProcessor(contentAssistRequestor, offset); return p != null ? p.getContextInformationAutoActivationCharacters() : null; } diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java index d18df69a002..0d4d2c9a5b5 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java @@ -80,6 +80,18 @@ class ContextInformationPopup implements IContentAssistListener { private TextPresentation fTextPresentation; private Stack fContextFrameStack= new Stack(); + /** + * The content assist requestor. + * + * @since 3.0 + */ + private IContentAssistRequestor fContentAssistRequestor; + /** + * The content assist requestor adapter. + * + * @since 3.0 + */ + private ContentAssistRequestorAdapter fContentAssistRequestorAdapter; /** * Selection listener on the text widget which is active @@ -98,6 +110,20 @@ class ContextInformationPopup implements IContentAssistListener { public ContextInformationPopup(ContentAssistant contentAssistant, ITextViewer viewer) { fContentAssistant= contentAssistant; fViewer= viewer; + fContentAssistRequestorAdapter= new ContentAssistRequestorAdapter(fViewer); + } + + /** + * Creates a new context information popup. + * + * @param contentAssistant the content assist for computing the context information + * @param contentAssistRequestor the content assist requestor on top of which the context information is shown + * @since 3.0 + */ + public ContextInformationPopup(ContentAssistant contentAssistant, IContentAssistRequestor contentAssistRequestor) { + fContentAssistant= contentAssistant; + fContentAssistRequestor= contentAssistRequestor; + fContentAssistRequestorAdapter= new ContentAssistRequestorAdapter(fContentAssistRequestor); } /** @@ -107,11 +133,11 @@ class ContextInformationPopup implements IContentAssistListener { * @return a potential error message or <code>null</code> in case of no error */ public String showContextProposals(final boolean autoActivated) { - final StyledText styledText= fViewer.getTextWidget(); - BusyIndicator.showWhile(styledText.getDisplay(), new Runnable() { + final Control control= fContentAssistRequestorAdapter.getControl(); + BusyIndicator.showWhile(control.getDisplay(), new Runnable() { public void run() { - int position= fViewer.getSelectedRange().x; + int position= fContentAssistRequestorAdapter.getSelectedRange().x; IContextInformation[] contexts= computeContextInformation(position); int count = (contexts == null ? 0 : contexts.length); @@ -124,7 +150,7 @@ class ContextInformationPopup implements IContentAssistListener { // Precise context must be selected if (fLineDelimiter == null) - fLineDelimiter= styledText.getLineDelimiter(); + fLineDelimiter= fContentAssistRequestorAdapter.getLineDelimiter(); createContextSelector(); setContexts(contexts); @@ -132,7 +158,7 @@ class ContextInformationPopup implements IContentAssistListener { hideContextInfoPopup(); } else if (!autoActivated) { - styledText.getDisplay().beep(); + control.getDisplay().beep(); } } }); @@ -148,7 +174,7 @@ class ContextInformationPopup implements IContentAssistListener { * @since 2.0 */ public void showContextInformation(final IContextInformation info, final int position) { - Control control= fViewer.getTextWidget(); + Control control= fContentAssistRequestorAdapter.getControl(); BusyIndicator.showWhile(control.getDisplay(), new Runnable() { public void run() { internalShowContextInfo(info, position); @@ -167,7 +193,7 @@ class ContextInformationPopup implements IContentAssistListener { private void internalShowContextInfo(IContextInformation information, int offset) { - IContextInformationValidator validator= fContentAssistant.getContextInformationValidator(fViewer, offset); + IContextInformationValidator validator= fContentAssistRequestorAdapter.getContextInformationValidator(fContentAssistant, offset); if (validator != null) { ContextFrame current= new ContextFrame(); @@ -175,9 +201,9 @@ class ContextInformationPopup implements IContentAssistListener { current.fBeginOffset= (information instanceof IContextInformationExtension) ? ((IContextInformationExtension) information).getContextInformationPosition() : offset; if (current.fBeginOffset == -1) current.fBeginOffset= offset; current.fOffset= offset; - current.fVisibleOffset= fViewer.getTextWidget().getSelectionRange().x - (offset - current.fBeginOffset); + current.fVisibleOffset= fContentAssistRequestorAdapter.getWidgetSelectionRange().x - (offset - current.fBeginOffset); current.fValidator= validator; - current.fPresenter= fContentAssistant.getContextInformationPresenter(fViewer, offset); + current.fPresenter= fContentAssistRequestorAdapter.getContextInformationPresenter(fContentAssistant, offset); fContextFrameStack.push(current); @@ -194,12 +220,12 @@ class ContextInformationPopup implements IContentAssistListener { */ private void internalShowContextFrame(ContextFrame frame, boolean initial) { - frame.fValidator.install(frame.fInformation, fViewer, frame.fOffset); + fContentAssistRequestorAdapter.installValidator(frame); if (frame.fPresenter != null) { if (fTextPresentation == null) fTextPresentation= new TextPresentation(); - frame.fPresenter.install(frame.fInformation, fViewer, frame.fBeginOffset); + fContentAssistRequestorAdapter.installContextInformationPresenter(frame); frame.fPresenter.updatePresentation(frame.fOffset, fTextPresentation); } @@ -212,7 +238,7 @@ class ContextInformationPopup implements IContentAssistListener { if (initial) { if (fContentAssistant.addContentAssistListener(this, ContentAssistant.CONTEXT_INFO_POPUP)) { - if (fViewer.getTextWidget() != null) { + if (fContentAssistRequestorAdapter.getControl() != null) { fTextWidgetSelectionListener= new SelectionAdapter() { /* * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) @@ -220,7 +246,7 @@ class ContextInformationPopup implements IContentAssistListener { public void widgetSelected(SelectionEvent e) { validateContextInformation(); }}; - fViewer.getTextWidget().addSelectionListener(fTextWidgetSelectionListener); + fContentAssistRequestorAdapter.addSelectionListener(fTextWidgetSelectionListener); } fContentAssistant.addToLayout(this, fContextInfoPopup, ContentAssistant.LayoutManager.LAYOUT_CONTEXT_INFO_POPUP, frame.fVisibleOffset); fContextInfoPopup.setVisible(true); @@ -238,7 +264,7 @@ class ContextInformationPopup implements IContentAssistListener { * @since 2.0 */ private IContextInformation[] computeContextInformation(int position) { - return fContentAssistant.computeContextInformation(fViewer, position); + return fContentAssistRequestorAdapter.computeContextInformation(fContentAssistant, position); } /** @@ -257,7 +283,7 @@ class ContextInformationPopup implements IContentAssistListener { if (Helper.okToUse(fContextInfoPopup)) return; - Control control= fViewer.getTextWidget(); + Control control= fContentAssistRequestorAdapter.getControl(); Display display= control.getDisplay(); fContextInfoPopup= new Shell(control.getShell(), SWT.NO_TRIM | SWT.ON_TOP); @@ -310,8 +336,8 @@ class ContextInformationPopup implements IContentAssistListener { fContentAssistant.removeContentAssistListener(this, ContentAssistant.CONTEXT_INFO_POPUP); - if (fViewer.getTextWidget() != null) - fViewer.getTextWidget().removeSelectionListener(fTextWidgetSelectionListener); + if (fContentAssistRequestorAdapter.getControl() != null) + fContentAssistRequestorAdapter.removeSelectionListener(fTextWidgetSelectionListener); fTextWidgetSelectionListener= null; fContextInfoPopup.setVisible(false); @@ -337,7 +363,7 @@ class ContextInformationPopup implements IContentAssistListener { if (Helper.okToUse(fContextSelectorShell)) return; - Control control= fViewer.getTextWidget(); + Control control= fContentAssistRequestorAdapter.getControl(); fContextSelectorShell= new Shell(control.getShell(), SWT.NO_TRIM | SWT.ON_TOP); fContextSelectorTable= new Table(fContextSelectorShell, SWT.H_SCROLL | SWT.V_SCROLL); @@ -384,7 +410,7 @@ class ContextInformationPopup implements IContentAssistListener { if (i < 0 || i >= fContextSelectorInput.length) return; - int position= fViewer.getSelectedRange().x; + int position= fContentAssistRequestorAdapter.getSelectedRange().x; internalShowContextInfo(fContextSelectorInput[i], position); } @@ -634,7 +660,7 @@ class ContextInformationPopup implements IContentAssistListener { public void run() { if (Helper.okToUse(fContextInfoPopup) && fFrame == fContextFrameStack.peek()) { - int offset= fViewer.getSelectedRange().x; + int offset= fContentAssistRequestorAdapter.getSelectedRange().x; if (fFrame.fValidator == null || !fFrame.fValidator.isContextInformationValid(offset)) { hideContextInfoPopup(); } else if (fFrame.fPresenter != null && fFrame.fPresenter.updatePresentation(offset, fTextPresentation)) { diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationPresenterExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationPresenterExtension.java new file mode 100644 index 00000000000..ee92fb07866 --- /dev/null +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationPresenterExtension.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * 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 + *******************************************************************************/ + +package org.eclipse.jface.text.contentassist; + +/** + * Extends <code>IContentAssit</code> with the concept of a + * content assist requestor which provides the context for + * the content assistant. + * <p> + * XXX: This is work in progress and can change anytime until API for 3.0 is frozen. + * </p> + * + * @since 3.0 + */ +public interface IContextInformationPresenterExtension { + + /** + * Installs this presenter for the given context information. + * + * @param info the context information which this presenter should style + * @param contentAssistRequestor the content assit requestor + * @param documentPosition the document position for which the information has been computed + */ + void install(IContextInformation info, IContentAssistRequestor contentAssistRequestor, int documentPosition); +} diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationValidatorExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationValidatorExtension.java new file mode 100644 index 00000000000..099a52ab209 --- /dev/null +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationValidatorExtension.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * 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 + *******************************************************************************/ + +package org.eclipse.jface.text.contentassist; +/** + * Extends <code>IContentAssit</code> with the concept of a content assist + * requestor which provides the context for the content assistant. + * <p> + * XXX: This is work in progress and can change anytime until API for 3.0 is + * frozen. + * </p> + * + * @since 3.0 + */ +public interface IContextInformationValidatorExtension { + + /** + * Installs this validator for the given context information. + * + * @param info the context information which this validator should check + * @param contentAssistRequestor the content assist requestor + * @param documentPosition the document position for which the information + * has been computed + */ + void install(IContextInformation info, IContentAssistRequestor contentAssistRequestor, int documentPosition); +} |