Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorangelozerr2018-08-21 10:32:48 +0000
committerMickael Istria2018-08-24 07:34:53 +0000
commit762fdeb324379150150e696639fd967baee29b97 (patch)
treeb2cab271f90fe8d5e7ec00e520970b71f8e592f0 /org.eclipse.ui.genericeditor
parent16bb876f5de4fab50e3b7b5328553fff76166ef0 (diff)
downloadeclipse.platform.text-762fdeb324379150150e696639fd967baee29b97.tar.gz
eclipse.platform.text-762fdeb324379150150e696639fd967baee29b97.tar.xz
eclipse.platform.text-762fdeb324379150150e696639fd967baee29b97.zip
Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
Change-Id: Id8fd3d0dcfc09fa8f7037dbac83de487e729f26a Signed-off-by: angelozerr <angelo.zerr@gmail.com>
Diffstat (limited to 'org.eclipse.ui.genericeditor')
-rw-r--r--org.eclipse.ui.genericeditor/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.ui.genericeditor/plugin.properties1
-rw-r--r--org.eclipse.ui.genericeditor/plugin.xml4
-rw-r--r--org.eclipse.ui.genericeditor/resources/css/dark.css5
-rw-r--r--org.eclipse.ui.genericeditor/schema/characterPairMatchers.exsd154
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CharacterPairMatcherRegistry.java100
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextEditor.java62
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java2
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java53
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPluginPreferenceInitializer.java89
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPreferenceConstants.java106
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/IGenericEditorThemeConstants.java31
12 files changed, 592 insertions, 18 deletions
diff --git a/org.eclipse.ui.genericeditor/META-INF/MANIFEST.MF b/org.eclipse.ui.genericeditor/META-INF/MANIFEST.MF
index 4e0a0c264b6..7920154b899 100644
--- a/org.eclipse.ui.genericeditor/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.genericeditor/META-INF/MANIFEST.MF
@@ -17,7 +17,8 @@ Require-Bundle: org.eclipse.ui.workbench.texteditor;bundle-version="3.10.0",
org.eclipse.core.expressions;bundle-version="3.6.0"
Export-Package: org.eclipse.ui.internal.genericeditor;x-internal:=true,
org.eclipse.ui.internal.genericeditor.hover;x-internal:=true,
- org.eclipse.ui.internal.genericeditor.markers;x-internal:=true
+ org.eclipse.ui.internal.genericeditor.markers;x-internal:=true,
+ org.eclipse.ui.internal.genericeditor.preferences;x-internal:=true
Bundle-Activator: org.eclipse.ui.internal.genericeditor.GenericEditorPlugin
Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
diff --git a/org.eclipse.ui.genericeditor/plugin.properties b/org.eclipse.ui.genericeditor/plugin.properties
index 1ff71d17785..48953f9e772 100644
--- a/org.eclipse.ui.genericeditor/plugin.properties
+++ b/org.eclipse.ui.genericeditor/plugin.properties
@@ -22,6 +22,7 @@ ExtPoint.contentAssistProcessors=Content Assist Providers
ExtPoint.autoEditStrategies=Auto Edit Strategies
ExtPoint.highlightReconcilers=Highlight Reconcilers
ExtPoint.foldingReconcilers=Folding Reconcilers
+ExtPoint.characterPairMatchers=Character Pair Matcher Providers
ExtPoint.hyperlinkDetectorTarget=Generic Text Editor
openDeclarationCommand_name=Open Declaration
context_name=in Generic Code Editor
diff --git a/org.eclipse.ui.genericeditor/plugin.xml b/org.eclipse.ui.genericeditor/plugin.xml
index e1c2570e5db..938663e7438 100644
--- a/org.eclipse.ui.genericeditor/plugin.xml
+++ b/org.eclipse.ui.genericeditor/plugin.xml
@@ -23,6 +23,7 @@
<extension-point id="autoEditStrategies" name="%ExtPoint.autoEditStrategies" schema="schema/autoEditStrategies.exsd"/>
<extension-point id="highlightReconcilers" name="%ExtPoint.highlightReconcilers" schema="schema/highlightReconcilers.exsd"/>
<extension-point id="foldingReconcilers" name="%ExtPoint.foldingReconcilers" schema="schema/foldingReconcilers.exsd"/>
+ <extension-point id="characterPairMatchers" name="%ExtPoint.characterPairMatchers" schema="schema/characterPairMatchers.exsd"/>
<extension
point="org.eclipse.ui.editors">
<editor
@@ -193,4 +194,7 @@
</with>
</definition>
</extension>
+ <extension point="org.eclipse.core.runtime.preferences">
+ <initializer class="org.eclipse.ui.internal.genericeditor.preferences.GenericEditorPluginPreferenceInitializer"/>
+ </extension>
</plugin>
diff --git a/org.eclipse.ui.genericeditor/resources/css/dark.css b/org.eclipse.ui.genericeditor/resources/css/dark.css
index 92c466cc0ed..b37247230dd 100644
--- a/org.eclipse.ui.genericeditor/resources/css/dark.css
+++ b/org.eclipse.ui.genericeditor/resources/css/dark.css
@@ -17,3 +17,8 @@ IEclipsePreferences#org-eclipse-ui-editors:org-eclipse-ui-genericeditor {
'TextOccurrenceIndicationColor=27, 98, 145'
}
+IEclipsePreferences#org-eclipse-ui-genericeditor:org-eclipse-ui-genericeditor {
+ preferences:
+ 'matchingBracketsColor=249,250,244'
+}
+
diff --git a/org.eclipse.ui.genericeditor/schema/characterPairMatchers.exsd b/org.eclipse.ui.genericeditor/schema/characterPairMatchers.exsd
new file mode 100644
index 00000000000..6890423431f
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/schema/characterPairMatchers.exsd
@@ -0,0 +1,154 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.ui.genericeditor" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.ui.genericeditor" id="characterPairMatchers" name="Character pair matchers"/>
+ </appinfo>
+ <documentation>
+ This extension point is used to contribute character pair matchers for controlling the matching brackets on a file with a given content type.
+ </documentation>
+ </annotation>
+
+ <include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="characterPairMatcher"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+ a fully qualified identifier of the target extension point
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ an optional identifier of the extension instance
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ an optional name of the extension instance
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="characterPairMatcher">
+ <complexType>
+ <sequence>
+ <element ref="enabledWhen" minOccurs="0" maxOccurs="1"/>
+ </sequence>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.source.ICharacterPairMatcher&lt;/code&gt;
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.jface.text.source.ICharacterPairMatcher"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="contentType" type="string" use="required">
+ <annotation>
+ <documentation>
+ The target content-type for this extension. Content-types are defined as extension to the org.eclipse.core.contenttype.contentTypes extension point.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="identifier" basedOn="org.eclipse.core.contenttype.contentTypes/content-type/@id"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="enabledWhen">
+ <annotation>
+ <documentation>
+ A core Expression that controls the enabled of the given character pair matcher. The viewer, editor, and editor input are registered in the evaluation context as variable:
+
+ * &lt;with variable=&quot;viewer&quot;/&gt; : use it if your expression requires the viewer.
+ * &lt;with variable=&quot;editor&quot;/&gt; : use it if your expression requires the editor.
+ * &lt;with variable=&quot;editorInput&quot;/&gt; : use it if your expression requires the editor input.
+ </documentation>
+ </annotation>
+ <complexType>
+ <choice minOccurs="0" maxOccurs="1">
+ <element ref="not"/>
+ <element ref="or"/>
+ <element ref="and"/>
+ <element ref="instanceof"/>
+ <element ref="test"/>
+ <element ref="systemTest"/>
+ <element ref="equals"/>
+ <element ref="count"/>
+ <element ref="with"/>
+ <element ref="resolve"/>
+ <element ref="adapt"/>
+ <element ref="iterate"/>
+ <element ref="reference"/>
+ </choice>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ 1.2
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ Below is an example of how to use the character pair matchers extension point:
+
+&lt;pre&gt;
+&lt;extension point=&quot;org.eclipse.ui.genericeditor.characterPairMatchers&quot;&gt;
+ &lt;characterPairMatcher
+ class=&quot;org.eclipse.ui.genericeditor.examples.TargetDefinitionCharacterPairMatchers&quot;
+ contentType=&quot;org.eclipse.pde.targetFile&quot;&gt;
+ &lt;enabledWhen&gt;
+ &lt;with variable=&quot;editor&quot;&gt;
+ &lt;test property=&quot;org.eclipse.ui.genericeditor.examples.TargetDefinitionPropertyTester&quot;&gt;
+ &lt;/test&gt;
+ &lt;/with&gt;
+ &lt;/enabledWhen&gt;
+ &lt;/characterPairMatcher&gt;
+&lt;/extension&gt;
+&lt;/pre&gt;
+ </documentation>
+ </annotation>
+
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ Copyright (c) 2018 Angelo ZERR and others
+All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at &lt;a href=&quot;http://www.eclipse.org/legal/epl-v20.html&quot;&gt;http://www.eclipse.org/legal/epl-v20.html&lt;/a&gt;
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CharacterPairMatcherRegistry.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CharacterPairMatcherRegistry.java
new file mode 100644
index 00000000000..52f03824f42
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/CharacterPairMatcherRegistry.java
@@ -0,0 +1,100 @@
+/**
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
+ */
+package org.eclipse.ui.internal.genericeditor;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.text.source.ICharacterPairMatcher;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * A registry of character pair matchers provided by extension
+ * <code>org.eclipse.ui.genericeditor.characterPairMatchers</code>. Those
+ * extensions are specific to a given {@link IContentType}.
+ *
+ * @since 1.2
+ */
+public class CharacterPairMatcherRegistry {
+
+ private static final String EXTENSION_POINT_ID = GenericEditorPlugin.BUNDLE_ID + ".characterPairMatchers"; //$NON-NLS-1$
+
+ private Map<IConfigurationElement, GenericContentTypeRelatedExtension<ICharacterPairMatcher>> extensions = new HashMap<>();
+ private boolean outOfSync = true;
+
+ /**
+ * Creates the registry and binds it to the extension point.
+ */
+ public CharacterPairMatcherRegistry() {
+ Platform.getExtensionRegistry().addRegistryChangeListener(new IRegistryChangeListener() {
+ @Override
+ public void registryChanged(IRegistryChangeEvent event) {
+ outOfSync = true;
+ }
+ }, EXTENSION_POINT_ID);
+ }
+
+ /**
+ * Get the contributed {@link IPresentationReconciliers}s that are relevant to
+ * hook on source viewer according to document content types.
+ *
+ * @param sourceViewer the source viewer we're hooking completion to.
+ * @param editor the text editor
+ * @param contentTypes the content types of the document we're editing.
+ * @return the list of {@link ICharacterPairMatcher} contributed for at least
+ * one of the content types.
+ */
+ public List<ICharacterPairMatcher> getCharacterPairMatchers(ISourceViewer sourceViewer, ITextEditor editor,
+ Set<IContentType> contentTypes) {
+ if (this.outOfSync) {
+ sync();
+ }
+ return this.extensions.values().stream().filter(ext -> contentTypes.contains(ext.targetContentType))
+ .filter(ext -> ext.matches(sourceViewer, editor))
+ .sorted(new ContentTypeSpecializationComparator<ICharacterPairMatcher>())
+ .map(GenericContentTypeRelatedExtension<ICharacterPairMatcher>::createDelegate)
+ .collect(Collectors.toList());
+ }
+
+ private void sync() {
+ Set<IConfigurationElement> toRemoveExtensions = new HashSet<>(this.extensions.keySet());
+ for (IConfigurationElement extension : Platform.getExtensionRegistry()
+ .getConfigurationElementsFor(EXTENSION_POINT_ID)) {
+ toRemoveExtensions.remove(extension);
+ if (!this.extensions.containsKey(extension)) {
+ try {
+ this.extensions.put(extension,
+ new GenericContentTypeRelatedExtension<ICharacterPairMatcher>(extension));
+ } catch (Exception ex) {
+ GenericEditorPlugin.getDefault().getLog()
+ .log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, ex.getMessage(), ex));
+ }
+ }
+ }
+ for (IConfigurationElement toRemove : toRemoveExtensions) {
+ this.extensions.remove(toRemove);
+ }
+ this.outOfSync = false;
+ }
+
+}
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 5415840f1b8..b0e8db54022 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
@@ -11,10 +11,15 @@
* Contributors:
* Sopot Cela, Mickael Istria (Red Hat Inc.) - initial implementation
* Lucas Bullen (Red Hat Inc.) - Bug 508829 custom reconciler support
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
*******************************************************************************/
package org.eclipse.ui.internal.genericeditor;
+import java.util.List;
+
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.source.ICharacterPairMatcher;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
@@ -22,16 +27,26 @@ import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.internal.editors.text.EditorsPlugin;
+import org.eclipse.ui.internal.genericeditor.preferences.GenericEditorPreferenceConstants;
+import org.eclipse.ui.texteditor.ChainedPreferenceStore;
+import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
/**
- * A generic code editor that is aimed at being extended by contributions. Behavior
- * is supposed to be added via extensions, not by inheritance.
+ * A generic code editor that is aimed at being extended by contributions.
+ * Behavior is supposed to be added via extensions, not by inheritance.
*
* @since 1.0
*/
public class ExtensionBasedTextEditor extends TextEditor {
private static final String CONTEXT_ID = "org.eclipse.ui.genericeditor.genericEditorContext"; //$NON-NLS-1$
+
+ private static final String MATCHING_BRACKETS = GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS;
+ private static final String MATCHING_BRACKETS_COLOR = GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
+ private static final String HIGHLIGHT_BRACKET_AT_CARET_LOCATION = GenericEditorPreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION;
+ private static final String ENCLOSING_BRACKETS = GenericEditorPreferenceConstants.EDITOR_ENCLOSING_BRACKETS;
+
private ExtensionBasedTextViewerConfiguration configuration;
/**
@@ -55,23 +70,48 @@ public class ExtensionBasedTextEditor extends TextEditor {
@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
- fAnnotationAccess= getAnnotationAccess();
- fOverviewRuler= createOverviewRuler(getSharedColors());
+ fAnnotationAccess = getAnnotationAccess();
+ fOverviewRuler = createOverviewRuler(getSharedColors());
- ProjectionViewer viewer= new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
- getSourceViewerDecorationSupport(viewer);
+ ProjectionViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(),
+ styles);
+ SourceViewerDecorationSupport support = getSourceViewerDecorationSupport(viewer);
+ configureCharacterPairMatcher(viewer, support);
return viewer;
}
-
@Override
- public void createPartControl(Composite parent)
- {
+ public void createPartControl(Composite parent) {
super.createPartControl(parent);
- ProjectionViewer viewer =(ProjectionViewer)getSourceViewer();
+ ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
- new ProjectionSupport(viewer,getAnnotationAccess(),getSharedColors()).install();
+ new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors()).install();
viewer.doOperation(ProjectionViewer.TOGGLE);
}
+ @Override
+ protected void initializeEditor() {
+ setPreferenceStore(new ChainedPreferenceStore(
+ new IPreferenceStore[] { GenericEditorPreferenceConstants.getPreferenceStore(),
+ EditorsPlugin.getDefault().getPreferenceStore() }));
+ }
+
+ /**
+ * Configure the {@link ICharacterPairMatcher} from the
+ * "org.eclipse.ui.genericeditor.characterPairMatchers" extension point.
+ *
+ * @param viewer the source viewer.
+ *
+ * @param support the source viewer decoration support.
+ */
+ private void configureCharacterPairMatcher(ISourceViewer viewer, SourceViewerDecorationSupport support) {
+ List<ICharacterPairMatcher> matchers = GenericEditorPlugin.getDefault().getCharacterPairMatcherRegistry()
+ .getCharacterPairMatchers(viewer, this, configuration.getContentTypes());
+ if (!matchers.isEmpty()) {
+ ICharacterPairMatcher matcher = matchers.get(0);
+ support.setCharacterPairMatcher(matcher);
+ support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR,
+ HIGHLIGHT_BRACKET_AT_CARET_LOCATION, ENCLOSING_BRACKETS);
+ }
+ }
}
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 eb4455e7919..28a2c64a6c0 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
@@ -87,7 +87,7 @@ public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewe
});
}
- private Set<IContentType> getContentTypes() {
+ Set<IContentType> getContentTypes() {
if (this.contentTypes == null) {
this.contentTypes = new LinkedHashSet<>();
Queue<IContentType> types = new LinkedList<>(Arrays
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java
index 21c46b87708..12fe25a7ff3 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java
@@ -14,11 +14,20 @@
*******************************************************************************/
package org.eclipse.ui.internal.genericeditor;
+import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.source.ICharacterPairMatcher;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.genericeditor.hover.TextHoverRegistry;
+import org.eclipse.ui.internal.genericeditor.preferences.GenericEditorPluginPreferenceInitializer;
+import org.eclipse.ui.internal.genericeditor.preferences.GenericEditorPreferenceConstants;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.ui.themes.IThemeManager;
import org.osgi.framework.BundleContext;
/**
@@ -37,16 +46,35 @@ public class GenericEditorPlugin extends AbstractUIPlugin {
private ReconcilerRegistry reconcilierRegistry;
private PresentationReconcilerRegistry presentationReconcilierRegistry;
private AutoEditStrategyRegistry autoEditStrategyRegistry;
+ private CharacterPairMatcherRegistry characterPairMatcherRegistry;
+
+ private IPropertyChangeListener themeListener;
@Override
- public void start(BundleContext context) throws Exception{
+ public void start(BundleContext context) throws Exception {
INSTANCE = this;
super.start(context);
+
+ if (PlatformUI.isWorkbenchRunning()) {
+ themeListener = new IPropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty()))
+ GenericEditorPluginPreferenceInitializer
+ .setThemeBasedPreferences(GenericEditorPreferenceConstants.getPreferenceStore(), true);
+ }
+ };
+ PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(themeListener);
+ }
}
@Override
public void stop(BundleContext context) throws Exception {
super.stop(context);
+ if (themeListener != null) {
+ PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(themeListener);
+ themeListener = null;
+ }
INSTANCE = null;
}
@@ -66,7 +94,8 @@ public class GenericEditorPlugin extends AbstractUIPlugin {
}
/**
- * @return the registry allowing to access contributed {@link IContentAssistProcessor}s.
+ * @return the registry allowing to access contributed
+ * {@link IContentAssistProcessor}s.
* @since 1.0
*/
public synchronized ContentAssistProcessorRegistry getContentAssistProcessorRegistry() {
@@ -75,7 +104,7 @@ public class GenericEditorPlugin extends AbstractUIPlugin {
}
return this.contentAssistProcessorsRegistry;
}
-
+
/**
* @return the registry allowing to access contributed {@link IReconciler}s.
* @since 1.1
@@ -88,7 +117,8 @@ public class GenericEditorPlugin extends AbstractUIPlugin {
}
/**
- * @return the registry allowing to access contributed {@link IPresentationReconciler}s.
+ * @return the registry allowing to access contributed
+ * {@link IPresentationReconciler}s.
* @since 1.0
*/
public synchronized PresentationReconcilerRegistry getPresentationReconcilerRegistry() {
@@ -99,7 +129,8 @@ public class GenericEditorPlugin extends AbstractUIPlugin {
}
/**
- * @return the registry allowing to access contributed {@link IAutoEditStrategy}s.
+ * @return the registry allowing to access contributed
+ * {@link IAutoEditStrategy}s.
* @since 1.1
*/
public synchronized AutoEditStrategyRegistry getAutoEditStrategyRegistry() {
@@ -108,4 +139,16 @@ public class GenericEditorPlugin extends AbstractUIPlugin {
}
return this.autoEditStrategyRegistry;
}
+
+ /**
+ * @return the registry allowing to access contributed
+ * {@link ICharacterPairMatcher}s.
+ * @since 1.2
+ */
+ public synchronized CharacterPairMatcherRegistry getCharacterPairMatcherRegistry() {
+ if (this.characterPairMatcherRegistry == null) {
+ this.characterPairMatcherRegistry = new CharacterPairMatcherRegistry();
+ }
+ return this.characterPairMatcherRegistry;
+ }
}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPluginPreferenceInitializer.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPluginPreferenceInitializer.java
new file mode 100644
index 00000000000..40ed2349648
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPluginPreferenceInitializer.java
@@ -0,0 +1,89 @@
+/**
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
+ */
+package org.eclipse.ui.internal.genericeditor.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.resource.ColorRegistry;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Preference initializer for Generic Editor plug-in.
+ *
+ * @since 1.2
+ */
+public class GenericEditorPluginPreferenceInitializer extends AbstractPreferenceInitializer {
+
+ @Override
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = GenericEditorPreferenceConstants.getPreferenceStore();
+ GenericEditorPreferenceConstants.initializeDefaultValues(store);
+ }
+
+ public static void setThemeBasedPreferences(IPreferenceStore store, boolean fireEvent) {
+ ColorRegistry registry = null;
+ if (PlatformUI.isWorkbenchRunning())
+ registry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
+
+ setDefault(store, GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR,
+ findRGB(registry, IGenericEditorThemeConstants.EDITOR_MATCHING_BRACKETS_COLOR, new RGB(127, 0, 85)),
+ fireEvent);
+
+ }
+
+ /**
+ * Sets the default value and fires a property change event if necessary.
+ *
+ * @param store the preference store
+ * @param key the preference key
+ * @param newValue the new value
+ * @param fireEvent <code>false</code> if no event should be fired
+ * @since 1.2
+ */
+ private static void setDefault(IPreferenceStore store, String key, RGB newValue, boolean fireEvent) {
+ if (!fireEvent) {
+ PreferenceConverter.setDefault(store, key, newValue);
+ return;
+ }
+
+ RGB oldValue = null;
+ if (store.isDefault(key))
+ oldValue = PreferenceConverter.getDefaultColor(store, key);
+
+ PreferenceConverter.setDefault(store, key, newValue);
+
+ if (oldValue != null && !oldValue.equals(newValue))
+ store.firePropertyChangeEvent(key, oldValue, newValue);
+ }
+
+ /**
+ * Returns the RGB for the given key in the given color registry.
+ *
+ * @param registry the color registry
+ * @param key the key for the constant in the registry
+ * @param defaultRGB the default RGB if no entry is found
+ * @return RGB the RGB
+ * @since 1.2
+ */
+ private static RGB findRGB(ColorRegistry registry, String key, RGB defaultRGB) {
+ if (registry == null)
+ return defaultRGB;
+
+ RGB rgb = registry.getRGB(key);
+ if (rgb != null)
+ return rgb;
+
+ return defaultRGB;
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPreferenceConstants.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPreferenceConstants.java
new file mode 100644
index 00000000000..75dda6478d0
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/GenericEditorPreferenceConstants.java
@@ -0,0 +1,106 @@
+/**
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
+ */
+package org.eclipse.ui.internal.genericeditor.preferences;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.internal.genericeditor.GenericEditorPlugin;
+
+/**
+ * Preference constants used in the Generic Editor preference store. Clients
+ * should only read the Generic Editor preference store using these values.
+ * Clients are not allowed to modify the preference store programmatically.
+ * <p>
+ * This class it is not intended to be instantiated or subclassed by clients.
+ * </p>
+ *
+ * @since 1.2
+ *
+ * @noinstantiate This class is not intended to be instantiated by clients.
+ * @noextend This class is not intended to be subclassed by clients.
+ */
+public class GenericEditorPreferenceConstants {
+
+ private GenericEditorPreferenceConstants() {
+
+ }
+
+ /**
+ * A named preference that controls whether bracket matching highlighting is
+ * turned on or off.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ *
+ * @since 1.2
+ */
+ public final static String EDITOR_MATCHING_BRACKETS = "matchingBrackets"; //$NON-NLS-1$
+
+ /**
+ * A named preference that holds the color used to highlight matching brackets.
+ * <p>
+ * Value is of type <code>String</code>. A RGB color value encoded as a string
+ * using class <code>PreferenceConverter</code>
+ * </p>
+ *
+ * @see org.eclipse.jface.resource.StringConverter
+ * @see org.eclipse.jface.preference.PreferenceConverter
+ *
+ * @since 1.2
+ */
+ public final static String EDITOR_MATCHING_BRACKETS_COLOR = "matchingBracketsColor"; //$NON-NLS-1$
+
+ /**
+ * A named preference that controls whether bracket at caret location is
+ * highlighted or not.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ *
+ * @since 1.2
+ */
+ public final static String EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION = "highlightBracketAtCaretLocation"; //$NON-NLS-1$
+
+ /**
+ * A named preference that controls whether enclosing bracket matching
+ * highlighting is turned on or off.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ *
+ * @since 1.2
+ */
+ public final static String EDITOR_ENCLOSING_BRACKETS = "enclosingBrackets"; //$NON-NLS-1$
+
+ /**
+ * Returns the Generic Editor preference store.
+ *
+ * @return the Generic Editor preference store
+ */
+ public static IPreferenceStore getPreferenceStore() {
+ return GenericEditorPlugin.getDefault().getPreferenceStore();
+ }
+
+ /**
+ * Initializes the given preference store with the default values.
+ *
+ * @param store the preference store to be initialized
+ *
+ * @since 1.2
+ */
+ public static void initializeDefaultValues(IPreferenceStore store) {
+ store.setDefault(GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS, true);
+ store.setDefault(GenericEditorPreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION, false);
+ store.setDefault(GenericEditorPreferenceConstants.EDITOR_ENCLOSING_BRACKETS, false);
+ // Colors that are set by the current theme
+ GenericEditorPluginPreferenceInitializer.setThemeBasedPreferences(store, false);
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/IGenericEditorThemeConstants.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/IGenericEditorThemeConstants.java
new file mode 100644
index 00000000000..aad591abfd8
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/preferences/IGenericEditorThemeConstants.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 538111 - [generic editor] Extension point for ICharacterPairMatcher
+ */
+package org.eclipse.ui.internal.genericeditor.preferences;
+
+import org.eclipse.ui.internal.genericeditor.GenericEditorPlugin;
+
+/**
+ * Defines the constants used in the <code>org.eclipse.ui.themes</code>
+ * extension contributed by this plug-in.
+ *
+ * @since 1.2
+ */
+public interface IGenericEditorThemeConstants {
+
+ String ID_PREFIX = GenericEditorPlugin.BUNDLE_ID + "."; //$NON-NLS-1$
+
+ /**
+ * Theme constant for the color used to highlight matching brackets.
+ */
+ public final String EDITOR_MATCHING_BRACKETS_COLOR = ID_PREFIX
+ + GenericEditorPreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
+
+}

Back to the top