1 12 package org.eclipse.ant.internal.ui.editor.formatter; 13 14 import org.eclipse.ant.internal.ui.AntUIPlugin; 15 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; 16 import org.eclipse.jface.preference.IPreferenceStore; 17 import org.eclipse.jface.util.PropertyChangeEvent; 18 19 public class FormattingPreferences { 20 21 IPreferenceStore fPrefs= AntUIPlugin.getDefault().getPreferenceStore(); 22 23 public String getCanonicalIndent() { 24 String canonicalIndent; 25 if (!useSpacesInsteadOfTabs()) { 26 canonicalIndent = "\t"; } else { 28 String tab = ""; for (int i = 0; i < getTabWidth(); i++) { 30 tab = tab.concat(" "); } 32 canonicalIndent = tab; 33 } 34 35 return canonicalIndent; 36 } 37 38 public int getMaximumLineWidth() { 39 return fPrefs.getInt(AntEditorPreferenceConstants.FORMATTER_MAX_LINE_LENGTH); 40 } 41 42 public boolean wrapLongTags() { 43 return fPrefs.getBoolean(AntEditorPreferenceConstants.FORMATTER_WRAP_LONG); 44 } 45 46 public boolean alignElementCloseChar() { 47 return fPrefs.getBoolean(AntEditorPreferenceConstants.FORMATTER_ALIGN); 48 } 49 50 public int getTabWidth() { 51 return fPrefs.getInt(AntEditorPreferenceConstants.FORMATTER_TAB_SIZE); 52 } 53 54 public boolean useSpacesInsteadOfTabs() { 55 return ! fPrefs.getBoolean(AntEditorPreferenceConstants.FORMATTER_TAB_CHAR); 56 } 57 58 public static boolean affectsFormatting(PropertyChangeEvent event) { 59 String property= event.getProperty(); 60 return property.startsWith(AntEditorPreferenceConstants.FORMATTER_ALIGN) || 61 property.startsWith(AntEditorPreferenceConstants.FORMATTER_MAX_LINE_LENGTH) || 62 property.startsWith(AntEditorPreferenceConstants.FORMATTER_TAB_CHAR) || 63 property.startsWith(AntEditorPreferenceConstants.FORMATTER_TAB_SIZE) || 64 property.startsWith(AntEditorPreferenceConstants.FORMATTER_WRAP_LONG); 65 } 66 71 public void setPreferenceStore(IPreferenceStore prefs) { 72 fPrefs = prefs; 73 } 74 } | Popular Tags |