Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 22282 Details for
Bug 71271
add "insert spaces for tabs" function to sse editors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
org.eclipse.wst.html.ui.patch
org.eclipse.wst.html.ui.patch (text/plain), 14.60 KB, created by
Amy Wu
on 2005-06-02 17:41:10 EDT
(
hide
)
Description:
org.eclipse.wst.html.ui.patch
Filename:
MIME Type:
Creator:
Amy Wu
Created:
2005-06-02 17:41:10 EDT
Size:
14.60 KB
patch
obsolete
>Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /home/webtools/wst/components/html/plugins/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.2 >diff -u -r1.2 MANIFEST.MF >--- META-INF/MANIFEST.MF 1 Jun 2005 00:13:13 -0000 1.2 >+++ META-INF/MANIFEST.MF 2 Jun 2005 21:23:45 -0000 >@@ -8,6 +8,7 @@ > Bundle-Localization: plugin > Export-Package: org.eclipse.wst.html.internal.validation, > org.eclipse.wst.html.ui.internal, >+ org.eclipse.wst.html.ui.internal.autoedit, > org.eclipse.wst.html.ui.internal.contentassist, > org.eclipse.wst.html.ui.internal.contentoutline, > org.eclipse.wst.html.ui.internal.contentproperties.ui, >Index: src/org/eclipse/wst/html/ui/internal/provisional/StructuredTextViewerConfigurationHTML.java >=================================================================== >RCS file: /home/webtools/wst/components/html/plugins/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/provisional/StructuredTextViewerConfigurationHTML.java,v >retrieving revision 1.1 >diff -u -r1.1 StructuredTextViewerConfigurationHTML.java >--- src/org/eclipse/wst/html/ui/internal/provisional/StructuredTextViewerConfigurationHTML.java 18 Apr 2005 08:00:16 -0000 1.1 >+++ src/org/eclipse/wst/html/ui/internal/provisional/StructuredTextViewerConfigurationHTML.java 2 Jun 2005 21:23:45 -0000 >@@ -12,7 +12,9 @@ > > import java.util.ArrayList; > import java.util.List; >+import java.util.Vector; > >+import org.eclipse.core.runtime.Preferences; > import org.eclipse.jdt.ui.PreferenceConstants; > import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration; > import org.eclipse.jdt.ui.text.JavaTextTools; >@@ -38,7 +40,9 @@ > import org.eclipse.wst.css.core.internal.provisional.text.ICSSPartitionTypes; > import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor; > import org.eclipse.wst.css.ui.internal.style.LineStyleProviderForEmbeddedCSS; >+import org.eclipse.wst.html.core.internal.HTMLCorePlugin; > import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl; >+import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames; > import org.eclipse.wst.html.core.internal.provisional.text.IHTMLPartitionTypes; > import org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML; > import org.eclipse.wst.html.ui.internal.contentassist.HTMLContentAssistProcessor; >@@ -79,27 +83,30 @@ > InformationPresenter fInformationPresenter = null; > > private JavaSourceViewerConfiguration fJavaSourceViewerConfiguration; >- >+ > public StructuredTextViewerConfigurationHTML() { > super(); > } >- >+ > public StructuredTextViewerConfigurationHTML(IPreferenceStore store) { > super(store); > } >- >- >- /* (non-Javadoc) >- * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, java.lang.String) >+ >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, >+ * java.lang.String) > */ > public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { > List allStrategies = new ArrayList(0); >- >+ > IAutoEditStrategy[] superStrategies = super.getAutoEditStrategies(sourceViewer, contentType); > for (int i = 0; i < superStrategies.length; i++) { > allStrategies.add(superStrategies[i]); > } >- >+ > if (contentType == IHTMLPartitionTypes.HTML_DEFAULT || contentType == IHTMLPartitionTypes.HTML_DECLARATION) { > allStrategies.add(new StructuredAutoEditStrategyXML()); > } >@@ -248,6 +255,7 @@ > fInformationPresenter.setInformationProvider(javascriptInformationProvider, IHTMLPartitionTypes.SCRIPT); > > fInformationPresenter.setSizeConstraints(60, 10, true, true); >+ fInformationPresenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); > } > > return fInformationPresenter; >@@ -302,8 +310,7 @@ > if (contentTypeId != null) > fReconciler.setValidatorStrategy(createValidatorStrategy(contentTypeId)); > } >- } >- finally { >+ } finally { > if (sModel != null) > sModel.releaseFromRead(); > } >@@ -319,26 +326,21 @@ > if (hoverDescs[i].isEnabled() && EditorUtility.computeStateMask(hoverDescs[i].getModifierString()) == stateMask) { > String hoverType = hoverDescs[i].getId(); > if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType)) { >- // treat specially if it's JavaScript, HTML otherwise >- if (contentType.equals(IHTMLPartitionTypes.SCRIPT)) { >+ // check if script or html is needed >+ if (contentType == IHTMLPartitionTypes.SCRIPT) { > hover = new JavaScriptBestMatchHoverProcessor(); >- } >- else { >+ } else if (contentType == IHTMLPartitionTypes.HTML_DEFAULT) { > hover = new HTMLBestMatchHoverProcessor(); > } >- } >- else if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType)) { >+ } else if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType)) { > hover = new ProblemAnnotationHoverProcessor(); >- } >- else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType)) { >+ } else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType)) { > hover = new AnnotationHoverProcessor(); >- } >- else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) { >- // treat specially if it's JavaScript, HTML otherwise >- if (contentType.equals(IHTMLPartitionTypes.SCRIPT)) { >+ } else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) { >+ // check if script or html is needed >+ if (contentType == IHTMLPartitionTypes.SCRIPT) { > hover = new JavaScriptTagInfoHoverProcessor(); >- } >- else { >+ } else if (contentType == IHTMLPartitionTypes.HTML_DEFAULT) { > hover = new HTMLTagInfoHoverProcessor(); > } > } >@@ -358,4 +360,46 @@ > if (fInformationPresenter != null) > fInformationPresenter.uninstall(); > } >+ >+ public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { >+ Vector vector = new Vector(); >+ >+ // prefix[0] is either '\t' or ' ' x tabWidth, depending on preference >+ Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences(); >+ int indentationWidth = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE); >+ String indentCharPref = preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR); >+ boolean useSpaces = HTMLCorePreferenceNames.SPACE.equals(indentCharPref); >+ >+ for (int i = 0; i <= indentationWidth; i++) { >+ StringBuffer prefix = new StringBuffer(); >+ boolean appendTab = false; >+ >+ if (useSpaces) { >+ for (int j = 0; j + i < indentationWidth; j++) >+ prefix.append(' '); >+ >+ if (i != 0) >+ appendTab = true; >+ } else { >+ for (int j = 0; j < i; j++) >+ prefix.append(' '); >+ >+ if (i != indentationWidth) >+ appendTab = true; >+ } >+ >+ if (appendTab) { >+ prefix.append('\t'); >+ vector.add(prefix.toString()); >+ // remove the tab so that indentation - tab is also an indent >+ // prefix >+ prefix.deleteCharAt(prefix.length() - 1); >+ } >+ vector.add(prefix.toString()); >+ } >+ >+ vector.add(""); //$NON-NLS-1$ >+ >+ return (String[]) vector.toArray(new String[vector.size()]); >+ } > } >\ No newline at end of file >Index: src/org/eclipse/wst/html/ui/internal/autoedit/StructuredAutoEditStrategyHTML.java >=================================================================== >RCS file: src/org/eclipse/wst/html/ui/internal/autoedit/StructuredAutoEditStrategyHTML.java >diff -N src/org/eclipse/wst/html/ui/internal/autoedit/StructuredAutoEditStrategyHTML.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/html/ui/internal/autoedit/StructuredAutoEditStrategyHTML.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,165 @@ >+/******************************************************************************* >+ * Copyright (c) 2005 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.html.ui.internal.autoedit; >+ >+import org.eclipse.core.runtime.Preferences; >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.DocumentCommand; >+import org.eclipse.jface.text.IAutoEditStrategy; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.texteditor.ITextEditor; >+import org.eclipse.ui.texteditor.ITextEditorExtension3; >+import org.eclipse.wst.html.core.internal.HTMLCorePlugin; >+import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames; >+import org.eclipse.wst.html.ui.internal.Logger; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager; >+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; >+import org.eclipse.wst.sse.ui.internal.StructuredDocumentCommand; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; >+import org.w3c.dom.Node; >+ >+public class StructuredAutoEditStrategyHTML implements IAutoEditStrategy { >+ public void customizeDocumentCommand(IDocument document, DocumentCommand command) { >+ StructuredDocumentCommand structuredDocumentCommand = (StructuredDocumentCommand) command; >+ Object textEditor = getActiveTextEditor(); >+ if (!(textEditor instanceof ITextEditorExtension3 && ((ITextEditorExtension3) textEditor).getInsertMode() == ITextEditorExtension3.SMART_INSERT)) >+ return; >+ >+ IStructuredModel model = null; >+ try { >+ model = StructuredModelManager.getModelManager().getExistingModelForRead(document); >+ if (model != null) { >+ if (structuredDocumentCommand.text != null) { >+ smartInsertForComment(structuredDocumentCommand, document, model); >+ smartInsertForEndTag(structuredDocumentCommand, document, model); >+ } >+ } >+ } finally { >+ if (model != null) >+ model.releaseFromRead(); >+ } >+ >+ // spaces for tab character >+ if (command.text != null && command.text.length() > 0 && command.text.charAt(0) == '\t') >+ smartInsertForTab(command, document); >+ } >+ >+ private boolean isCommentNode(IDOMNode node) { >+ return (node != null && node instanceof IDOMElement && ((IDOMElement) node).isCommentTag()); >+ } >+ >+ private boolean isDocumentNode(IDOMNode node) { >+ return (node != null && node.getNodeType() == Node.DOCUMENT_NODE); >+ } >+ >+ private void smartInsertForComment(StructuredDocumentCommand structuredDocumentCommand, IDocument document, IStructuredModel model) { >+ try { >+ if (structuredDocumentCommand.text.equals("-") && document.getLength() >= 3 && document.get(structuredDocumentCommand.offset - 3, 3).equals("<!-")) { //$NON-NLS-1$ //$NON-NLS-2$ >+ structuredDocumentCommand.text += " "; //$NON-NLS-1$ >+ structuredDocumentCommand.doit = false; >+ structuredDocumentCommand.addCommand(structuredDocumentCommand.offset, 0, " -->", null); //$NON-NLS-1$ >+ } >+ } catch (BadLocationException e) { >+ Logger.logException(e); >+ } >+ >+ } >+ >+ private void smartInsertForEndTag(StructuredDocumentCommand structuredDocumentCommand, IDocument document, IStructuredModel model) { >+ try { >+ if (structuredDocumentCommand.text.equals("/") && document.getLength() >= 1 && document.get(structuredDocumentCommand.offset - 1, 1).equals("<")) { //$NON-NLS-1$ //$NON-NLS-2$ >+ IDOMNode parentNode = (IDOMNode) ((IDOMNode) model.getIndexedRegion(structuredDocumentCommand.offset - 1)).getParentNode(); >+ if (isCommentNode(parentNode)) { >+ // loop and find non comment node parent >+ while (parentNode != null && isCommentNode(parentNode)) { >+ parentNode = (IDOMNode) parentNode.getParentNode(); >+ } >+ } >+ >+ if (!isDocumentNode(parentNode)) { >+ IStructuredDocumentRegion endTagStructuredDocumentRegion = parentNode.getEndStructuredDocumentRegion(); >+ if (endTagStructuredDocumentRegion == null) { >+ structuredDocumentCommand.text += parentNode.getNodeName(); >+ structuredDocumentCommand.text += ">"; //$NON-NLS-1$ >+ } >+ } >+ } >+ } catch (BadLocationException e) { >+ Logger.logException(e); >+ } >+ } >+ >+ /** >+ * Insert spaces for tabs >+ * >+ * @param command >+ */ >+ private void smartInsertForTab(DocumentCommand command, IDocument document) { >+ // tab key was pressed. now check preferences to see if need to insert >+ // spaces instead of tab >+ Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences(); >+ if (HTMLCorePreferenceNames.SPACE.equals(preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR))) { >+ int indentationWidth = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE); >+ >+ StringBuffer indent = new StringBuffer(); >+ if (indentationWidth != 0) { >+ int indentSize = indentationWidth; >+ try { >+ IRegion firstLine = document.getLineInformationOfOffset(command.offset); >+ int offsetInLine = command.offset - firstLine.getOffset(); >+ int remainder = offsetInLine % indentationWidth; >+ >+ indentSize = indentationWidth - remainder; >+ } catch (BadLocationException e) { >+ Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >+ } >+ >+ for (int i = 0; i < indentSize; i++) >+ indent.append(' '); >+ } >+ >+ // replace \t characters with spaces >+ command.text = indent.toString(); >+ } >+ } >+ >+ /** >+ * Return the active text editor if possible, otherwise the active editor >+ * part. >+ * >+ * @return >+ */ >+ private Object getActiveTextEditor() { >+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); >+ if (window != null) { >+ IWorkbenchPage page = window.getActivePage(); >+ if (page != null) { >+ IEditorPart editor = page.getActiveEditor(); >+ if (editor != null) { >+ if (editor instanceof ITextEditor) >+ return editor; >+ ITextEditor textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class); >+ if (textEditor != null) >+ return textEditor; >+ return editor; >+ } >+ } >+ } >+ return null; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 71271
:
22276
|
22277
|
22278
|
22279
|
22281
| 22282 |
22283
|
22284
|
22285
|
22286
|
22287
|
22288
|
22289
|
24931
|
24932
|
24933