Permalink
Browse files

Soft tabs for the HTML editor

  • Loading branch information...
erwan committed May 21, 2010
1 parent 80056de commit c3cb350afca790727181b26443bb2efdb5c858fb
@@ -310,12 +310,10 @@ protected ISourceViewer createSourceViewer(Composite parent,IVerticalRuler ruler
@Override
public void verifyText(VerifyEvent evt) {
String softTab = "";
if (useSoftTabs) {
if (useSoftTabs && evt.text.equals("\t")) {
String softTab = "";
for (int i = 0; i < softTabsWidth; i++) softTab = softTab + " ";
if (evt.text.equals("\t")) {
evt.text = softTab;
}
evt.text = softTab;
}
}
@@ -17,8 +17,8 @@ public HTMLConfiguration(HTMLEditor editor) {
super(editor);
}
public IReconciler getReconciler(ISourceViewer sourceViewer)
{
@Override
public IReconciler getReconciler(ISourceViewer sourceViewer) {
XMLReconcilingStrategy strategy = new XMLReconcilingStrategy();
strategy.setEditor((HTMLEditor)editor);
MonoReconciler reconciler = new MonoReconciler(strategy,false);
@@ -5,6 +5,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Position;
@@ -16,7 +17,9 @@
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Composite;
import org.playframework.playclipse.PlayPlugin;
import org.playframework.playclipse.editors.PlayEditor;
public class HTMLEditor extends PlayEditor {
@@ -31,11 +34,17 @@
public static final String KEYWORD_COLOR = "html_keyword_color";
public static final String STRING_COLOR = "html_string_color";
public static final String SOFT_TABS = "html_soft_tabs";
public static final String SOFT_TABS_WIDTH = "html_soft_tabs_width";
private ProjectionSupport projectionSupport;
public HTMLEditor() {
super();
setSourceViewerConfiguration(new HTMLConfiguration(this));
IPreferenceStore store = PlayPlugin.getDefault().getPreferenceStore();
useSoftTabs = store.getBoolean(SOFT_TABS);
softTabsWidth = store.getInt(SOFT_TABS_WIDTH);
}
public String[] getTypes() {
@@ -305,30 +314,30 @@ public void updateFoldingStructure(ArrayList<Position> positions) {
}
@Override
public void createPartControl(Composite parent)
{
public void createPartControl(Composite parent) {
super.createPartControl(parent);
ProjectionViewer viewer =(ProjectionViewer)getSourceViewer();
ProjectionViewer viewer = (ProjectionViewer)getSourceViewer();
projectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors());
projectionSupport.install();
//turn projection mode on
viewer.doOperation(ProjectionViewer.TOGGLE);
annotationModel = viewer.getProjectionAnnotationModel();
}
@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles)
{
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
// ensure decoration support has been created and configured.
getSourceViewerDecorationSupport(viewer);
viewer.getTextWidget().addVerifyListener(this);
return viewer;
}
@Override
public void propertyChange(PropertyChangeEvent event) {
String key = event.getProperty();
if (key.equals(SOFT_TABS)) {
useSoftTabs = ((Boolean)event.getNewValue()).booleanValue();
}
super.propertyChange(event);
}
}
@@ -101,9 +101,7 @@ public String getStylePref(String type) {
@Override
public void propertyChange(PropertyChangeEvent event) {
String key = event.getProperty();
System.out.println("handlePrefChanged: " + key);
if (key.equals(SOFT_TABS)) {
System.out.println("soft tabs!!");
useSoftTabs = ((Boolean)event.getNewValue()).booleanValue();
}
super.propertyChange(event);
@@ -3,6 +3,8 @@
import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.playframework.playclipse.editors.html.HTMLEditor;
public class HTMLEditorPreferencePage extends PlayEditorPreferencePage {
@@ -27,4 +29,11 @@ public HTMLEditorPreferencePage() {
return fields;
}
@Override
public void createFieldEditors() {
super.createFieldEditors();
addField(new BooleanFieldEditor(HTMLEditor.SOFT_TABS, "Indent with spaces (soft tabs)", getFieldEditorParent()));
addField(new IntegerFieldEditor(HTMLEditor.SOFT_TABS_WIDTH, "Soft tabs length", getFieldEditorParent()));
}
}
@@ -46,6 +46,8 @@ public void initializeDefaultPreferences() {
PreferenceConverter.setDefault(store, HTMLEditor.SKIPPED_COLOR, new RGB(90, 90, 90));
PreferenceConverter.setDefault(store, HTMLEditor.TAG_COLOR, new RGB(129, 0, 153));
PreferenceConverter.setDefault(store, HTMLEditor.STRING_COLOR, new RGB(5, 152, 220));
store.setDefault(HTMLEditor.SOFT_TABS, false);
store.setDefault(HTMLEditor.SOFT_TABS_WIDTH, 4);
}
}

0 comments on commit c3cb350

Please sign in to comment.