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 22288 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.xml.ui.patch
org.eclipse.wst.xml.ui.patch (text/plain), 13.56 KB, created by
Amy Wu
on 2005-06-02 17:45:29 EDT
(
hide
)
Description:
org.eclipse.wst.xml.ui.patch
Filename:
MIME Type:
Creator:
Amy Wu
Created:
2005-06-02 17:45:29 EDT
Size:
13.56 KB
patch
obsolete
>Index: src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java >=================================================================== >RCS file: /home/webtools/wst/components/xml/plugins/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java,v >retrieving revision 1.10 >diff -u -r1.10 StructuredAutoEditStrategyXML.java >--- src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java 18 Apr 2005 07:59:12 -0000 1.10 >+++ src/org/eclipse/wst/xml/ui/internal/autoedit/StructuredAutoEditStrategyXML.java 2 Jun 2005 21:26:01 -0000 >@@ -12,22 +12,31 @@ > *******************************************************************************/ > package org.eclipse.wst.xml.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.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.sse.ui.internal.autoedit.BasicAutoEditStrategy; >+import org.eclipse.wst.xml.core.internal.XMLCorePlugin; >+import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; > import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; > import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; > import org.eclipse.wst.xml.ui.internal.Logger; > import org.w3c.dom.Node; > > >-public class StructuredAutoEditStrategyXML extends BasicAutoEditStrategy { >+public class StructuredAutoEditStrategyXML implements IAutoEditStrategy { > public void customizeDocumentCommand(IDocument document, DocumentCommand command) { > StructuredDocumentCommand structuredDocumentCommand = (StructuredDocumentCommand) command; > Object textEditor = getActiveTextEditor(); >@@ -47,6 +56,10 @@ > 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) { >@@ -57,24 +70,7 @@ > return (node != null && node.getNodeType() == Node.DOCUMENT_NODE); > } > >- protected boolean isEndTagRequired(IDOMNode node) { >- >- if (node == null) >- return false; >- return node.isContainer(); >- } >- >- protected boolean prefixedWith(IDocument document, int offset, String string) { >- >- try { >- return document.getLength() >= string.length() && document.get(offset - string.length(), string.length()).equals(string); >- } catch (BadLocationException e) { >- Logger.logException(e); >- return false; >- } >- } >- >- protected void smartInsertForComment(StructuredDocumentCommand structuredDocumentCommand, IDocument document, IStructuredModel model) { >+ 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$ >@@ -87,7 +83,7 @@ > > } > >- protected void smartInsertForEndTag(StructuredDocumentCommand structuredDocumentCommand, IDocument document, IStructuredModel model) { >+ 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(); >@@ -109,6 +105,64 @@ > } 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 = XMLCorePlugin.getDefault().getPluginPreferences(); >+ if (XMLCorePreferenceNames.SPACE.equals(preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR))) { >+ int indentationWidth = preferences.getInt(XMLCorePreferenceNames.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 Object >+ */ >+ 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; > } > } >Index: src/org/eclipse/wst/xml/ui/internal/provisional/StructuredTextViewerConfigurationXML.java >=================================================================== >RCS file: /home/webtools/wst/components/xml/plugins/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/StructuredTextViewerConfigurationXML.java,v >retrieving revision 1.1 >diff -u -r1.1 StructuredTextViewerConfigurationXML.java >--- src/org/eclipse/wst/xml/ui/internal/provisional/StructuredTextViewerConfigurationXML.java 18 Apr 2005 07:59:12 -0000 1.1 >+++ src/org/eclipse/wst/xml/ui/internal/provisional/StructuredTextViewerConfigurationXML.java 2 Jun 2005 21:26:01 -0000 >@@ -14,7 +14,9 @@ > > import java.util.ArrayList; > import java.util.List; >+import java.util.Vector; > >+import org.eclipse.core.runtime.Preferences; > import org.eclipse.jface.preference.IPreferenceStore; > import org.eclipse.jface.text.IAutoEditStrategy; > import org.eclipse.jface.text.IDocument; >@@ -48,6 +50,8 @@ > import org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor; > import org.eclipse.wst.sse.ui.internal.taginfo.TextHoverManager; > import org.eclipse.wst.sse.ui.internal.util.EditorUtility; >+import org.eclipse.wst.xml.core.internal.XMLCorePlugin; >+import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; > import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML; > import org.eclipse.wst.xml.core.internal.provisional.text.IXMLPartitions; > import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML; >@@ -65,31 +69,35 @@ > > /** > * This class provides >+ * > * @since 1.0 > */ > public class StructuredTextViewerConfigurationXML extends StructuredTextViewerConfiguration { >- >+ > InformationPresenter fInformationPresenter = null; > > public StructuredTextViewerConfigurationXML() { > super(); > } >- >+ > public StructuredTextViewerConfigurationXML(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 == IXMLPartitions.XML_DEFAULT) { > allStrategies.add(new StructuredAutoEditStrategyXML()); > } >@@ -183,6 +191,7 @@ > fInformationPresenter.setInformationProvider(xmlInformationProvider, IStructuredPartitionTypes.DEFAULT_PARTITION); > fInformationPresenter.setInformationProvider(xmlInformationProvider, IXMLPartitions.XML_DEFAULT); > fInformationPresenter.setSizeConstraints(60, 10, true, true); >+ fInformationPresenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); > } > return fInformationPresenter; > } >@@ -197,31 +206,31 @@ > } > > if (fReconciler == null) { >- fReconciler = new StructuredRegionProcessor(); >+ fReconciler = new StructuredRegionProcessor(); > fReconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); > } > > boolean reconcilingEnabled = fPreferenceStore.getBoolean(CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS); >- >- if(!reconcilingEnabled) >- return fReconciler; >- >+ >+ if (!reconcilingEnabled) >+ return fReconciler; >+ > // the second time through, the strategies are set > if (fReconciler != null) { > >- IDocument doc = ((StructuredTextEditor)editorPart).getDocumentProvider().getDocument(editorPart.getEditorInput()); >+ IDocument doc = ((StructuredTextEditor) editorPart).getDocumentProvider().getDocument(editorPart.getEditorInput()); > IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(doc); >- >+ > try { > > if (sModel != null) { >- >+ > IReconcilingStrategy markupStrategy = new StructuredTextReconcilingStrategyForMarkup((ITextEditor) editorPart); >- fReconciler.setReconcilingStrategy(markupStrategy, IXMLPartitions.XML_DEFAULT); >+ fReconciler.setReconcilingStrategy(markupStrategy, IXMLPartitions.XML_DEFAULT); > fReconciler.setDefaultStrategy(markupStrategy); > > String contentTypeId = sModel.getContentTypeIdentifier(); >- if(contentTypeId != null) >+ if (contentTypeId != null) > fReconciler.setValidatorStrategy(createValidatorStrategy(contentTypeId)); > } > } finally { >@@ -272,18 +281,20 @@ > fInformationPresenter.uninstall(); > } > } >- >- /* (non-Javadoc) >+ >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.ui.editors.text.TextSourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer) > */ > public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) { > if (sourceViewer == null || !fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED)) > return null; >- >+ > List allDetectors = new ArrayList(0); > allDetectors.add(new XMLHyperlinkDetector()); >- >- IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer); >+ >+ IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer); > for (int m = 0; m < superDetectors.length; m++) { > IHyperlinkDetector detector = superDetectors[m]; > if (!allDetectors.contains(detector)) { >@@ -292,4 +303,46 @@ > } > return (IHyperlinkDetector[]) allDetectors.toArray(new IHyperlinkDetector[0]); > } >+ >+ public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { >+ Vector vector = new Vector(); >+ >+ // prefix[0] is either '\t' or ' ' x tabWidth, depending on preference >+ Preferences preferences = XMLCorePlugin.getDefault().getPluginPreferences(); >+ int indentationWidth = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE); >+ String indentCharPref = preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR); >+ boolean useSpaces = XMLCorePreferenceNames.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()]); >+ } > }
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