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

(-)META-INF/MANIFEST.MF (+1 lines)
Lines 8-13 Link Here
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Export-Package: org.eclipse.wst.html.internal.validation,
9
Export-Package: org.eclipse.wst.html.internal.validation,
10
 org.eclipse.wst.html.ui.internal,
10
 org.eclipse.wst.html.ui.internal,
11
 org.eclipse.wst.html.ui.internal.autoedit,
11
 org.eclipse.wst.html.ui.internal.contentassist,
12
 org.eclipse.wst.html.ui.internal.contentassist,
12
 org.eclipse.wst.html.ui.internal.contentoutline,
13
 org.eclipse.wst.html.ui.internal.contentoutline,
13
 org.eclipse.wst.html.ui.internal.contentproperties.ui,
14
 org.eclipse.wst.html.ui.internal.contentproperties.ui,
(-)src/org/eclipse/wst/html/ui/internal/provisional/StructuredTextViewerConfigurationHTML.java (-24 / +68 lines)
Lines 12-18 Link Here
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.List;
14
import java.util.List;
15
import java.util.Vector;
15
16
17
import org.eclipse.core.runtime.Preferences;
16
import org.eclipse.jdt.ui.PreferenceConstants;
18
import org.eclipse.jdt.ui.PreferenceConstants;
17
import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration;
19
import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration;
18
import org.eclipse.jdt.ui.text.JavaTextTools;
20
import org.eclipse.jdt.ui.text.JavaTextTools;
Lines 38-44 Link Here
38
import org.eclipse.wst.css.core.internal.provisional.text.ICSSPartitionTypes;
40
import org.eclipse.wst.css.core.internal.provisional.text.ICSSPartitionTypes;
39
import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor;
41
import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor;
40
import org.eclipse.wst.css.ui.internal.style.LineStyleProviderForEmbeddedCSS;
42
import org.eclipse.wst.css.ui.internal.style.LineStyleProviderForEmbeddedCSS;
43
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
41
import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl;
44
import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl;
45
import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames;
42
import org.eclipse.wst.html.core.internal.provisional.text.IHTMLPartitionTypes;
46
import org.eclipse.wst.html.core.internal.provisional.text.IHTMLPartitionTypes;
43
import org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML;
47
import org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML;
44
import org.eclipse.wst.html.ui.internal.contentassist.HTMLContentAssistProcessor;
48
import org.eclipse.wst.html.ui.internal.contentassist.HTMLContentAssistProcessor;
Lines 79-105 Link Here
79
	InformationPresenter fInformationPresenter = null;
83
	InformationPresenter fInformationPresenter = null;
80
84
81
	private JavaSourceViewerConfiguration fJavaSourceViewerConfiguration;
85
	private JavaSourceViewerConfiguration fJavaSourceViewerConfiguration;
82
	
86
83
	public StructuredTextViewerConfigurationHTML() {
87
	public StructuredTextViewerConfigurationHTML() {
84
		super();
88
		super();
85
	}
89
	}
86
	
90
87
	public StructuredTextViewerConfigurationHTML(IPreferenceStore store) {
91
	public StructuredTextViewerConfigurationHTML(IPreferenceStore store) {
88
		super(store);
92
		super(store);
89
	}
93
	}
90
	
94
91
	
95
92
	/* (non-Javadoc)
96
	/*
93
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, java.lang.String)
97
	 * (non-Javadoc)
98
	 * 
99
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer,
100
	 *      java.lang.String)
94
	 */
101
	 */
95
	public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
102
	public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
96
		List allStrategies = new ArrayList(0);
103
		List allStrategies = new ArrayList(0);
97
		
104
98
		IAutoEditStrategy[] superStrategies = super.getAutoEditStrategies(sourceViewer, contentType);
105
		IAutoEditStrategy[] superStrategies = super.getAutoEditStrategies(sourceViewer, contentType);
99
		for (int i = 0; i < superStrategies.length; i++) {
106
		for (int i = 0; i < superStrategies.length; i++) {
100
			allStrategies.add(superStrategies[i]);
107
			allStrategies.add(superStrategies[i]);
101
		}
108
		}
102
		
109
103
		if (contentType == IHTMLPartitionTypes.HTML_DEFAULT || contentType == IHTMLPartitionTypes.HTML_DECLARATION) {
110
		if (contentType == IHTMLPartitionTypes.HTML_DEFAULT || contentType == IHTMLPartitionTypes.HTML_DECLARATION) {
104
			allStrategies.add(new StructuredAutoEditStrategyXML());
111
			allStrategies.add(new StructuredAutoEditStrategyXML());
105
		}
112
		}
Lines 248-253 Link Here
248
			fInformationPresenter.setInformationProvider(javascriptInformationProvider, IHTMLPartitionTypes.SCRIPT);
