Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 71271 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java (-42 lines)
Lines 12-23 Link Here
12
 *******************************************************************************/
12
 *******************************************************************************/
13
package org.eclipse.wst.xml.ui.internal.autoedit;
13
package org.eclipse.wst.xml.ui.internal.autoedit;
14
14
15
import org.eclipse.core.runtime.Preferences;
16
import org.eclipse.jface.text.BadLocationException;
15
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.DocumentCommand;
16
import org.eclipse.jface.text.DocumentCommand;
18
import org.eclipse.jface.text.IAutoEditStrategy;
17
import org.eclipse.jface.text.IAutoEditStrategy;
19
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.IDocument;
20
import org.eclipse.jface.text.IRegion;
21
import org.eclipse.ui.IEditorPart;
19
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.IWorkbenchPage;
20
import org.eclipse.ui.IWorkbenchPage;
23
import org.eclipse.ui.IWorkbenchWindow;
21
import org.eclipse.ui.IWorkbenchWindow;
Lines 28-35 Link Here
28
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
26
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
29
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
27
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
30
import org.eclipse.wst.sse.ui.internal.StructuredDocumentCommand;
28
import org.eclipse.wst.sse.ui.internal.StructuredDocumentCommand;
31
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
32
import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
33
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
29
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
34
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
30
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
35
import org.eclipse.wst.xml.ui.internal.Logger;
31
import org.eclipse.wst.xml.ui.internal.Logger;
Lines 56-65 Link Here
56
			if (model != null)
52
			if (model != null)
57
				model.releaseFromRead();
53
				model.releaseFromRead();
58
		}
54
		}
59
60
		// spaces for tab character
61
		if (command.text != null && command.text.length() > 0 && command.text.charAt(0) == '\t')
62
			smartInsertForTab(command, document);
63
	}
55
	}
64
56
65
	private boolean isCommentNode(IDOMNode node) {
57
	private boolean isCommentNode(IDOMNode node) {
Lines 108-147 Link Here
108
	}
100
	}
109
101
110
	/**
102
	/**
111
	 * Insert spaces for tabs
112
	 * 
113
	 * @param command
114
	 */
115
	private void smartInsertForTab(DocumentCommand command, IDocument document) {
116
		// tab key was pressed. now check preferences to see if need to insert
117
		// spaces instead of tab
118
		Preferences preferences = XMLCorePlugin.getDefault().getPluginPreferences();
119
		if (XMLCorePreferenceNames.SPACE.equals(preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR))) {
120
			int indentationWidth = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE);
121
122
			StringBuffer indent = new StringBuffer();
123
			if (indentationWidth != 0) {
124
				int indentSize = indentationWidth;
125
				try {
126
					IRegion firstLine = document.getLineInformationOfOffset(command.offset);
127
					int offsetInLine = command.offset - firstLine.getOffset();
128
					int remainder = offsetInLine % indentationWidth;
129
130
					indentSize = indentationWidth - remainder;
131
				} catch (BadLocationException e) {
132
					Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
133
				}
134
135
				for (int i = 0; i < indentSize; i++)
136
					indent.append(' ');
137
			}
138
139
			// replace \t characters with spaces
140
			command.text = indent.toString();
141
		}
142
	}
143
	
144
	/**
145
	 * Return the active text editor if possible, otherwise the active editor
103
	 * Return the active text editor if possible, otherwise the active editor
146
	 * part.
104
	 * part.
147
	 * 
105
	 * 
(-)src/org/eclipse/wst/xml/ui/internal/provisional/StructuredTextViewerConfigurationXML.java (+4 lines)
Lines 55-60 Link Here
55
import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML;
55
import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML;
56
import org.eclipse.wst.xml.core.internal.provisional.text.IXMLPartitions;
56
import org.eclipse.wst.xml.core.internal.provisional.text.IXMLPartitions;
57
import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML;
57
import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML;
58
import org.eclipse.wst.xml.ui.internal.autoedit.AutoEditStrategyForTabs;
58
import org.eclipse.wst.xml.ui.internal.autoedit.StructuredAutoEditStrategyXML;
59
import org.eclipse.wst.xml.ui.internal.autoedit.StructuredAutoEditStrategyXML;
59
import org.eclipse.wst.xml.ui.internal.contentassist.NoRegionContentAssistProcessor;
60
import org.eclipse.wst.xml.ui.internal.contentassist.NoRegionContentAssistProcessor;
60
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor;
61
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor;
Lines 97-102 Link Here
97
		for (int i = 0; i < superStrategies.length; i++) {
98
		for (int i = 0; i < superStrategies.length; i++) {
98
			allStrategies.add(superStrategies[i]);
99
			allStrategies.add(superStrategies[i]);
99
		}
100
		}
101
		
102
		// add auto edit strategy that handles when tab key is pressed
103
		allStrategies.add(new AutoEditStrategyForTabs());
100
104
101
		if (contentType == IXMLPartitions.XML_DEFAULT) {
105
		if (contentType == IXMLPartitions.XML_DEFAULT) {
102
			allStrategies.add(new StructuredAutoEditStrategyXML());
106
			allStrategies.add(new StructuredAutoEditStrategyXML());
(-)src/org/eclipse/wst/xml/ui/internal/autoedit/AutoEditStrategyForTabs.java (+69 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *   IBM - Initial API and implementation
10
 *   Jens Lukowski/Innoopract - initial renaming/restructuring
11
 * 
12
 */
13
package org.eclipse.wst.xml.ui.internal.autoedit;
14
15
import org.eclipse.core.runtime.Preferences;
16
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.DocumentCommand;
18
import org.eclipse.jface.text.IAutoEditStrategy;
19
import org.eclipse.jface.text.IDocument;
20
import org.eclipse.jface.text.IRegion;
21
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
22
import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
23
import org.eclipse.wst.xml.ui.internal.Logger;
24
25
/**
26
 * AutoEditStrategy to handle characters inserted when Tab key is pressed
27
 */
28
public class AutoEditStrategyForTabs implements IAutoEditStrategy {
29
30
	public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
31
		// spaces for tab character
32
		if (command.text != null && command.text.length() > 0 && command.text.charAt(0) == '\t')
33
			smartInsertForTab(command, document);
34
	}
35
36
	/**
37
	 * Insert spaces for tabs
38
	 * 
39
	 * @param command
40
	 */
41
	private void smartInsertForTab(DocumentCommand command, IDocument document) {
42
		// tab key was pressed. now check preferences to see if need to insert
43
		// spaces instead of tab
44
		Preferences preferences = XMLCorePlugin.getDefault().getPluginPreferences();
45
		if (XMLCorePreferenceNames.SPACE.equals(preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR))) {
46
			int indentationWidth = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE);
47
48
			StringBuffer indent = new StringBuffer();
49
			if (indentationWidth != 0) {
50
				int indentSize = indentationWidth;
51
				try {
52
					IRegion firstLine = document.getLineInformationOfOffset(command.offset);
53
					int offsetInLine = command.offset - firstLine.getOffset();
54
					int remainder = offsetInLine % indentationWidth;
55
56
					indentSize = indentationWidth - remainder;
57
				} catch (BadLocationException e) {
58
					Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
59
				}
60
61
				for (int i = 0; i < indentSize; i++)
62
					indent.append(' ');
63
			}
64
65
			// replace \t characters with spaces
66
			command.text = indent.toString();
67
		}
68
	}
69
}

Return to bug 71271