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

(-)src/org/eclipse/wst/css/ui/internal/autoedit/StructuredAutoEditStrategyCSS.java (-7 / +76 lines)
Lines 11-17 Link Here
11
import org.eclipse.core.runtime.Preferences;
11
import org.eclipse.core.runtime.Preferences;
12
import org.eclipse.jface.text.BadLocationException;
12
import org.eclipse.jface.text.BadLocationException;
13
import org.eclipse.jface.text.DocumentCommand;
13
import org.eclipse.jface.text.DocumentCommand;
14
import org.eclipse.jface.text.IAutoEditStrategy;
14
import org.eclipse.jface.text.IDocument;
15
import org.eclipse.jface.text.IDocument;
16
import org.eclipse.jface.text.IRegion;
17
import org.eclipse.ui.IEditorPart;
18
import org.eclipse.ui.IWorkbenchPage;
19
import org.eclipse.ui.IWorkbenchWindow;
20
import org.eclipse.ui.PlatformUI;
21
import org.eclipse.ui.texteditor.ITextEditor;
15
import org.eclipse.ui.texteditor.ITextEditorExtension3;
22
import org.eclipse.ui.texteditor.ITextEditorExtension3;
16
import org.eclipse.wst.css.core.internal.CSSCorePlugin;
23
import org.eclipse.wst.css.core.internal.CSSCorePlugin;
17
import org.eclipse.wst.css.core.internal.parserz.CSSRegionContexts;
24
import org.eclipse.wst.css.core.internal.parserz.CSSRegionContexts;
Lines 21-29 Link Here
21
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
28
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
22
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
29
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
23
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
30
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
24
import org.eclipse.wst.sse.ui.internal.autoedit.BasicAutoEditStrategy;
25
31
26
public class StructuredAutoEditStrategyCSS extends BasicAutoEditStrategy {
32
public class StructuredAutoEditStrategyCSS implements IAutoEditStrategy {
27
	protected IStructuredDocument structuredDocument = null;
33
	protected IStructuredDocument structuredDocument = null;
28
34
29
	class CompoundRegion {
35
	class CompoundRegion {
Lines 153-158 Link Here
153
			}
159
			}
154
		}
160
		}
155
		// */
161
		// */
162
		
163
		// spaces for tab character
164
		if (command.text != null && command.text.length() > 0 && command.text.charAt(0) == '\t')
165
			smartInsertForTab(command, document);
156
	}
166
	}
157
167
158
	/**
168
	/**
Lines 501-521 Link Here
501
511
502
512
503
	private String getIndentString() {
513
	private String getIndentString() {
504
		String indent = ""; //$NON-NLS-1$
514
		StringBuffer indent = new StringBuffer();
505
515
506
		Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
516
		Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
507
		if (preferences != null) {
517
		if (preferences != null) {
508
			String indentChar = " "; //$NON-NLS-1$
518
			char indentChar = ' ';
509
			String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
519
			String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
510
			if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) {
520
			if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) {
511
				indentChar = "\t"; //$NON-NLS-1$
521
				indentChar = '\t';
512
			}
522
			}
513
			int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
523
			int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
514
524
515
			for (int i = 0; i < indentationWidth; i++) {
525
			for (int i = 0; i < indentationWidth; i++) {
516
				indent += indentChar;
526
				indent.append(indentChar);
517
			}
527
			}
518
		}
528
		}
519
		return indent;
529
		return indent.toString();
530
	}
531
	
532
	/**
533
	 * Return the active text editor if possible, otherwise the active editor
534
	 * part.
535
	 * 
536
	 * @return
537
	 */
538
	private Object getActiveTextEditor() {
539
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
540
		if (window != null) {
541
			IWorkbenchPage page = window.getActivePage();
542
			if (page != null) {
543
				IEditorPart editor = page.getActiveEditor();
544
				if (editor != null) {
545
					if (editor instanceof ITextEditor)
546
						return editor;
547
					ITextEditor textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
548
					if (textEditor != null)
549
						return textEditor;
550
					return editor;
551
				}
552
			}
553
		}
554
		return null;
555
	}
556
	
557
	/**
558
	 * Insert spaces for tabs
559
	 * 
560
	 * @param command
561
	 */
562
	private void smartInsertForTab(DocumentCommand command, IDocument document) {
563
		// tab key was pressed. now check preferences to see if need to insert
564
		// spaces instead of tab
565
		Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
566
		if (CSSCorePreferenceNames.SPACE.equals(preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR))) {
567
			int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
568
569
			StringBuffer indent = new StringBuffer();
570
			if (indentationWidth != 0) {
571
				int indentSize = indentationWidth;
572
				try {
573
					IRegion firstLine = document.getLineInformationOfOffset(command.offset);
574
					int offsetInLine = command.offset - firstLine.getOffset();
575
					int remainder = offsetInLine % indentationWidth;
576
577
					indentSize = indentationWidth - remainder;
578
				} catch (BadLocationException e) {
579
					Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
580
				}
581
582
				for (int i = 0; i < indentSize; i++)
583
					indent.append(' ');
584
			}
585
586
			// replace \t characters with spaces
587
			command.text = indent.toString();
588
		}
