2323import org .eclipse .jface .preference .IPreferenceStore ;
2424import org .eclipse .jface .preference .PreferencePage ;
2525import org .eclipse .swt .SWT ;
26- import org .eclipse .swt .events .ModifyEvent ;
27- import org .eclipse .swt .events .ModifyListener ;
2826import org .eclipse .swt .events .SelectionAdapter ;
2927import org .eclipse .swt .events .SelectionEvent ;
3028import org .eclipse .swt .widgets .Button ;
3129import org .eclipse .swt .widgets .Composite ;
3230import org .eclipse .swt .widgets .Control ;
3331import org .eclipse .swt .widgets .Display ;
32+ import org .eclipse .swt .widgets .Event ;
3433import org .eclipse .swt .widgets .FileDialog ;
34+ import org .eclipse .swt .widgets .Listener ;
3535import org .eclipse .swt .widgets .Text ;
3636import org .eclipse .ui .IWorkbench ;
3737import org .eclipse .ui .IWorkbenchPreferencePage ;
4949public class JSHintPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
5050
5151 private final JSHintPreferences preferences ;
52- private Button defaultLibButton ;
53- private Button customLibButton ;
52+ private Button defaultLibRadio ;
53+ private Button customLibRadio ;
5454 private Text customLibPathText ;
5555 private Button customLibPathButton ;
56+ private Button enableErrorsCheckbox ;
5657
5758 public JSHintPreferencePage () {
5859 setPreferenceStore ( Activator .getDefault ().getPreferenceStore () );
@@ -71,9 +72,11 @@ protected IPreferenceStore doGetPreferenceStore() {
7172 @ Override
7273 protected Control createContents ( Composite parent ) {
7374 Composite composite = new Composite ( parent , SWT .NONE );
74- gridLayout ( composite ).columns ( 3 ).marginTop ( 10 );
75+ gridLayout ( composite ).columns ( 3 ).spacing ( 3 ). marginTop ( 10 );
7576 createCustomJSHintArea ( composite );
76- updateControls ();
77+ createEnableErrorMarkersArea ( composite );
78+ updateControlsFromPrefs ();
79+ updateControlsEnabled ();
7780 return composite ;
7881 }
7982
@@ -94,45 +97,59 @@ public boolean performOk() {
9497 @ Override
9598 protected void performDefaults () {
9699 preferences .resetToDefaults ();
97- updateControls ();
100+ updateControlsFromPrefs ();
101+ updateControlsEnabled ();
98102 super .performDefaults ();
99103 }
100104
101105 private void createCustomJSHintArea ( Composite parent ) {
102- defaultLibButton = new Button ( parent , SWT .RADIO );
103- defaultLibButton .setText ( "Use the &built-in JSHint library (version "
104- + JSHint .getDefaultLibraryVersion ()
105- + ")" );
106- gridData ( defaultLibButton ).fillHorizontal ().span ( 3 , 1 );
107- customLibButton = new Button ( parent , SWT .RADIO );
108- customLibButton .setText ( "Provide a &custom JSHint library file" );
109- gridData ( customLibButton ).fillHorizontal ().span ( 3 , 1 );
110- customLibButton .addSelectionListener ( new SelectionAdapter () {
111- @ Override
112- public void widgetSelected ( SelectionEvent e ) {
113- updateValuesFromControls ();
114- updateControls ();
106+ defaultLibRadio = new Button ( parent , SWT .RADIO );
107+ String version = JSHint .getDefaultLibraryVersion ();
108+ defaultLibRadio .setText ( "Use the &built-in JSHint library (version " + version + ")" );
109+ gridData ( defaultLibRadio ).fillHorizontal ().span ( 3 , 1 );
110+ customLibRadio = new Button ( parent , SWT .RADIO );
111+ customLibRadio .setText ( "Provide a &custom JSHint library file" );
112+ gridData ( customLibRadio ).fillHorizontal ().span ( 3 , 1 );
113+ customLibRadio .addListener ( SWT .Selection , new Listener () {
114+ public void handleEvent ( Event event ) {
115+ preferences .setUseCustomLib ( customLibRadio .getSelection () );
116+ validate ();
117+ updateControlsEnabled ();
115118 }
116119 } );
117120 customLibPathText = new Text ( parent , SWT .BORDER );
118121 gridData ( customLibPathText ).fillHorizontal ().span ( 2 , 1 ).indent ( 25 , 0 );
119- customLibPathText .addModifyListener ( new ModifyListener () {
120- public void modifyText ( ModifyEvent e ) {
121- updateValuesFromControls ();
122+ customLibPathText .addListener ( SWT .Modify , new Listener () {
123+ public void handleEvent ( Event event ) {
124+ preferences .setCustomLibPath ( customLibPathText .getText () );
125+ validate ();
122126 }
123127 } );
124128 customLibPathButton = new Button ( parent , SWT .PUSH );
125129 customLibPathButton .setText ( "Select" );
126- customLibPathButton .addSelectionListener ( new SelectionAdapter () {
127- @ Override
128- public void widgetSelected ( SelectionEvent e ) {
130+ customLibPathButton .addListener ( SWT .Selection , new Listener () {
131+ public void handleEvent ( Event event ) {
129132 selectFile ();
130133 }
131134 } );
132135 Text customLibPathLabelText = new Text ( parent , SWT .READ_ONLY | SWT .WRAP );
133136 customLibPathLabelText .setText ( "This file is usually named 'jshint.js'." );
134137 customLibPathLabelText .setBackground ( parent .getBackground () );
135- gridData ( customLibPathLabelText ).fillBoth ().span ( 2 , 1 ).indent ( 25 , 1 );
138+ gridData ( customLibPathLabelText ).fillHorizontal ().span ( 3 , 1 ).indent ( 25 , 1 );
139+ }
140+
141+ private void createEnableErrorMarkersArea ( Composite parent ) {
142+ enableErrorsCheckbox = new Button ( parent , SWT .CHECK );
143+ enableErrorsCheckbox .setText ( "Enable JSHint errors" );
144+ enableErrorsCheckbox .setToolTipText ( "If unchecked, errors will be shown as warnings" );
145+ gridData ( enableErrorsCheckbox ).fillHorizontal ().span ( 3 , 1 );
146+ enableErrorsCheckbox .addSelectionListener ( new SelectionAdapter () {
147+ @ Override
148+ public void widgetSelected ( SelectionEvent e ) {
149+ preferences .setEnableErrorMarkers ( enableErrorsCheckbox .getSelection () );
150+ validate ();
151+ }
152+ } );
136153 }
137154
138155 private void selectFile () {
@@ -145,17 +162,10 @@ private void selectFile() {
145162 fileDialog .setFilterExtensions ( new String [] { "*.js" , "" } );
146163 String selectedPath = fileDialog .open ();
147164 if ( selectedPath != null ) {
148- preferences .setCustomLibPath ( selectedPath );
149- updateControls ();
165+ customLibPathText .setText ( selectedPath );
150166 }
151167 }
152168
153- private void updateValuesFromControls () {
154- preferences .setUseCustomLib ( customLibButton .getSelection () );
155- preferences .setCustomLibPath ( customLibPathText .getText () );
156- validate ();
157- }
158-
159169 private void validate () {
160170 setErrorMessage ( null );
161171 setValid ( false );
@@ -189,8 +199,7 @@ public void run() {
189199 private void validatePrefs () {
190200 if ( preferences .getUseCustomLib () ) {
191201 String path = preferences .getCustomLibPath ();
192- File file = new File ( path );
193- validateFile ( file );
202+ validateFile ( new File ( path ) );
194203 }
195204 }
196205
@@ -214,13 +223,17 @@ private static void validateFile( File file ) throws IllegalArgumentException {
214223 }
215224 }
216225
217- private void updateControls () {
218- boolean useCustomLib = preferences .getUseCustomLib ();
219- defaultLibButton .setSelection ( !useCustomLib );
220- customLibButton .setSelection ( useCustomLib );
226+ private void updateControlsFromPrefs () {
227+ customLibRadio .setSelection ( preferences .getUseCustomLib () );
228+ defaultLibRadio .setSelection ( !customLibRadio .getSelection () );
221229 customLibPathText .setText ( preferences .getCustomLibPath () );
222- customLibPathText .setEnabled ( useCustomLib );
223- customLibPathButton .setEnabled ( useCustomLib );
230+ enableErrorsCheckbox .setSelection ( preferences .getEnableErrorMarkers () );
231+ }
232+
233+ private void updateControlsEnabled () {
234+ boolean enabled = customLibRadio .getSelection ();
235+ customLibPathText .setEnabled ( enabled );
236+ customLibPathButton .setEnabled ( enabled );
224237 }
225238
226239 private void triggerRebuild () throws CoreException {
0 commit comments