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 22279 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.css.ui.patch
org.eclipse.wst.css.ui.patch (text/plain), 9.23 KB, created by
Amy Wu
on 2005-06-02 17:38:15 EDT
(
hide
)
Description:
org.eclipse.wst.css.ui.patch
Filename:
MIME Type:
Creator:
Amy Wu
Created:
2005-06-02 17:38:15 EDT
Size:
9.23 KB
patch
obsolete
>Index: src/org/eclipse/wst/css/ui/internal/autoedit/StructuredAutoEditStrategyCSS.java >=================================================================== >RCS file: /home/webtools/wst/components/css/plugins/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/autoedit/StructuredAutoEditStrategyCSS.java,v >retrieving revision 1.3 >diff -u -r1.3 StructuredAutoEditStrategyCSS.java >--- src/org/eclipse/wst/css/ui/internal/autoedit/StructuredAutoEditStrategyCSS.java 25 May 2005 21:11:11 -0000 1.3 >+++ src/org/eclipse/wst/css/ui/internal/autoedit/StructuredAutoEditStrategyCSS.java 2 Jun 2005 21:23:05 -0000 >@@ -11,7 +11,14 @@ > 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.css.core.internal.CSSCorePlugin; > import org.eclipse.wst.css.core.internal.parserz.CSSRegionContexts; >@@ -21,9 +28,8 @@ > import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; > import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; > import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; >-import org.eclipse.wst.sse.ui.internal.autoedit.BasicAutoEditStrategy; > >-public class StructuredAutoEditStrategyCSS extends BasicAutoEditStrategy { >+public class StructuredAutoEditStrategyCSS implements IAutoEditStrategy { > protected IStructuredDocument structuredDocument = null; > > class CompoundRegion { >@@ -153,6 +159,10 @@ > } > } > // */ >+ >+ // spaces for tab character >+ if (command.text != null && command.text.length() > 0 && command.text.charAt(0) == '\t') >+ smartInsertForTab(command, document); > } > > /** >@@ -501,21 +511,80 @@ > > > private String getIndentString() { >- String indent = ""; //$NON-NLS-1$ >+ StringBuffer indent = new StringBuffer(); > > Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences(); > if (preferences != null) { >- String indentChar = " "; //$NON-NLS-1$ >+ char indentChar = ' '; > String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR); > if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) { >- indentChar = "\t"; //$NON-NLS-1$ >+ indentChar = '\t'; > } > int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE); > > for (int i = 0; i < indentationWidth; i++) { >- indent += indentChar; >+ indent.append(indentChar); > } > } >- return indent; >+ return 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; >+ } >+ >+ /** >+ * 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 = CSSCorePlugin.getDefault().getPluginPreferences(); >+ if (CSSCorePreferenceNames.SPACE.equals(preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR))) { >+ int indentationWidth = preferences.getInt(CSSCorePreferenceNames.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(); >+ } > } > } >Index: src/org/eclipse/wst/css/ui/internal/contentassist/CSSProposalGenerator.java >=================================================================== >RCS file: /home/webtools/wst/components/css/plugins/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/contentassist/CSSProposalGenerator.java,v >retrieving revision 1.3 >diff -u -r1.3 CSSProposalGenerator.java >--- src/org/eclipse/wst/css/ui/internal/contentassist/CSSProposalGenerator.java 25 May 2005 21:11:11 -0000 1.3 >+++ src/org/eclipse/wst/css/ui/internal/contentassist/CSSProposalGenerator.java 2 Jun 2005 21:23:05 -0000 >@@ -212,21 +212,21 @@ > > > private String getIndentString() { >- String indent = ""; //$NON-NLS-1$ >+ StringBuffer indent = new StringBuffer(); > > Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences(); > if (preferences != null) { >- String indentChar = " "; //$NON-NLS-1$ >+ char indentChar = ' '; > String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR); > if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) { >- indentChar = "\t"; //$NON-NLS-1$ >+ indentChar = '\t'; > } > int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE); > > for (int i = 0; i < indentationWidth; i++) { >- indent += indentChar; >+ indent.append(indentChar); > } > } >- return indent; >+ return indent.toString(); > } > } >\ No newline at end of file >Index: src/org/eclipse/wst/css/ui/internal/provisional/StructuredTextViewerConfigurationCSS.java >=================================================================== >RCS file: /home/webtools/wst/components/css/plugins/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/provisional/StructuredTextViewerConfigurationCSS.java,v >retrieving revision 1.1 >diff -u -r1.1 StructuredTextViewerConfigurationCSS.java >--- src/org/eclipse/wst/css/ui/internal/provisional/StructuredTextViewerConfigurationCSS.java 18 Apr 2005 07:59:04 -0000 1.1 >+++ src/org/eclipse/wst/css/ui/internal/provisional/StructuredTextViewerConfigurationCSS.java 2 Jun 2005 21:23:05 -0000 >@@ -10,7 +10,9 @@ > > import java.util.ArrayList; > import java.util.List; >+import java.util.Vector; > >+import org.eclipse.core.runtime.Preferences; > import org.eclipse.jface.text.IAutoEditStrategy; > import org.eclipse.jface.text.ITextHover; > import org.eclipse.jface.text.contentassist.ContentAssistant; >@@ -19,7 +21,9 @@ > import org.eclipse.jface.text.formatter.IContentFormatter; > import org.eclipse.jface.text.formatter.MultiPassContentFormatter; > import org.eclipse.jface.text.source.ISourceViewer; >+import org.eclipse.wst.css.core.internal.CSSCorePlugin; > import org.eclipse.wst.css.core.internal.format.FormatProcessorCSS; >+import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceNames; > import org.eclipse.wst.css.core.internal.provisional.text.ICSSPartitionTypes; > import org.eclipse.wst.css.ui.internal.autoedit.StructuredAutoEditStrategyCSS; > import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor; >@@ -120,4 +124,46 @@ > } > return super.getTextHover(sourceViewer, contentType, stateMask); > } >+ >+ public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { >+ Vector vector = new Vector(); >+ >+ // prefix[0] is either '\t' or ' ' x tabWidth, depending on preference >+ Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences(); >+ int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE); >+ String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR); >+ boolean useSpaces = CSSCorePreferenceNames.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
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