255
			fInformationPresenter.setInformationProvider(javascriptInformationProvider, IHTMLPartitionTypes.SCRIPT);
249
256
250
			fInformationPresenter.setSizeConstraints(60, 10, true, true);
257
			fInformationPresenter.setSizeConstraints(60, 10, true, true);
258
			fInformationPresenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
251
		}
259
		}
252
260
253
		return fInformationPresenter;
261
		return fInformationPresenter;
Lines 302-309 Link Here
302
					if (contentTypeId != null)
310
					if (contentTypeId != null)
303
						fReconciler.setValidatorStrategy(createValidatorStrategy(contentTypeId));
311
						fReconciler.setValidatorStrategy(createValidatorStrategy(contentTypeId));
304
				}
312
				}
305
			}
313
			} finally {
306
			finally {
307
				if (sModel != null)
314
				if (sModel != null)
308
					sModel.releaseFromRead();
315
					sModel.releaseFromRead();
309
			}
316
			}
Lines 319-344 Link Here
319
			if (hoverDescs[i].isEnabled() && EditorUtility.computeStateMask(hoverDescs[i].getModifierString()) == stateMask) {
326
			if (hoverDescs[i].isEnabled() && EditorUtility.computeStateMask(hoverDescs[i].getModifierString()) == stateMask) {
320
				String hoverType = hoverDescs[i].getId();
327
				String hoverType = hoverDescs[i].getId();
321
				if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType)) {
328
				if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType)) {
322
					// treat specially if it's JavaScript, HTML otherwise
329
					// check if script or html is needed
323
					if (contentType.equals(IHTMLPartitionTypes.SCRIPT)) {
330
					if (contentType == IHTMLPartitionTypes.SCRIPT) {
324
						hover = new JavaScriptBestMatchHoverProcessor();
331
						hover = new JavaScriptBestMatchHoverProcessor();
325
					}
332
					} else if (contentType == IHTMLPartitionTypes.HTML_DEFAULT) {
326
					else {
327
						hover = new HTMLBestMatchHoverProcessor();
333
						hover = new HTMLBestMatchHoverProcessor();
328
					}
334
					}
329
				}
335
				} else if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType)) {
330
				else if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType)) {
331
					hover = new ProblemAnnotationHoverProcessor();
336
					hover = new ProblemAnnotationHoverProcessor();
332
				}
337
				} else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType)) {
333
				else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType)) {
334
					hover = new AnnotationHoverProcessor();
338
					hover = new AnnotationHoverProcessor();
335
				}
339
				} else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) {
336
				else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) {
340
					// check if script or html is needed
337
					// treat specially if it's JavaScript, HTML otherwise
341
					if (contentType == IHTMLPartitionTypes.SCRIPT) {
338
					if (contentType.equals(IHTMLPartitionTypes.SCRIPT)) {
339
						hover = new JavaScriptTagInfoHoverProcessor();
342
						hover = new JavaScriptTagInfoHoverProcessor();
340
					}
343
					} else if (contentType == IHTMLPartitionTypes.HTML_DEFAULT) {
341
					else {
342
						hover = new HTMLTagInfoHoverProcessor();
344
						hover = new HTMLTagInfoHoverProcessor();
343
					}
345
					}
344
				}
346
				}
Lines 358-361 Link Here
358
		if (fInformationPresenter != null)
360
		if (fInformationPresenter != null)
359
			fInformationPresenter.uninstall();
361
			fInformationPresenter.uninstall();
360
	}
362
	}
363
364
	public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
365
		Vector vector = new Vector();
366
367
		// prefix[0] is either '\t' or ' ' x tabWidth, depending on preference
368
		Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences();
369
		int indentationWidth = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE);
370
		String indentCharPref = preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR);
371
		boolean useSpaces = HTMLCorePreferenceNames.SPACE.equals(indentCharPref);
372
373
		for (int i = 0; i <= indentationWidth; i++) {
374
			StringBuffer prefix = new StringBuffer();
375
			boolean appendTab = false;
376
377
			if (useSpaces) {
378
				for (int j = 0; j + i < indentationWidth; j++)
379
					prefix.append(' ');
380
381
				if (i != 0)
382
					appendTab = true;
383
			} else {
384
				for (int j = 0; j < i; j++)
385
					prefix.append(' ');
386
387
				if (i != indentationWidth)
388
					appendTab = true;
389
			}
390
391
			if (appendTab) {
392
				prefix.append('\t');
393
				vector.add(prefix.toString());
394
				// remove the tab so that indentation - tab is also an indent
395
				// prefix
396
				prefix.deleteCharAt(prefix.length() - 1);
397
			}
398
			vector.add(prefix.toString());
399
		}
400
401
		vector.add(""); //$NON-NLS-1$
402
403
		return (String[]) vector.toArray(new String[vector.size()]);
404
	}
