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/src/org/eclipse/ui/internal/genericeditor/preferences
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/src/org/eclipse/ui/internal/genericeditor/preferences')
-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
3 files changed, 226 insertions, 0 deletions
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