Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornitind2008-03-27 07:16:38 +0000
committernitind2008-03-27 07:16:38 +0000
commitf4a9c3fe2b15016a29463572a3205aeb0772227c (patch)
tree06be0d868d98178287a4e60c0c7112b43a28e26a /bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal
parentddb7e7f638b25245ddd9b27e99eeb336c846b1a6 (diff)
downloadwebtools.sourceediting-f4a9c3fe2b15016a29463572a3205aeb0772227c.tar.gz
webtools.sourceediting-f4a9c3fe2b15016a29463572a3205aeb0772227c.tar.xz
webtools.sourceediting-f4a9c3fe2b15016a29463572a3205aeb0772227c.zip
[144313] Preference to turn off auto-insertion
Diffstat (limited to 'bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal')
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java5
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties5
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java12
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTypingPreferencePage.java106
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java5
-rw-r--r--bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java29
6 files changed, 158 insertions, 4 deletions
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
index 864bdd1404..b460f6d255 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
@@ -266,6 +266,11 @@ public class XMLUIMessages extends NLS {
public static String OpenFileFromSource_tooltip; // Resource bundle
public static String OpenFileFromSource_description; // Resource bundle
public static String XMLContentOutlineConfiguration_0;
+ public static String XMLTyping_Auto_Complete;
+ public static String XMLTyping_Auto_Remove;
+ public static String XMLTyping_Complete_Comments;
+ public static String XMLTyping_Complete_End_Tags;
+ public static String XMLTyping_Remove_End_Tags;
public static String StructureSelectEnclosing_label;
public static String StructureSelectEnclosing_tooltip;
public static String StructureSelectEnclosing_description;
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
index 70d4493e65..e44d9aaa31 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
@@ -298,6 +298,11 @@ OpenFileFromSource_label=Op&en Selection
OpenFileFromSource_tooltip=Open an editor on the selected link
OpenFileFromSource_description=Open an editor on the selected link
XMLContentOutlineConfiguration_0=Show Attributes
+XMLTyping_Auto_Complete=Automatically close
+XMLTyping_Auto_Remove=Automatically remove
+XMLTyping_Complete_Comments=&Comments
+XMLTyping_Complete_End_Tags=&End tags
+XMLTyping_Remove_End_Tags=E&nd tags when creating empty self-closing tags
StructureSelectEnclosing_label=Enclosing Element
StructureSelectEnclosing_tooltip=Expand selection to include enclosing element
StructureSelectEnclosing_description=Expand selection to include enclosing element
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java
index 494a4e178b..df619e79f0 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java
@@ -28,6 +28,8 @@ import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentReg
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.ui.internal.Logger;
+import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
+import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames;
import org.w3c.dom.Node;
/**
@@ -62,6 +64,10 @@ public class StructuredAutoEditStrategyXML implements IAutoEditStrategy {
}
}
}
+
+ private boolean isPreferenceEnabled(String key) {
+ return (key != null && XMLUIPlugin.getDefault().getPreferenceStore().getBoolean(key));
+ }
private boolean isCommentNode(IDOMNode node) {
return ((node != null) && (node instanceof IDOMElement) && ((IDOMElement) node).isCommentTag());
@@ -82,7 +88,7 @@ public class StructuredAutoEditStrategyXML implements IAutoEditStrategy {
private void smartRemoveEndTag(DocumentCommand command, IDocument document, IStructuredModel model) {
try {
// An opening tag is now a self-terminated end-tag
- if ("/".equals(command.text) && ">".equals(document.get(command.offset, 1))) { //$NON-NLS-1$ //$NON-NLS-2$
+ if ("/".equals(command.text) && ">".equals(document.get(command.offset, 1)) && isPreferenceEnabled(XMLUIPreferenceNames.TYPING_REMOVE_END_TAGS)) { //$NON-NLS-1$ //$NON-NLS-2$
IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset);
if (node != null && !node.hasChildNodes()) {
IStructuredDocumentRegion region = node.getEndStructuredDocumentRegion();
@@ -99,7 +105,7 @@ public class StructuredAutoEditStrategyXML implements IAutoEditStrategy {
private void smartInsertForComment(DocumentCommand command, IDocument document, IStructuredModel model) {
try {
- if (command.text.equals("-") && (document.getLength() >= 3) && document.get(command.offset - 3, 3).equals("<!-")) { //$NON-NLS-1$ //$NON-NLS-2$
+ if (command.text.equals("-") && (document.getLength() >= 3) && document.get(command.offset - 3, 3).equals("<!-") && isPreferenceEnabled(XMLUIPreferenceNames.TYPING_COMPLETE_COMMENTS)) { //$NON-NLS-1$ //$NON-NLS-2$
command.text += " -->"; //$NON-NLS-1$
command.shiftsCaret = false;
command.caretOffset = command.offset + 2;
@@ -114,7 +120,7 @@ public class StructuredAutoEditStrategyXML implements IAutoEditStrategy {
private void smartInsertForEndTag(DocumentCommand command, IDocument document, IStructuredModel model) {
try {
- if (command.text.equals("/") && (document.getLength() >= 1) && document.get(command.offset - 1, 1).equals("<")) { //$NON-NLS-1$ //$NON-NLS-2$
+ if (command.text.equals("/") && (document.getLength() >= 1) && document.get(command.offset - 1, 1).equals("<") && isPreferenceEnabled(XMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS)) { //$NON-NLS-1$ //$NON-NLS-2$
IDOMNode parentNode = (IDOMNode) ((IDOMNode) model.getIndexedRegion(command.offset - 1)).getParentNode();
if (isCommentNode(parentNode)) {
// loop and find non comment node parent
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTypingPreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTypingPreferencePage.java
new file mode 100644
index 0000000000..a30a7dd7e8
--- /dev/null
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTypingPreferencePage.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *
+ *******************************************************************************/
+package org.eclipse.wst.xml.ui.internal.preferences;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.layout.GridData;
+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.ui.PlatformUI;
+import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferencePage;
+import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
+import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
+import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds;
+
+public class XMLTypingPreferencePage extends AbstractPreferencePage {
+
+ private Button fCloseComment;
+ private Button fCloseEndTag;
+ private Button fRemoveEndTag;
+
+ protected Control createContents(Composite parent) {
+ Composite composite = super.createComposite(parent, 1);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_FILES_HELPID);
+
+ createAutoComplete(composite);
+ createAutoRemove(composite);
+
+ setSize(composite);
+ loadPreferences();
+
+ return composite;
+ }
+
+ private void createAutoComplete(Composite parent) {
+ Group group = createGroup(parent, 2);
+
+ group.setText(XMLUIMessages.XMLTyping_Auto_Complete);
+
+ fCloseComment = createCheckBox(group, XMLUIMessages.XMLTyping_Complete_Comments);
+ ((GridData) fCloseComment.getLayoutData()).horizontalSpan = 2;
+
+ fCloseEndTag = createCheckBox(group, XMLUIMessages.XMLTyping_Complete_End_Tags);
+ ((GridData) fCloseEndTag.getLayoutData()).horizontalSpan = 2;
+
+ }
+
+ private void createAutoRemove(Composite parent) {
+ Group group = createGroup(parent, 2);
+
+ group.setText(XMLUIMessages.XMLTyping_Auto_Remove);
+
+ fRemoveEndTag = createCheckBox(group, XMLUIMessages.XMLTyping_Remove_End_Tags);
+ ((GridData) fRemoveEndTag.getLayoutData()).horizontalSpan = 2;
+ }
+
+ public boolean performOk() {
+ boolean result = super.performOk();
+
+ XMLUIPlugin.getDefault().savePluginPreferences();
+
+ return result;
+ }
+
+ protected void initializeValues() {
+ initCheckbox(fCloseComment, XMLUIPreferenceNames.TYPING_COMPLETE_COMMENTS);
+ initCheckbox(fCloseEndTag, XMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS);
+ initCheckbox(fRemoveEndTag, XMLUIPreferenceNames.TYPING_REMOVE_END_TAGS);
+ }
+
+ protected void performDefaults() {
+ defaultCheckbox(fCloseComment, XMLUIPreferenceNames.TYPING_COMPLETE_COMMENTS);
+ defaultCheckbox(fCloseEndTag, XMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS);
+ defaultCheckbox(fRemoveEndTag, XMLUIPreferenceNames.TYPING_REMOVE_END_TAGS);
+ }
+
+ private void initCheckbox(Button box, String key) {
+ if(box != null && key != null)
+ box.setSelection(getPreferenceStore().getBoolean(key));
+ }
+
+ private void defaultCheckbox(Button box, String key) {
+ if(box != null && key != null)
+ box.setSelection(getPreferenceStore().getDefaultBoolean(key));
+ }
+
+ protected void storeValues() {
+ getPreferenceStore().setValue(XMLUIPreferenceNames.TYPING_COMPLETE_COMMENTS, (fCloseComment != null) ? fCloseComment.getSelection() : false);
+ getPreferenceStore().setValue(XMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS, (fCloseEndTag != null) ? fCloseEndTag.getSelection() : false);
+ getPreferenceStore().setValue(XMLUIPreferenceNames.TYPING_REMOVE_END_TAGS, (fRemoveEndTag != null) ? fRemoveEndTag.getSelection() : false);
+ }
+
+ protected IPreferenceStore doGetPreferenceStore() {
+ return XMLUIPlugin.getDefault().getPreferenceStore();
+ }
+}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java
index 8a9bcfdc69..80ac7a4910 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java
@@ -122,6 +122,11 @@ public class XMLUIPreferenceInitializer extends AbstractPreferenceInitializer {
if (template != null)
templateName = template.getName();
store.setDefault(XMLUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName);
+
+ // Defaults for the Typing preference page
+ store.setDefault(XMLUIPreferenceNames.TYPING_COMPLETE_COMMENTS, true);
+ store.setDefault(XMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS, true);
+ store.setDefault(XMLUIPreferenceNames.TYPING_REMOVE_END_TAGS, true);
}
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java
index 293e5781cb..d71a7a3652 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 IBM Corporation 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
@@ -92,4 +92,31 @@ public class XMLUIPreferenceNames {
* </p>
*/
public static final String NEW_FILE_TEMPLATE_NAME = "newFileTemplateName"; //$NON-NLS-1$
+
+ /**
+ * The key to store the option for auto-completing comments while
+ * typing.
+ * <p>
+ * Value is of type <code>boolean</code>.
+ * </p>
+ */
+ public static final String TYPING_COMPLETE_COMMENTS = "completeComments"; //$NON-NLS-1$
+
+ /**
+ * The key to store the option for auto-completing end-tags after entering
+ * <code>&lt;/</code>
+ * <p>
+ * Value is of type <code>boolean</code>.
+ * </p>
+ */
+ public static final String TYPING_COMPLETE_END_TAGS = "completeEndTags"; //$NON-NLS-1$
+
+ /**
+ * The key to store the option for removing an end-tag if the start tag is
+ * converted to an empty-tag.
+ * <p>
+ * Value is of type <code>boolean</code>.
+ * </p>
+ */
+ public static final String TYPING_REMOVE_END_TAGS = "removeEndTags"; //$NON-NLS-1$
}

Back to the top