|
Lines 10-29
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.wst.html.ui.internal.autoedit; |
11 |
package org.eclipse.wst.html.ui.internal.autoedit; |
| 12 |
|
12 |
|
| 13 |
import org.eclipse.core.runtime.Preferences; |
|
|
| 14 |
import org.eclipse.jface.text.BadLocationException; |
13 |
import org.eclipse.jface.text.BadLocationException; |
| 15 |
import org.eclipse.jface.text.DocumentCommand; |
14 |
import org.eclipse.jface.text.DocumentCommand; |
| 16 |
import org.eclipse.jface.text.IAutoEditStrategy; |
15 |
import org.eclipse.jface.text.IAutoEditStrategy; |
| 17 |
import org.eclipse.jface.text.IDocument; |
16 |
import org.eclipse.jface.text.IDocument; |
| 18 |
import org.eclipse.jface.text.IRegion; |
|
|
| 19 |
import org.eclipse.ui.IEditorPart; |
17 |
import org.eclipse.ui.IEditorPart; |
| 20 |
import org.eclipse.ui.IWorkbenchPage; |
18 |
import org.eclipse.ui.IWorkbenchPage; |
| 21 |
import org.eclipse.ui.IWorkbenchWindow; |
19 |
import org.eclipse.ui.IWorkbenchWindow; |
| 22 |
import org.eclipse.ui.PlatformUI; |
20 |
import org.eclipse.ui.PlatformUI; |
| 23 |
import org.eclipse.ui.texteditor.ITextEditor; |
21 |
import org.eclipse.ui.texteditor.ITextEditor; |
| 24 |
import org.eclipse.ui.texteditor.ITextEditorExtension3; |
22 |
import org.eclipse.ui.texteditor.ITextEditorExtension3; |
| 25 |
import org.eclipse.wst.html.core.internal.HTMLCorePlugin; |
|
|
| 26 |
import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames; |
| 27 |
import org.eclipse.wst.html.ui.internal.Logger; |
23 |
import org.eclipse.wst.html.ui.internal.Logger; |
| 28 |
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; |
24 |
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; |
| 29 |
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager; |
25 |
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager; |
|
Lines 53-62
Link Here
|
| 53 |
if (model != null) |
49 |
if (model != null) |
| 54 |
model.releaseFromRead(); |
50 |
model.releaseFromRead(); |
| 55 |
} |
51 |
} |
| 56 |
|
|
|
| 57 |
// spaces for tab character |
| 58 |
if (command.text != null && command.text.length() > 0 && command.text.charAt(0) == '\t') |
| 59 |
smartInsertForTab(command, document); |
| 60 |
} |
52 |
} |
| 61 |
|
53 |
|
| 62 |
private boolean isCommentNode(IDOMNode node) { |
54 |
private boolean isCommentNode(IDOMNode node) { |
|
Lines 105-144
Link Here
|
| 105 |
} |
97 |
} |
| 106 |
|
98 |
|
| 107 |
/** |
99 |
/** |
| 108 |
* Insert spaces for tabs |
|
|
| 109 |
* |
| 110 |
* @param command |
| 111 |
*/ |
| 112 |
private void smartInsertForTab(DocumentCommand command, IDocument document) { |
| 113 |
// tab key was pressed. now check preferences to see if need to insert |
| 114 |
// spaces instead of tab |
| 115 |
Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences(); |
| 116 |
if (HTMLCorePreferenceNames.SPACE.equals(preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR))) { |
| 117 |
int indentationWidth = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE); |
| 118 |
|
| 119 |
StringBuffer indent = new StringBuffer(); |
| 120 |
if (indentationWidth != 0) { |
| 121 |
int indentSize = indentationWidth; |
| 122 |
try { |
| 123 |
IRegion firstLine = document.getLineInformationOfOffset(command.offset); |
| 124 |
int offsetInLine = command.offset - firstLine.getOffset(); |
| 125 |
int remainder = offsetInLine % indentationWidth; |
| 126 |
|
| 127 |
indentSize = indentationWidth - remainder; |
| 128 |
} catch (BadLocationException e) { |
| 129 |
Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); |
| 130 |
} |
| 131 |
|
| 132 |
for (int i = 0; i < indentSize; i++) |
| 133 |
indent.append(' '); |
| 134 |
} |
| 135 |
|
| 136 |
// replace \t characters with spaces |
| 137 |
command.text = indent.toString(); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Return the active text editor if possible, otherwise the active editor |
100 |
* Return the active text editor if possible, otherwise the active editor |
| 143 |
* part. |
101 |
* part. |
| 144 |
* |
102 |
* |