Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2016-11-08 06:52:49 -0500
committerMickael Istria2016-11-08 07:30:55 -0500
commit0425c77dced32fbcc337ebbd6753a4829ec513a9 (patch)
treef54202ee018aab861f310595b54efc7f189610a8 /org.eclipse.ui.genericeditor
parent52ae262a804b8c49ed8ee4b7bc4fac2fd21cc18c (diff)
downloadeclipse.platform.text-0425c77dced32fbcc337ebbd6753a4829ec513a9.tar.gz
eclipse.platform.text-0425c77dced32fbcc337ebbd6753a4829ec513a9.tar.xz
eclipse.platform.text-0425c77dced32fbcc337ebbd6753a4829ec513a9.zip
Bug 500755: [Generic Editor] attach completion to all token contenttypes
As some extension can provide some specific document partitioner, we need to attach completion dynamically to all supported token content-types. Change-Id: Ibfb55c7c254d78b6b6da61916af8b789bb50dfd5 Signed-off-by: Mickael Istria <mistria@redhat.com>
Diffstat (limited to 'org.eclipse.ui.genericeditor')
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextEditor.java15
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java67
2 files changed, 68 insertions, 14 deletions
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextEditor.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextEditor.java
index 467be5318..bcbf846c5 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextEditor.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextEditor.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.ui.internal.genericeditor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.TextEditor;
/**
@@ -21,17 +24,25 @@ import org.eclipse.ui.editors.text.TextEditor;
public class ExtensionBasedTextEditor extends TextEditor {
private static final String CONTEXT_ID = "org.eclipse.ui.genericeditor.genericEditorContext"; //$NON-NLS-1$
+ private ExtensionBasedTextViewerConfiguration configuration;
/**
*
*/
public ExtensionBasedTextEditor() {
- setSourceViewerConfiguration(new ExtensionBasedTextViewerConfiguration(this, getPreferenceStore()));
+ configuration = new ExtensionBasedTextViewerConfiguration(this, getPreferenceStore());
+ setSourceViewerConfiguration(configuration);
}
-
+
@Override
protected void setKeyBindingScopes(String[] scopes) {
super.setKeyBindingScopes(new String[] { CONTEXT_ID });
}
+ @Override
+ protected void doSetInput(IEditorInput input) throws CoreException {
+ super.doSetInput(input);
+ configuration.watchDocument(getDocumentProvider().getDocument(input));
+ }
+
}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
index d5b84b523..6af35f9d1 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
@@ -23,6 +23,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.AbstractReusableInformationControlCreator;
import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioningListener;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.contentassist.ContentAssistant;
@@ -32,7 +33,9 @@ import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+import org.eclipse.ui.texteditor.ITextEditor;
/**
* The configuration of the {@link ExtensionBasedTextEditor}. It registers the proxy composite
@@ -41,19 +44,30 @@ import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
*
* @since 1.0
*/
-public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewerConfiguration {
+public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewerConfiguration implements IDocumentPartitioningListener {
- private IEditorPart editor;
+ private ITextEditor editor;
private Set<IContentType> contentTypes;
+ private IDocument document;
+ private ContentAssistant contentAssistant;
+ private IContentAssistProcessor contentAssistProcessor;
/**
*
* @param editor the editor we're creating.
* @param preferenceStore the preference store.
*/
- public ExtensionBasedTextViewerConfiguration(IEditorPart editor, IPreferenceStore preferenceStore) {
+ public ExtensionBasedTextViewerConfiguration(ITextEditor editor, IPreferenceStore preferenceStore) {
super(preferenceStore);
this.editor = editor;
+ this.editor.addPropertyListener(new IPropertyListener() {
+ @Override
+ public void propertyChanged(Object source, int propId) {
+ if (propId == IEditorPart.PROP_INPUT) {
+ watchDocument(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
+ }
+ }
+ });
}
private Set<IContentType> getContentTypes() {
@@ -81,20 +95,23 @@ public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewe
@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
ContentAssistProcessorRegistry registry= GenericEditorPlugin.getDefault().getContentAssistProcessorRegistry();
- IContentAssistProcessor processor = new CompositeContentAssistProcessor(registry.getContentAssistProcessors(sourceViewer, getContentTypes()));
- ContentAssistant res= new ContentAssistant();
- res.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
- res.setProposalPopupOrientation(ContentAssistant.PROPOSAL_REMOVE);
- res.enableColoredLabels(true);
- res.enableAutoActivation(true);
- res.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
- res.setInformationControlCreator(new AbstractReusableInformationControlCreator() {
+ contentAssistProcessor = new CompositeContentAssistProcessor(registry.getContentAssistProcessors(sourceViewer, getContentTypes()));
+ contentAssistant = new ContentAssistant();
+ contentAssistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
+ contentAssistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_REMOVE);
+ contentAssistant.enableColoredLabels(true);
+ contentAssistant.enableAutoActivation(true);
+ contentAssistant.setContentAssistProcessor(contentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE);
+ if (this.document != null) {
+ associateTokenContentTypes(this.document);
+ }
+ contentAssistant.setInformationControlCreator(new AbstractReusableInformationControlCreator() {
@Override
protected IInformationControl doCreateInformationControl(Shell parent) {
return new DefaultInformationControl(parent);
}
});
- return res;
+ return contentAssistant;
}
@Override
@@ -107,4 +124,30 @@ public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewe
return super.getPresentationReconciler(sourceViewer);
}
+ void watchDocument(IDocument document) {
+ if (this.document == document) {
+ return;
+ }
+ if (this.document != null) {
+ this.document.removeDocumentPartitioningListener(this);
+ }
+ this.document = document;
+ associateTokenContentTypes(document);
+ document.addDocumentPartitioningListener(this);
+ }
+
+ @Override
+ public void documentPartitioningChanged(IDocument document) {
+ associateTokenContentTypes(document);
+ }
+
+ private void associateTokenContentTypes(IDocument document) {
+ if (contentAssistant == null) {
+ return;
+ }
+ for (String legalTokenContentType : document.getLegalContentTypes()) {
+ contentAssistant.setContentAssistProcessor(this.contentAssistProcessor, legalTokenContentType);
+ }
+ }
+
}

Back to the top