Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2017-03-21 14:30:07 -0400
committerMickael Istria2017-03-21 16:13:55 -0400
commit7246e5b58d418d14b6647937bc83bc16a7db7083 (patch)
treef7f62c6fb5dc7f88723e68301d51cb28b919b7e6 /org.eclipse.ui.genericeditor
parent2506487936fb97d773fe2797e919a44d830b23b2 (diff)
downloadeclipse.platform.text-7246e5b58d418d14b6647937bc83bc16a7db7083.tar.gz
eclipse.platform.text-7246e5b58d418d14b6647937bc83bc16a7db7083.tar.xz
eclipse.platform.text-7246e5b58d418d14b6647937bc83bc16a7db7083.zip
Bug 513314 - Example enabling spellcheck on generic editorI20170324-2000I20170323-2000
+ Enable quick fix for spelling issues by default Change-Id: I32973aa0e064547f1c5800e2503f43ef3c319078 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/CompositeQuickAssistProcessor.java85
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java7
2 files changed, 91 insertions, 1 deletions
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CompositeQuickAssistProcessor.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CompositeQuickAssistProcessor.java
new file mode 100644
index 000000000..0e11b3c97
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CompositeQuickAssistProcessor.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * - Mickael Istria (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.ui.internal.genericeditor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
+import org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
+import org.eclipse.jface.text.source.Annotation;
+
+/**
+ * A quick assist processor that delegates all content assist
+ * operations to children provided in constructor and aggregates
+ * the results.
+ *
+ * @since 1.0
+ */
+public class CompositeQuickAssistProcessor implements IQuickAssistProcessor {
+
+ private List<IQuickAssistProcessor> fProcessors;
+
+ public CompositeQuickAssistProcessor(List<IQuickAssistProcessor> processors) {
+ this.fProcessors = processors;
+ }
+
+ @Override
+ public String getErrorMessage() {
+ StringBuilder res = new StringBuilder();
+ for (IQuickAssistProcessor processor : this.fProcessors) {
+ String errorMessage = processor.getErrorMessage();
+ if (errorMessage != null) {
+ res.append(errorMessage);
+ res.append('\n');
+ }
+ }
+ if (res.length() == 0) {
+ return null;
+ }
+ return res.toString();
+ }
+
+ @Override
+ public boolean canFix(Annotation annotation) {
+ for (IQuickAssistProcessor processor : this.fProcessors) {
+ if (processor.canFix(annotation)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean canAssist(IQuickAssistInvocationContext invocationContext) {
+ for (IQuickAssistProcessor processor : this.fProcessors) {
+ if (processor.canAssist(invocationContext)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
+ List<ICompletionProposal> res = new ArrayList<>();
+ for (IQuickAssistProcessor processor : this.fProcessors) {
+ ICompletionProposal[] proposals = processor.computeQuickAssistProposals(invocationContext);
+ if (proposals != null) {
+ res.addAll(Arrays.asList(proposals));
+ }
+ }
+ return res.toArray(new ICompletionProposal[res.size()]);
+ }
+
+}
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 d24f71fc9..1fe651b32 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
@@ -42,6 +42,7 @@ import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
import org.eclipse.ui.internal.genericeditor.markers.MarkerResoltionQuickAssistProcessor;
import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.spelling.SpellingCorrectionProcessor;
/**
* The configuration of the {@link ExtensionBasedTextEditor}. It registers the proxy composite
@@ -165,7 +166,11 @@ public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewe
@Override
public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) {
QuickAssistAssistant quickAssistAssistant = new QuickAssistAssistant();
- quickAssistAssistant.setQuickAssistProcessor(new MarkerResoltionQuickAssistProcessor());
+ CompositeQuickAssistProcessor processor = new CompositeQuickAssistProcessor(Arrays.asList(
+ new MarkerResoltionQuickAssistProcessor(),
+ new SpellingCorrectionProcessor()
+ ));
+ quickAssistAssistant.setQuickAssistProcessor(processor);
quickAssistAssistant.setRestoreCompletionProposalSize(EditorsPlugin.getDefault().getDialogSettingsSection("quick_assist_proposal_size")); //$NON-NLS-1$
quickAssistAssistant.setInformationControlCreator(new IInformationControlCreator() {
@Override

Back to the top