|
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 |
* |