520
	}
589
	}
521
}
590
}
(-)src/org/eclipse/wst/css/ui/internal/contentassist/CSSProposalGenerator.java (-5 / +5 lines)
Lines 212-232 Link Here
212
	
212
	
213
213
214
	private String getIndentString() {
214
	private String getIndentString() {
215
		String indent = ""; //$NON-NLS-1$
215
		StringBuffer indent = new StringBuffer();
216
216
217
		Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
217
		Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
218
		if (preferences != null) {
218
		if (preferences != null) {
219
			String indentChar = " "; //$NON-NLS-1$
219
			char indentChar = ' ';
220
			String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
220
			String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
221
			if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) {
221
			if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) {
222
				indentChar = "\t"; //$NON-NLS-1$
222
				indentChar = '\t';
223
			}
223
			}
224
			int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
224
			int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
225
225
226
			for (int i = 0; i < indentationWidth; i++) {
226
			for (int i = 0; i < indentationWidth; i++) {
227
				indent += indentChar;
227
				indent.append(indentChar);
228
			}
228
			}
229
		}
229
		}
230
		return indent;
230
		return indent.toString();
231
	}
231
	}
232
}
232
}
(-)src/org/eclipse/wst/css/ui/internal/provisional/StructuredTextViewerConfigurationCSS.java (+46 lines)
Lines 10-16 Link Here
10
10
11
import java.util.ArrayList;
11
import java.util.ArrayList;
12
import java.util.List;
12
import java.util.List;
13
import java.util.Vector;
13
14
15
import org.eclipse.core.runtime.Preferences;
14
import org.eclipse.jface.text.IAutoEditStrategy;
16
import org.eclipse.jface.text.IAutoEditStrategy;
15
import org.eclipse.jface.text.ITextHover;
17
import org.eclipse.jface.text.ITextHover;
16
import org.eclipse.jface.text.contentassist.ContentAssistant;
18
import org.eclipse.jface.text.contentassist.ContentAssistant;
Lines 19-25 Link Here
19
import org.eclipse.jface.text.formatter.IContentFormatter;
21
import org.eclipse.jface.text.formatter.IContentFormatter;
20
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
22
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
21
import org.eclipse.jface.text.source.ISourceViewer;
23
import org.eclipse.jface.text.source.ISourceViewer;
24
import org.eclipse.wst.css.core.internal.CSSCorePlugin;
22
import org.eclipse.wst.css.core.internal.format.FormatProcessorCSS;
25
import org.eclipse.wst.css.core.internal.format.FormatProcessorCSS;
26
import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceNames;
23
import org.eclipse.wst.css.core.internal.provisional.text.ICSSPartitionTypes;
27
import org.eclipse.wst.css.core.internal.provisional.text.ICSSPartitionTypes;
24
import org.eclipse.wst.css.ui.internal.autoedit.StructuredAutoEditStrategyCSS;
28
import org.eclipse.wst.css.ui.internal.autoedit.StructuredAutoEditStrategyCSS;
25
import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor;
29
import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor;
Lines 120-123 Link Here
120
		}
124
		}
121
		return super.getTextHover(sourceViewer, contentType, stateMask);
125
		return super.getTextHover(sourceViewer, contentType, stateMask);
122
	}
126
	}
127
	
128
	public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
129
		Vector vector = new Vector();
130
131
		// prefix[0] is either '\t' or ' ' x tabWidth, depending on preference
132
		Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
133
		int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
134
		String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
135
		boolean useSpaces = CSSCorePreferenceNames.SPACE.equals(indentCharPref);
136
137
		for (int i = 0; i <= indentationWidth; i++) {
138
			StringBuffer prefix = new StringBuffer();
139
			boolean appendTab = false;
140
141
			if (useSpaces) {
142
				for (int j = 0; j + i < indentationWidth; j++)
143
					prefix.append(' ');
144
145
				if (i != 0)
146
					appendTab = true;
147
			} else {
148
				for (int j = 0; j < i; j++)
149
					prefix.append(' ');
150
151
				if (i != indentationWidth)
152
					appendTab = true;
153
			}
154
155
			if (appendTab) {
156
				prefix.append('\t');
157
				vector.add(prefix.toString());
158
				// remove the tab so that indentation - tab is also an indent
159
				// prefix
160
				prefix.deleteCharAt(prefix.length() - 1);
161
			}
162
			vector.add(prefix.toString());
163
		}
164
165
		vector.add(""); //$NON-NLS-1$
166
167
		return (String[]) vector.toArray(new String[vector.size()]);
168
	}
123
}
169
}

Return to bug 71271