361
}
405
}
(-)src/org/eclipse/wst/html/ui/internal/autoedit/StructuredAutoEditStrategyHTML.java (+165 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 Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.wst.html.ui.internal.autoedit;
12
13
import org.eclipse.core.runtime.Preferences;
14
import org.eclipse.jface.text.BadLocationException;
15
import org.eclipse.jface.text.DocumentCommand;
16
import org.eclipse.jface.text.IAutoEditStrategy;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.IRegion;
19
import org.eclipse.ui.IEditorPart;
20
import org.eclipse.ui.IWorkbenchPage;
21
import org.eclipse.ui.IWorkbenchWindow;
22
import org.eclipse.ui.PlatformUI;
23
import org.eclipse.ui.texteditor.ITextEditor;
24
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;
28
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
29
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
30
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
31
import org.eclipse.wst.sse.ui.internal.StructuredDocumentCommand;
32
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
33
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
34
import org.w3c.dom.Node;
35
36
public class StructuredAutoEditStrategyHTML implements IAutoEditStrategy {
37
	public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
38
		StructuredDocumentCommand structuredDocumentCommand = (StructuredDocumentCommand) command;
39
		Object textEditor = getActiveTextEditor();
40
		if (!(textEditor instanceof ITextEditorExtension3 && ((ITextEditorExtension3) textEditor).getInsertMode() == ITextEditorExtension3.SMART_INSERT))
41
			return;
42
43
		IStructuredModel model = null;
44
		try {
45
			model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
46
			if (model != null) {
47
				if (structuredDocumentCommand.text != null) {
48
					smartInsertForComment(structuredDocumentCommand, document, model);
49
					smartInsertForEndTag(structuredDocumentCommand, document, model);
50
				}
51
			}
52
		} finally {
53
			if (model != null)
54
				model.releaseFromRead();
55
		}
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
	}
61
62
	private boolean isCommentNode(IDOMNode node) {
63
		return (node != null && node instanceof IDOMElement && ((IDOMElement) node).isCommentTag());
64
	}
65
66
	private boolean isDocumentNode(IDOMNode node) {
67
		return (node != null && node.getNodeType() == Node.DOCUMENT_NODE);
68
	}
69
70
	private void smartInsertForComment(StructuredDocumentCommand structuredDocumentCommand, IDocument document, IStructuredModel model) {
71
		try {
72
			if (structuredDocumentCommand.text.equals("-") && document.getLength() >= 3 && document.get(structuredDocumentCommand.offset - 3, 3).equals("<!-")) { //$NON-NLS-1$ //$NON-NLS-2$
73
				structuredDocumentCommand.text += " "; //$NON-NLS-1$
74
				structuredDocumentCommand.doit = false;
75
				structuredDocumentCommand.addCommand(structuredDocumentCommand.offset, 0, " -->", null); //$NON-NLS-1$
76
			}
77
		} catch (BadLocationException e) {
78
			Logger.logException(e);
79
		}
80
81
	}
82
83
	private void smartInsertForEndTag(StructuredDocumentCommand structuredDocumentCommand, IDocument document, IStructuredModel model) {
84
		try {
85
			if (structuredDocumentCommand.text.equals("/") && document.getLength() >= 1 && document.get(structuredDocumentCommand.offset - 1, 1).equals("<")) { //$NON-NLS-1$ //$NON-NLS-2$
86
				IDOMNode parentNode = (IDOMNode) ((IDOMNode) model.getIndexedRegion(structuredDocumentCommand.offset - 1)).getParentNode();
87
				if (isCommentNode(parentNode)) {
88
					// loop and find non comment node parent
89
					while (parentNode != null && isCommentNode(parentNode)) {
90
						parentNode = (IDOMNode) parentNode.getParentNode();
91
					}
92
				}
93
94
				if (!isDocumentNode(parentNode)) {
95
					IStructuredDocumentRegion endTagStructuredDocumentRegion = parentNode.getEndStructuredDocumentRegion();
96
					if (endTagStructuredDocumentRegion == null) {
97
						structuredDocumentCommand.text += parentNode.getNodeName();
98
						structuredDocumentCommand.text += ">"; //$NON-NLS-1$
99
					}
100
				}
101
			}
102
		} catch (BadLocationException e) {
103
			Logger.logException(e);
104
		}
105
	}
106
107
	/**
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
143
	 * part.
144
	 * 
145
	 * @return
146
	 */
147
	private Object getActiveTextEditor() {
148
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
149
		if (window != null) {
150
			IWorkbenchPage page = window.getActivePage();
151
			if (page != null) {
152
				IEditorPart editor = page.getActiveEditor();
153
				if (editor != null) {
154
					if (editor instanceof ITextEditor)
155
						return editor;
156
					ITextEditor textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
157
					if (textEditor != null)
158
						return textEditor;
159
					return editor;
160
				}
161
			}
162
		}
163
		return null;
164
	}
165
}

Return to bug 71271