[521209] Add/enable Typing preferences
diff --git a/json/bundles/org.eclipse.wst.json.ui/META-INF/MANIFEST.MF b/json/bundles/org.eclipse.wst.json.ui/META-INF/MANIFEST.MF index 3748aeb..a81c6a6 100755 --- a/json/bundles/org.eclipse.wst.json.ui/META-INF/MANIFEST.MF +++ b/json/bundles/org.eclipse.wst.json.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.wst.json.ui;singleton:=true -Bundle-Version: 1.0.400.qualifier +Bundle-Version: 1.0.500.qualifier Bundle-Activator: org.eclipse.wst.json.ui.internal.JSONUIPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin
diff --git a/json/bundles/org.eclipse.wst.json.ui/plugin.xml b/json/bundles/org.eclipse.wst.json.ui/plugin.xml index 225573a..f278be8 100755 --- a/json/bundles/org.eclipse.wst.json.ui/plugin.xml +++ b/json/bundles/org.eclipse.wst.json.ui/plugin.xml
@@ -37,10 +37,12 @@ <documentationTextHover class="org.eclipse.wst.json.ui.internal.text.hover.JSONHoverProcessor" target="org.eclipse.wst.json.JSON" /> - <!--<provisionalConfiguration + <!-- + <provisionalConfiguration type="characterpairmatcher" class="org.eclipse.wst.json.ui.internal.text.JSONDocumentRegionEdgeMatcher" - target="org.eclipse.wst.json.core.jsonsource" />--> + target="org.eclipse.wst.json.core.jsonsource" /> + --> <provisionalConfiguration type="foldingstrategy" class="org.eclipse.wst.json.ui.internal.projection.JSONFoldingStrategy" @@ -151,13 +153,12 @@ id="org.eclipse.wst.json.ui.internal.preferences.JSONCatalogPreferencePage"> <keywordReference id="org.eclipse.wst.json.ui.jsoncatalog"/> </page> - <!-- <page name="%JSON_Typing" category="org.eclipse.wst.sse.ui.preferences.json.source" class="org.eclipse.wst.json.ui.internal.preferences.JSONTypingPreferencePage" id="org.eclipse.wst.sse.ui.preferences.json.typing"> - </page>--> + </page> <page name="%JSON_Validator.name" category="org.eclipse.wst.json.ui.preferences.json.json"
diff --git a/json/bundles/org.eclipse.wst.json.ui/pom.xml b/json/bundles/org.eclipse.wst.json.ui/pom.xml index ea81b88..d12f2c9 100644 --- a/json/bundles/org.eclipse.wst.json.ui/pom.xml +++ b/json/bundles/org.eclipse.wst.json.ui/pom.xml
@@ -21,6 +21,6 @@ <groupId>org.eclipse.webtools.sourceediting</groupId> <artifactId>org.eclipse.wst.json.ui</artifactId> - <version>1.0.400-SNAPSHOT</version> + <version>1.0.500-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project>
diff --git a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.java b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.java index be825c5..61b7031 100644 --- a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.java +++ b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.java
@@ -1,5 +1,5 @@ /** - * Copyright (c) 2013-2016 Angelo ZERR. + * Copyright (c) 2013-2021 Angelo ZERR. and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -119,6 +119,11 @@ public static String PrefsLabel_WrappingInsertLineBreak; public static String PrefsLabel_SelectorWhitespace; + public static String Automatically_close; + public static String Close_braces; + public static String Close_brackets; + public static String Close_strings; + public static String Creating_files_encoding; static {
diff --git a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.properties b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.properties index 1495191..971fdc4 100644 --- a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.properties +++ b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/JSONUIMessages.properties
@@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2015, 2018 IBM Corporation and others. +# Copyright (c) 2015, 2021 IBM Corporation and others. # This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 # which accompanies this distribution, and is available at @@ -107,3 +107,7 @@ The_url_field_is_required=The url field is required. Invalid_URL=Invalid url. +Automatically_close=Automatically close +Close_braces=Braces +Close_brackets=(Parentheses) and [square] brackets +Close_strings=Strings
diff --git a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONTypingPreferencePage.java b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONTypingPreferencePage.java new file mode 100644 index 0000000..4c15eb5 --- /dev/null +++ b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONTypingPreferencePage.java
@@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2008, 2021 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * + *******************************************************************************/ +package org.eclipse.wst.json.ui.internal.preferences; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.wst.json.ui.internal.JSONUIMessages; +import org.eclipse.wst.json.ui.internal.JSONUIPlugin; +import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferencePage; + +public class JSONTypingPreferencePage extends AbstractPreferencePage { + + private Button fCloseBraces; + private Button fCloseBrackets; + private Button fCloseStrings; + + protected Control createContents(Composite parent) { + Composite composite = super.createComposite(parent, 1); + + createAutoComplete(composite); + + setSize(composite); + loadPreferences(); + + return composite; + } + + private void createAutoComplete(Composite parent) { + Group group = createGroup(parent, 1); + + group.setText(JSONUIMessages.Automatically_close); + + fCloseBraces = createCheckBox(group, JSONUIMessages.Close_braces); + fCloseBrackets = createCheckBox(group, JSONUIMessages.Close_brackets); + fCloseStrings = createCheckBox(group, JSONUIMessages.Close_strings); + } + + public boolean performOk() { + boolean result = super.performOk(); + + JSONUIPlugin.getDefault().savePluginPreferences(); + + return result; + } + + protected void initializeValues() { + initCheckbox(fCloseBraces, JSONUIPreferenceNames.TYPING_CLOSE_BRACES); + initCheckbox(fCloseBrackets, JSONUIPreferenceNames.TYPING_CLOSE_BRACKETS); + initCheckbox(fCloseStrings, JSONUIPreferenceNames.TYPING_CLOSE_STRINGS); + } + + protected void performDefaults() { + defaultCheckbox(fCloseBraces, JSONUIPreferenceNames.TYPING_CLOSE_BRACES); + defaultCheckbox(fCloseBrackets, JSONUIPreferenceNames.TYPING_CLOSE_BRACKETS); + defaultCheckbox(fCloseStrings, JSONUIPreferenceNames.TYPING_CLOSE_STRINGS); + } + + protected void storeValues() { + getPreferenceStore().setValue(JSONUIPreferenceNames.TYPING_CLOSE_BRACES, (fCloseBraces != null) ? fCloseBraces.getSelection() : false); + getPreferenceStore().setValue(JSONUIPreferenceNames.TYPING_CLOSE_BRACKETS, (fCloseBrackets != null) ? fCloseBrackets.getSelection() : false); + getPreferenceStore().setValue(JSONUIPreferenceNames.TYPING_CLOSE_STRINGS, (fCloseStrings != null) ? fCloseStrings.getSelection() : false); + } + + protected IPreferenceStore doGetPreferenceStore() { + return JSONUIPlugin.getDefault().getPreferenceStore(); + } +}
diff --git a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceInitializer.java b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceInitializer.java index 7cfc169..286ab54 100644 --- a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceInitializer.java +++ b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceInitializer.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2020 IBM Corporation and others. + * Copyright (c) 2006, 2021 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -113,6 +113,10 @@ PreferenceConverter.setDefault(store, AppearancePreferenceNames.CODEASSIST_PARAMETERS_BACKGROUND, ColorHelper.findRGB(registry, AppearancePreferenceNames.CODEASSIST_PARAMETERS_BACKGROUND, new RGB(255, 255, 255))); PreferenceConverter.setDefault(store, AppearancePreferenceNames.CODEASSIST_PARAMETERS_FOREGROUND, ColorHelper.findRGB(registry, AppearancePreferenceNames.CODEASSIST_PARAMETERS_FOREGROUND, new RGB(0, 0, 0))); + store.setDefault(JSONUIPreferenceNames.TYPING_CLOSE_BRACES, true); + store.setDefault(JSONUIPreferenceNames.TYPING_CLOSE_BRACKETS, false); + store.setDefault(JSONUIPreferenceNames.TYPING_CLOSE_STRINGS, true); + // hover help preferences are not part of base text editor preference String mod2Name = Action.findModifierString(SWT.MOD2); /*
diff --git a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceNames.java b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceNames.java index da9bfed..75eed0a 100644 --- a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceNames.java +++ b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/preferences/JSONUIPreferenceNames.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2016 IBM Corporation and others. + * Copyright (c) 2005, 2021 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -144,4 +144,30 @@ */ public static final String INSERT_SINGLE_SUGGESTION = "insertSingleSuggestion"; //$NON-NLS-1$ + /** + * The key to store the option for auto-completing strings (" and ') while + * typing. + * <p> + * Value is of type <code>boolean</code>. + * </p> + */ + public static final String TYPING_CLOSE_STRINGS = "closeStrings"; //$NON-NLS-1$ + + /** + * The key to store the option for auto-completing braces ({) while + * typing. + * <p> + * Value is of type <code>boolean</code>. + * </p> + */ + public static final String TYPING_CLOSE_BRACES = "closeBraces"; //$NON-NLS-1$ + + /** + * The key to store the option for auto-completing brackets ([ and () while + * typing. + * <p> + * Value is of type <code>boolean</code>. + * </p> + */ + public static final String TYPING_CLOSE_BRACKETS = "closeBrackets"; //$NON-NLS-1$ }
diff --git a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/text/JSONCharacterPairInserter.java b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/text/JSONCharacterPairInserter.java index c9383fc..a5e4f5d 100644 --- a/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/text/JSONCharacterPairInserter.java +++ b/json/bundles/org.eclipse.wst.json.ui/src/org/eclipse/wst/json/ui/internal/text/JSONCharacterPairInserter.java
@@ -12,20 +12,30 @@ */ package org.eclipse.wst.json.ui.internal.text; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.link.ILinkedModeListener; import org.eclipse.jface.text.link.LinkedModeModel; import org.eclipse.jface.text.link.LinkedModeUI.ExitFlags; import org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.wst.json.ui.internal.JSONUIPlugin; +import org.eclipse.wst.json.ui.internal.preferences.JSONUIPreferenceNames; import org.eclipse.wst.sse.ui.typing.AbstractCharacterPairInserter; /** - * Character pair insrter for JSON to auto close JSON character like '{', '['. + * Character pair inserter for JSON to auto close JSON character like '{', '['. * */ -public class JSONCharacterPairInserter extends AbstractCharacterPairInserter { +public class JSONCharacterPairInserter extends AbstractCharacterPairInserter implements IPropertyChangeListener { + + private boolean fCloseStrings; + private boolean fCloseBrackets; + private boolean fCloseBraces; public boolean hasPair(char c) { switch (c) { @@ -39,6 +49,15 @@ } } + @Override + public void initialize() { + IPreferenceStore store = JSONUIPlugin.getDefault().getPreferenceStore(); + fCloseStrings = store.getBoolean(JSONUIPreferenceNames.TYPING_CLOSE_STRINGS); + fCloseBraces = store.getBoolean(JSONUIPreferenceNames.TYPING_CLOSE_BRACES); + fCloseBrackets = store.getBoolean(JSONUIPreferenceNames.TYPING_CLOSE_BRACKETS); + store.addPropertyChangeListener(this); + } + protected char getPair(char c) { switch (c) { case '\'': @@ -98,4 +117,28 @@ IDocument document) { return new ExitPolicy(exit, escape, document); } + public void propertyChange(PropertyChangeEvent event) { + if (JSONUIPreferenceNames.TYPING_CLOSE_BRACKETS.equals(event.getProperty())) + fCloseBrackets = ((Boolean) event.getNewValue()).booleanValue(); + else if (JSONUIPreferenceNames.TYPING_CLOSE_BRACES.equals(event.getProperty())) + fCloseBraces = ((Boolean) event.getNewValue()).booleanValue(); + else if (JSONUIPreferenceNames.TYPING_CLOSE_STRINGS.equals(event.getProperty())) + fCloseStrings = ((Boolean) event.getNewValue()).booleanValue(); + } + + @Override + protected boolean shouldPair(ISourceViewer viewer, char c) { + switch (c) { + case '\'' : + case '"' : + return fCloseStrings; + case '[' : + case '(' : + return fCloseBrackets; + case '{' : + return fCloseBraces; + default : + return false; + } + } }
diff --git a/json/features/org.eclipse.wst.json_ui.feature/feature.xml b/json/features/org.eclipse.wst.json_ui.feature/feature.xml index b5f42a1..00d001a 100644 --- a/json/features/org.eclipse.wst.json_ui.feature/feature.xml +++ b/json/features/org.eclipse.wst.json_ui.feature/feature.xml
@@ -11,11 +11,10 @@ Contributors: IBM Corporation - initial API and implementation --> - <feature id="org.eclipse.wst.json_ui.feature" label="%featureName" - version="1.1.8.qualifier" + version="1.1.9.qualifier" provider-name="%providerName" plugin="org.eclipse.wst.json.ui" license-feature="org.eclipse.license"
diff --git a/json/features/org.eclipse.wst.json_ui.feature/pom.xml b/json/features/org.eclipse.wst.json_ui.feature/pom.xml index ad16bf5..9e3e729 100644 --- a/json/features/org.eclipse.wst.json_ui.feature/pom.xml +++ b/json/features/org.eclipse.wst.json_ui.feature/pom.xml
@@ -21,7 +21,7 @@ <groupId>org.eclipse.webtools.sourceediting</groupId> <artifactId>org.eclipse.wst.json_ui.feature</artifactId> - <version>1.1.8-SNAPSHOT</version> + <version>1.1.9-SNAPSHOT</version> <packaging>eclipse-feature</packaging> <build>