This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 157561
Collapse All | Expand All

(-)a/editor.lib/nbproject/project.xml (-1 / +1 lines)
Lines 90-96 Link Here
90
                    <compile-dependency/>
90
                    <compile-dependency/>
91
                    <run-dependency>
91
                    <run-dependency>
92
                        <release-version>1</release-version>
92
                        <release-version>1</release-version>
93
                        <specification-version>1.20</specification-version>
93
                        <specification-version>1.33</specification-version>
94
                    </run-dependency>
94
                    </run-dependency>
95
                </dependency>
95
                </dependency>
96
                <dependency>
96
                <dependency>
(-)a/editor.lib/src/org/netbeans/modules/editor/lib/TrailingWhitespaceRemove.java (-8 / +21 lines)
Lines 46-51 Link Here
46
46
47
import java.util.logging.Level;
47
import java.util.logging.Level;
48
import java.util.logging.Logger;
48
import java.util.logging.Logger;
49
import java.util.prefs.Preferences;
49
import javax.swing.event.DocumentEvent;
50
import javax.swing.event.DocumentEvent;
50
import javax.swing.event.DocumentListener;
51
import javax.swing.event.DocumentListener;
51
import javax.swing.text.BadLocationException;
52
import javax.swing.text.BadLocationException;
Lines 57-62 Link Here
57
import javax.swing.undo.CannotUndoException;
58
import javax.swing.undo.CannotUndoException;
58
import javax.swing.undo.CompoundEdit;
59
import javax.swing.undo.CompoundEdit;
59
import org.netbeans.api.editor.EditorRegistry;
60
import org.netbeans.api.editor.EditorRegistry;
61
import org.netbeans.api.editor.mimelookup.MimeLookup;
62
import org.netbeans.api.editor.settings.SimpleValueNames;
60
import org.netbeans.editor.BaseDocument;
63
import org.netbeans.editor.BaseDocument;
61
import org.netbeans.lib.editor.util.ArrayUtilities;
64
import org.netbeans.lib.editor.util.ArrayUtilities;
62
import org.netbeans.lib.editor.util.GapList;
65
import org.netbeans.lib.editor.util.GapList;
Lines 98-103 Link Here
98
    
101
    
99
    private boolean inWhitespaceRemove;
102
    private boolean inWhitespaceRemove;
100
103
104
    @SuppressWarnings("LeakingThisInConstructor")
101
    private TrailingWhitespaceRemove(BaseDocument doc) {
105
    private TrailingWhitespaceRemove(BaseDocument doc) {
102
        this.doc = doc;
106
        this.doc = doc;
103
        this.docText = DocumentUtilities.getText(doc); // Persists for doc's lifetime
107
        this.docText = DocumentUtilities.getText(doc); // Persists for doc's lifetime
Lines 105-119 Link Here
105
        doc.addUpdateDocumentListener(this);
109
        doc.addUpdateDocumentListener(this);
106
    }
110
    }
107
111
112
    @Override
108
    public synchronized void run(CompoundEdit compoundEdit) {
113
    public synchronized void run(CompoundEdit compoundEdit) {
109
        inWhitespaceRemove = true;
114
        Preferences prefs = MimeLookup.getLookup(DocumentUtilities.getMimeType(doc)).lookup(Preferences.class);
110
        try {
115
        String policy = prefs.get(SimpleValueNames.ON_SAVE_REMOVE_TRAILING_WHITESPACE, "never"); //NOI18N
111
            new ModsProcessor().removeWhitespace();
116
        if (!"never".equals(policy)) { //NOI18N
112
            NewModRegionsEdit edit = new NewModRegionsEdit();
117
            inWhitespaceRemove = true;
113
            compoundEdit.addEdit(edit);
118
            try {
114
            edit.run();
119
                // XXX: somehow update the processor to support removing all lines vs modified lines only
115
        } finally {
120
                new ModsProcessor().removeWhitespace();
116
            inWhitespaceRemove = false;
121
                NewModRegionsEdit edit = new NewModRegionsEdit();
122
                compoundEdit.addEdit(edit);
123
                edit.run();
124
            } finally {
125
                inWhitespaceRemove = false;
126
            }
117
        }
127
        }
118
    }
128
    }
119
129
Lines 125-130 Link Here
125
        return new GapList<MutablePositionRegion>(3);
135
        return new GapList<MutablePositionRegion>(3);
126
    }
136
    }
127
137
138
    @Override
128
    public void insertUpdate(DocumentEvent evt) {
139
    public void insertUpdate(DocumentEvent evt) {
129
        CompoundEdit compoundEdit = (CompoundEdit) evt;
140
        CompoundEdit compoundEdit = (CompoundEdit) evt;
130
        int offset = evt.getOffset();
141
        int offset = evt.getOffset();
Lines 146-151 Link Here
146
        }
157
        }
147
    }
158
    }
148
159
160
    @Override
149
    public void removeUpdate(DocumentEvent evt) {
161
    public void removeUpdate(DocumentEvent evt) {
150
        // Currently do not handle in any special way but
162
        // Currently do not handle in any special way but
151
        // Since there's a mod on the line there will be a diff
163
        // Since there's a mod on the line there will be a diff
Lines 155-160 Link Here
155
        }
167
        }
156
    }
168
    }
157
169
170
    @Override
158
    public void changedUpdate(DocumentEvent evt) {
171
    public void changedUpdate(DocumentEvent evt) {
159
    }
172
    }
160
173
(-)a/editor.settings/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor.settings/1
2
OpenIDE-Module: org.netbeans.modules.editor.settings/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/settings/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/settings/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.32
4
OpenIDE-Module-Specification-Version: 1.33
5
OpenIDE-Module-Needs: org.netbeans.api.editor.settings.implementation
5
OpenIDE-Module-Needs: org.netbeans.api.editor.settings.implementation
(-)a/editor.settings/src/org/netbeans/api/editor/settings/SimpleValueNames.java (-1 / +13 lines)
Lines 424-430 Link Here
424
     * @since 1.30
424
     * @since 1.30
425
     */
425
     */
426
    public static final String NON_PRINTABLE_CHARACTERS_VISIBLE = "non-printable-characters-visible"; //NOI18N
426
    public static final String NON_PRINTABLE_CHARACTERS_VISIBLE = "non-printable-characters-visible"; //NOI18N
427
    
427
428
    /**
429
     * Determines whether to remove trailing whitespace when saving files and how exactly to do that.
430
     * Values: java.lang.String instances
431
     * <ul>
432
     * <li>never
433
     * <li>always
434
     * <li>modified-lines
435
     * </ul>
436
     * @since 1.33
437
     */
438
    public static final String ON_SAVE_REMOVE_TRAILING_WHITESPACE = "on-save-remove-trailing-whitespace"; //NOI18N
439
428
    @PatchedPublic
440
    @PatchedPublic
429
    private SimpleValueNames() {
441
    private SimpleValueNames() {
430
        // to prevent instantialization
442
        // to prevent instantialization
(-)a/options.editor/nbproject/project.xml (-1 / +1 lines)
Lines 109-115 Link Here
109
                    <compile-dependency/>
109
                    <compile-dependency/>
110
                    <run-dependency>
110
                    <run-dependency>
111
                        <release-version>1</release-version>
111
                        <release-version>1</release-version>
112
                        <specification-version>1.29</specification-version>
112
                        <specification-version>1.33</specification-version>
113
                    </run-dependency>
113
                    </run-dependency>
114
                </dependency>
114
                </dependency>
115
                <dependency>
115
                <dependency>
(-)a/options.editor/src/org/netbeans/modules/options/generaleditor/Bundle.properties (-1 / +9 lines)
Lines 105-108 Link Here
105
CTL_Camel_Case_Behavior_Example=Example: Caret stops at S, T, N in "SomeTypeName" when using next/previous word actions
105
CTL_Camel_Case_Behavior_Example=Example: Caret stops at S, T, N in "SomeTypeName" when using next/previous word actions
106
AN_Camel_Case_Behavior_Example=Example: Caret stops at S, T, N in "SomeTypeName" when using next/previous word actions
106
AN_Camel_Case_Behavior_Example=Example: Caret stops at S, T, N in "SomeTypeName" when using next/previous word actions
107
AD_Camel_Case_Behavior_Example=Example: Caret stops at S, T, N in "SomeTypeName" when using next/previous word actions
107
AD_Camel_Case_Behavior_Example=Example: Caret stops at S, T, N in "SomeTypeName" when using next/previous word actions
108
108
CTL_When_Saving_Files=When Saving Files
109
AN_When_Saving_Files=When Saving Files
110
AD_When_Saving_Files=When Saving Files
111
CTL_Remove_Trailing_Whitespace=Remove Trailing Whitespace
112
AN_Remove_Trailing_Whitespace=Remove Trailing Whitespace
113
AD_Remove_Trailing_Whitespace=Remove Trailing Whitespace
114
RTW_never=Never
115
RTW_always=Always
116
RTW_modified-lines=From Modified Lines Only
(-)a/options.editor/src/org/netbeans/modules/options/generaleditor/GeneralEditorPanel.form (-26 / +101 lines)
Lines 1-4 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
1
<?xml version="1.1" encoding="UTF-8" ?>
2
2
3
<Form version="1.3" maxVersion="1.3" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.3" maxVersion="1.3" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <Properties>
4
  <Properties>
Lines 21-37 Link Here
21
  <Layout>
21
  <Layout>
22
    <DimensionLayout dim="0">
22
    <DimensionLayout dim="0">
23
      <Group type="103" groupAlignment="0" attributes="0">
23
      <Group type="103" groupAlignment="0" attributes="0">
24
          <Group type="102" alignment="0" attributes="0">
24
          <Group type="102" attributes="0">
25
              <Component id="lCodeFolding" min="-2" max="-2" attributes="0"/>
26
              <EmptySpace min="-2" max="-2" attributes="0"/>
27
              <Component id="jSeparator1" pref="671" max="32767" attributes="0"/>
28
          </Group>
29
          <Group type="102" alignment="0" attributes="0">
30
              <Component id="lCamelCaseBehavior" min="-2" max="-2" attributes="0"/>
31
              <EmptySpace max="-2" attributes="0"/>
32
              <Component id="jSeparator3" pref="612" max="32767" attributes="0"/>
33
          </Group>
34
          <Group type="102" alignment="0" attributes="0">
35
              <EmptySpace max="-2" attributes="0"/>
25
              <EmptySpace max="-2" attributes="0"/>
36
              <Group type="103" groupAlignment="0" attributes="0">
26
              <Group type="103" groupAlignment="0" attributes="0">
37
                  <Component id="lUseCodeFolding" alignment="0" min="-2" max="-2" attributes="0"/>
27
                  <Component id="lUseCodeFolding" alignment="0" min="-2" max="-2" attributes="0"/>
Lines 39-59 Link Here
39
              </Group>
29
              </Group>
40
              <EmptySpace max="-2" attributes="0"/>
30
              <EmptySpace max="-2" attributes="0"/>
41
              <Group type="103" groupAlignment="0" attributes="0">
31
              <Group type="103" groupAlignment="0" attributes="0">
32
                  <Group type="102" alignment="0" attributes="0">
33
                      <Component id="lRemoveTrailingWhitespace" min="-2" max="-2" attributes="0"/>
34
                      <EmptySpace max="-2" attributes="0"/>
35
                      <Component id="cboRemoveTrailingWhitespace" min="-2" max="-2" attributes="0"/>
36
                  </Group>
42
                  <Component id="lCamelCaseBehaviorExample" alignment="0" min="-2" max="-2" attributes="0"/>
37
                  <Component id="lCamelCaseBehaviorExample" alignment="0" min="-2" max="-2" attributes="0"/>
43
                  <Component id="cbFoldInitialComments" linkSize="1" alignment="0" min="-2" max="-2" attributes="0"/>
44
                  <Component id="cbFoldJavadocComments" linkSize="1" alignment="0" min="-2" max="-2" attributes="0"/>
45
                  <Component id="cbUseCodeFolding" alignment="0" min="-2" max="-2" attributes="0"/>
46
                  <Group type="102" alignment="0" attributes="0">
47
                      <Component id="cbFoldMethods" linkSize="1" min="-2" max="-2" attributes="0"/>
48
                      <EmptySpace type="separate" max="-2" attributes="0"/>
49
                      <Component id="cbFoldTags" min="-2" max="-2" attributes="0"/>
50
                  </Group>
51
                  <Component id="cbFoldInnerClasses" linkSize="1" alignment="0" min="-2" max="-2" attributes="0"/>
52
                  <Component id="cbFoldImports" linkSize="1" alignment="0" min="-2" max="-2" attributes="0"/>
53
                  <Component id="cbCamelCaseBehavior" alignment="0" min="-2" max="-2" attributes="0"/>
54
              </Group>
38
              </Group>
55
              <EmptySpace pref="40" max="32767" attributes="0"/>
39
              <EmptySpace pref="40" max="32767" attributes="0"/>
56
          </Group>
40
          </Group>
41
          <Group type="102" alignment="0" attributes="0">
42
              <EmptySpace min="155" pref="155" max="155" attributes="0"/>
43
              <Component id="cbCamelCaseBehavior" min="-2" max="-2" attributes="0"/>
44
              <EmptySpace pref="391" max="32767" attributes="0"/>
45
          </Group>
46
          <Group type="102" alignment="0" attributes="0">
47
              <EmptySpace min="155" pref="155" max="155" attributes="0"/>
48
              <Component id="cbFoldImports" linkSize="1" min="-2" max="-2" attributes="0"/>
49
              <EmptySpace pref="461" max="32767" attributes="0"/>
50
          </Group>
51
          <Group type="102" alignment="0" attributes="0">
52
              <EmptySpace min="155" pref="155" max="155" attributes="0"/>
53
              <Component id="cbFoldInnerClasses" linkSize="1" min="-2" max="-2" attributes="0"/>
54
              <EmptySpace pref="461" max="32767" attributes="0"/>
55
          </Group>
56
          <Group type="102" alignment="0" attributes="0">
57
              <EmptySpace min="155" pref="155" max="155" attributes="0"/>
58
              <Component id="cbFoldMethods" linkSize="1" min="-2" max="-2" attributes="0"/>
59
              <EmptySpace type="separate" max="-2" attributes="0"/>
60
              <Component id="cbFoldTags" min="-2" max="-2" attributes="0"/>
61
              <EmptySpace pref="234" max="32767" attributes="0"/>
62
          </Group>
63
          <Group type="102" alignment="0" attributes="0">
64
              <EmptySpace min="155" pref="155" max="155" attributes="0"/>
65
              <Component id="cbUseCodeFolding" min="-2" max="-2" attributes="0"/>
66
              <EmptySpace pref="585" max="32767" attributes="0"/>
67
          </Group>
68
          <Group type="102" alignment="0" attributes="0">
69
              <EmptySpace min="155" pref="155" max="155" attributes="0"/>
70
              <Component id="cbFoldJavadocComments" linkSize="1" min="-2" max="-2" attributes="0"/>
71
              <EmptySpace pref="461" max="32767" attributes="0"/>
72
          </Group>
73
          <Group type="102" alignment="0" attributes="0">
74
              <EmptySpace min="155" pref="155" max="155" attributes="0"/>
75
              <Component id="cbFoldInitialComments" linkSize="1" min="-2" max="-2" attributes="0"/>
76
              <EmptySpace pref="461" max="32767" attributes="0"/>
77
          </Group>
78
          <Group type="102" alignment="0" attributes="0">
79
              <Component id="lWhenSavingFiles" min="-2" max="-2" attributes="0"/>
80
              <EmptySpace max="-2" attributes="0"/>
81
              <Component id="jSeparator4" pref="644" max="32767" attributes="0"/>
82
          </Group>
83
          <Group type="102" alignment="0" attributes="0">
84
              <Component id="lCamelCaseBehavior" min="-2" max="-2" attributes="0"/>
85
              <EmptySpace max="-2" attributes="0"/>
86
              <Component id="jSeparator3" pref="622" max="32767" attributes="0"/>
87
          </Group>
88
          <Group type="102" alignment="0" attributes="0">
89
              <Component id="lCodeFolding" min="-2" max="-2" attributes="0"/>
90
              <EmptySpace min="-2" max="-2" attributes="0"/>
91
              <Component id="jSeparator1" pref="673" max="32767" attributes="0"/>
92
          </Group>
57
      </Group>
93
      </Group>
58
    </DimensionLayout>
94
    </DimensionLayout>
59
    <DimensionLayout dim="1">
95
    <DimensionLayout dim="1">
Lines 91-100 Link Here
91
                  <Component id="lCamelCaseBehavior" min="-2" max="-2" attributes="0"/>
127
                  <Component id="lCamelCaseBehavior" min="-2" max="-2" attributes="0"/>
92
              </Group>
128
              </Group>
93
              <EmptySpace min="-2" pref="2" max="-2" attributes="0"/>
129
              <EmptySpace min="-2" pref="2" max="-2" attributes="0"/>
94
              <Component id="cbCamelCaseBehavior" min="-2" max="-2" attributes="0"/>
130
              <Group type="103" groupAlignment="1" attributes="0">
131
                  <Group type="102" attributes="0">
132
                      <Component id="cbCamelCaseBehavior" min="-2" max="-2" attributes="0"/>
133
                      <EmptySpace max="-2" attributes="0"/>
134
                      <Component id="lCamelCaseBehaviorExample" min="-2" max="-2" attributes="0"/>
135
                      <EmptySpace type="separate" max="-2" attributes="0"/>
136
                      <Component id="jSeparator4" min="-2" pref="10" max="-2" attributes="0"/>
137
                  </Group>
138
                  <Component id="lWhenSavingFiles" min="-2" max="-2" attributes="0"/>
139
              </Group>
95
              <EmptySpace max="-2" attributes="0"/>
140
              <EmptySpace max="-2" attributes="0"/>
96
              <Component id="lCamelCaseBehaviorExample" min="-2" max="-2" attributes="0"/>
141
              <Group type="103" groupAlignment="3" attributes="0">
97
              <EmptySpace pref="59" max="32767" attributes="0"/>
142
                  <Component id="lRemoveTrailingWhitespace" alignment="3" min="-2" max="-2" attributes="0"/>
143
                  <Component id="cboRemoveTrailingWhitespace" alignment="3" min="-2" max="-2" attributes="0"/>
144
              </Group>
145
              <EmptySpace pref="67" max="32767" attributes="0"/>
98
          </Group>
146
          </Group>
99
      </Group>
147
      </Group>
100
    </DimensionLayout>
148
    </DimensionLayout>
Lines 169-173 Link Here
169
        <Property name="text" type="java.lang.String" value="Example: Caret stops at J, T, N in &quot;JavaTypeName&quot; when using next/previous word acctions"/>
217
        <Property name="text" type="java.lang.String" value="Example: Caret stops at J, T, N in &quot;JavaTypeName&quot; when using next/previous word acctions"/>
170
      </Properties>
218
      </Properties>
171
    </Component>
219
    </Component>
220
    <Component class="javax.swing.JSeparator" name="jSeparator4">
221
    </Component>
222
    <Component class="javax.swing.JLabel" name="lWhenSavingFiles">
223
      <Properties>
224
        <Property name="text" type="java.lang.String" value="When Saving Files"/>
225
      </Properties>
226
    </Component>
227
    <Component class="javax.swing.JLabel" name="lRemoveTrailingWhitespace">
228
      <Properties>
229
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
230
          <ComponentRef name="cboRemoveTrailingWhitespace"/>
231
        </Property>
232
        <Property name="text" type="java.lang.String" value="Remove Trailing Whitespace:"/>
233
      </Properties>
234
    </Component>
235
    <Component class="javax.swing.JComboBox" name="cboRemoveTrailingWhitespace">
236
      <Properties>
237
        <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
238
          <StringArray count="4">
239
            <StringItem index="0" value="Item 1"/>
240
            <StringItem index="1" value="Item 2"/>
241
            <StringItem index="2" value="Item 3"/>
242
            <StringItem index="3" value="Item 4"/>
243
          </StringArray>
244
        </Property>
245
      </Properties>
246
    </Component>
172
  </SubComponents>
247
  </SubComponents>
173
</Form>
248
</Form>
(-)a/options.editor/src/org/netbeans/modules/options/generaleditor/GeneralEditorPanel.java (-25 / +115 lines)
Lines 48-55 Link Here
48
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionListener;
49
import java.awt.event.ActionListener;
50
import javax.swing.AbstractButton;
50
import javax.swing.AbstractButton;
51
import javax.swing.DefaultComboBoxModel;
51
import javax.swing.JLabel;
52
import javax.swing.JLabel;
53
import javax.swing.JList;
52
import javax.swing.JPanel;
54
import javax.swing.JPanel;
55
import javax.swing.ListCellRenderer;
53
import org.openide.awt.Mnemonics;
56
import org.openide.awt.Mnemonics;
54
import org.openide.util.NbBundle;
57
import org.openide.util.NbBundle;
55
58
Lines 84-91 Link Here
84
        loc (lCamelCaseBehavior, "Camel_Case_Behavior");
87
        loc (lCamelCaseBehavior, "Camel_Case_Behavior");
85
        loc (cbCamelCaseBehavior, "Enable_Camel_Case_In_Java");
88
        loc (cbCamelCaseBehavior, "Enable_Camel_Case_In_Java");
86
        loc (lCamelCaseBehaviorExample, "Camel_Case_Behavior_Example");
89
        loc (lCamelCaseBehaviorExample, "Camel_Case_Behavior_Example");
90
91
        loc (lWhenSavingFiles, "When_Saving_Files");
92
        loc (lRemoveTrailingWhitespace, "Remove_Trailing_Whitespace");
93
        loc (cboRemoveTrailingWhitespace, "Remove_Trailing_Whitespace");
94
87
        cbUseCodeFolding.setMnemonic(NbBundle.getMessage (GeneralEditorPanel.class, "MNEMONIC_Use_Folding").charAt(0));
95
        cbUseCodeFolding.setMnemonic(NbBundle.getMessage (GeneralEditorPanel.class, "MNEMONIC_Use_Folding").charAt(0));
88
96
        cboRemoveTrailingWhitespace.setRenderer(new RemoveTrailingWhitespaceRenderer(cboRemoveTrailingWhitespace.getRenderer()));
97
        cboRemoveTrailingWhitespace.setModel(new DefaultComboBoxModel(new Object [] { "never", "always", "modified-lines" })); //NOI18N
89
    }
98
    }
90
    
99
    
91
    /** This method is called from within the constructor to
100
    /** This method is called from within the constructor to
Lines 111-116 Link Here
111
        jSeparator3 = new javax.swing.JSeparator();
120
        jSeparator3 = new javax.swing.JSeparator();
112
        cbCamelCaseBehavior = new javax.swing.JCheckBox();
121
        cbCamelCaseBehavior = new javax.swing.JCheckBox();
113
        lCamelCaseBehaviorExample = new javax.swing.JLabel();
122
        lCamelCaseBehaviorExample = new javax.swing.JLabel();
123
        jSeparator4 = new javax.swing.JSeparator();
124
        lWhenSavingFiles = new javax.swing.JLabel();
125
        lRemoveTrailingWhitespace = new javax.swing.JLabel();
126
        cboRemoveTrailingWhitespace = new javax.swing.JComboBox();
114
127
115
        setForeground(new java.awt.Color(99, 130, 191));
128
        setForeground(new java.awt.Color(99, 130, 191));
116
129
Lines 139-175 Link Here
139
152
140
        lCamelCaseBehaviorExample.setText("Example: Caret stops at J, T, N in \"JavaTypeName\" when using next/previous word acctions");
153
        lCamelCaseBehaviorExample.setText("Example: Caret stops at J, T, N in \"JavaTypeName\" when using next/previous word acctions");
141
154
155
        lWhenSavingFiles.setText("When Saving Files");
156
157
        lRemoveTrailingWhitespace.setLabelFor(cboRemoveTrailingWhitespace);
158
        lRemoveTrailingWhitespace.setText("Remove Trailing Whitespace:");
159
160
        cboRemoveTrailingWhitespace.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
161
142
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
162
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
143
        this.setLayout(layout);
163
        this.setLayout(layout);
144
        layout.setHorizontalGroup(
164
        layout.setHorizontalGroup(
145
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
165
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
146
            .add(layout.createSequentialGroup()
166
            .add(layout.createSequentialGroup()
147
                .add(lCodeFolding)
148
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
149
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 671, Short.MAX_VALUE))
150
            .add(layout.createSequentialGroup()
151
                .add(lCamelCaseBehavior)
152
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
153
                .add(jSeparator3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 612, Short.MAX_VALUE))
154
            .add(layout.createSequentialGroup()
155
                .addContainerGap()
167
                .addContainerGap()
156
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
168
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
157
                    .add(lUseCodeFolding)
169
                    .add(lUseCodeFolding)
158
                    .add(lCollapseByDefault))
170
                    .add(lCollapseByDefault))
159
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
171
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
160
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
172
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
161
                    .add(lCamelCaseBehaviorExample)
162
                    .add(cbFoldInitialComments)
163
                    .add(cbFoldJavadocComments)
164
                    .add(cbUseCodeFolding)
165
                    .add(layout.createSequentialGroup()
173
                    .add(layout.createSequentialGroup()
166
                        .add(cbFoldMethods)
174
                        .add(lRemoveTrailingWhitespace)
167
                        .add(18, 18, 18)
175
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
168
                        .add(cbFoldTags))
176
                        .add(cboRemoveTrailingWhitespace, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
169
                    .add(cbFoldInnerClasses)
177
                    .add(lCamelCaseBehaviorExample))
170
                    .add(cbFoldImports)
171
                    .add(cbCamelCaseBehavior))
172
                .addContainerGap(40, Short.MAX_VALUE))
178
                .addContainerGap(40, Short.MAX_VALUE))
179
            .add(layout.createSequentialGroup()
180
                .add(155, 155, 155)
181
                .add(cbCamelCaseBehavior)
182
                .addContainerGap(391, Short.MAX_VALUE))
183
            .add(layout.createSequentialGroup()
184
                .add(155, 155, 155)
185
                .add(cbFoldImports)
186
                .addContainerGap(461, Short.MAX_VALUE))
187
            .add(layout.createSequentialGroup()
188
                .add(155, 155, 155)
189
                .add(cbFoldInnerClasses)
190
                .addContainerGap(461, Short.MAX_VALUE))
191
            .add(layout.createSequentialGroup()
192
                .add(155, 155, 155)
193
                .add(cbFoldMethods)
194
                .add(18, 18, 18)
195
                .add(cbFoldTags)
196
                .addContainerGap(234, Short.MAX_VALUE))
197
            .add(layout.createSequentialGroup()
198
                .add(155, 155, 155)
199
                .add(cbUseCodeFolding)
200
                .addContainerGap(585, Short.MAX_VALUE))
201
            .add(layout.createSequentialGroup()
202
                .add(155, 155, 155)
203
                .add(cbFoldJavadocComments)
204
                .addContainerGap(461, Short.MAX_VALUE))
205
            .add(layout.createSequentialGroup()
206
                .add(155, 155, 155)
207
                .add(cbFoldInitialComments)
208
                .addContainerGap(461, Short.MAX_VALUE))
209
            .add(layout.createSequentialGroup()
210
                .add(lWhenSavingFiles)
211
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
212
                .add(jSeparator4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 644, Short.MAX_VALUE))
213
            .add(layout.createSequentialGroup()
214
                .add(lCamelCaseBehavior)
215
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
216
                .add(jSeparator3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE))
217
            .add(layout.createSequentialGroup()
218
                .add(lCodeFolding)
219
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
220
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 673, Short.MAX_VALUE))
173
        );
221
        );
174
222
175
        layout.linkSize(new java.awt.Component[] {cbFoldImports, cbFoldInitialComments, cbFoldInnerClasses, cbFoldJavadocComments, cbFoldMethods}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
223
        layout.linkSize(new java.awt.Component[] {cbFoldImports, cbFoldInitialComments, cbFoldInnerClasses, cbFoldJavadocComments, cbFoldMethods}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
Lines 204-213 Link Here
204
                        .add(jSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
252
                        .add(jSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
205
                    .add(lCamelCaseBehavior))
253
                    .add(lCamelCaseBehavior))
206
                .add(2, 2, 2)
254
                .add(2, 2, 2)
207
                .add(cbCamelCaseBehavior)
255
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
256
                    .add(layout.createSequentialGroup()
257
                        .add(cbCamelCaseBehavior)
258
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
259
                        .add(lCamelCaseBehaviorExample)
260
                        .add(18, 18, 18)
261
                        .add(jSeparator4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
262
                    .add(lWhenSavingFiles))
208
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
263
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
209
                .add(lCamelCaseBehaviorExample)
264
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
210
                .addContainerGap(59, Short.MAX_VALUE))
265
                    .add(lRemoveTrailingWhitespace)
266
                    .add(cboRemoveTrailingWhitespace, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
267
                .addContainerGap(67, Short.MAX_VALUE))
211
        );
268
        );
212
    }// </editor-fold>//GEN-END:initComponents
269
    }// </editor-fold>//GEN-END:initComponents
213
    
270
    
Lines 221-233 Link Here
221
    private javax.swing.JCheckBox cbFoldMethods;
278
    private javax.swing.JCheckBox cbFoldMethods;
222
    private javax.swing.JCheckBox cbFoldTags;
279
    private javax.swing.JCheckBox cbFoldTags;
223
    private javax.swing.JCheckBox cbUseCodeFolding;
280
    private javax.swing.JCheckBox cbUseCodeFolding;
281
    private javax.swing.JComboBox cboRemoveTrailingWhitespace;
224
    private javax.swing.JSeparator jSeparator1;
282
    private javax.swing.JSeparator jSeparator1;
225
    private javax.swing.JSeparator jSeparator3;
283
    private javax.swing.JSeparator jSeparator3;
284
    private javax.swing.JSeparator jSeparator4;
226
    private javax.swing.JLabel lCamelCaseBehavior;
285
    private javax.swing.JLabel lCamelCaseBehavior;
227
    private javax.swing.JLabel lCamelCaseBehaviorExample;
286
    private javax.swing.JLabel lCamelCaseBehaviorExample;
228
    private javax.swing.JLabel lCodeFolding;
287
    private javax.swing.JLabel lCodeFolding;
229
    private javax.swing.JLabel lCollapseByDefault;
288
    private javax.swing.JLabel lCollapseByDefault;
289
    private javax.swing.JLabel lRemoveTrailingWhitespace;
230
    private javax.swing.JLabel lUseCodeFolding;
290
    private javax.swing.JLabel lUseCodeFolding;
291
    private javax.swing.JLabel lWhenSavingFiles;
231
    // End of variables declaration//GEN-END:variables
292
    // End of variables declaration//GEN-END:variables
232
    
293
    
233
    
294
    
Lines 245-251 Link Here
245
                (AbstractButton) c, 
306
                (AbstractButton) c, 
246
                loc ("CTL_" + key)
307
                loc ("CTL_" + key)
247
            );
308
            );
248
        } else {
309
        } else if (c instanceof JLabel) {
249
            Mnemonics.setLocalizedText (
310
            Mnemonics.setLocalizedText (
250
                (JLabel) c, 
311
                (JLabel) c, 
251
                loc ("CTL_" + key)
312
                loc ("CTL_" + key)
Lines 267-272 Link Here
267
            cbFoldInitialComments.addActionListener (this);
328
            cbFoldInitialComments.addActionListener (this);
268
            cbCamelCaseBehavior.addActionListener (this);
329
            cbCamelCaseBehavior.addActionListener (this);
269
            cbFoldTags.addActionListener (this);
330
            cbFoldTags.addActionListener (this);
331
            cboRemoveTrailingWhitespace.addActionListener(this);
270
        }
332
        }
271
        
333
        
272
        // init code folding
334
        // init code folding
Lines 288-294 Link Here
288
            cbCamelCaseBehavior.setEnabled(true);
350
            cbCamelCaseBehavior.setEnabled(true);
289
            cbCamelCaseBehavior.setSelected(ccJava);
351
            cbCamelCaseBehavior.setSelected(ccJava);
290
        }
352
        }
291
        
353
354
        // when saving files section
355
        cboRemoveTrailingWhitespace.setSelectedItem(model.getRemoveTrailingWhitespace());
356
292
        updateEnabledState ();
357
        updateEnabledState ();
293
        
358
        
294
        listen = true;
359
        listen = true;
Lines 312-317 Link Here
312
        // java camel case navigation
377
        // java camel case navigation
313
        model.setCamelCaseNavigation(cbCamelCaseBehavior.isSelected());
378
        model.setCamelCaseNavigation(cbCamelCaseBehavior.isSelected());
314
        
379
        
380
        // when saving files section
381
        model.setRemoveTrailingWhitespace((String)cboRemoveTrailingWhitespace.getSelectedItem());
382
315
        changed = false;
383
        changed = false;
316
    }
384
    }
317
    
385
    
Lines 327-336 Link Here
327
        return changed;
395
        return changed;
328
    }
396
    }
329
    
397
    
398
    @Override
330
    public void actionPerformed (ActionEvent e) {
399
    public void actionPerformed (ActionEvent e) {
331
        if (!listen) return;
400
        if (!listen) return;
332
        if (e.getSource () == cbUseCodeFolding)
401
        if (e.getSource () == cbUseCodeFolding) {
333
            updateEnabledState ();
402
            updateEnabledState ();
403
        }
334
        changed = true;
404
        changed = true;
335
    }
405
    }
336
    
406
    
Lines 346-349 Link Here
346
        cbFoldMethods.setEnabled (useCodeFolding);
416
        cbFoldMethods.setEnabled (useCodeFolding);
347
        cbFoldTags.setEnabled(useCodeFolding);
417
        cbFoldTags.setEnabled(useCodeFolding);
348
    }
418
    }
419
420
    private static final class RemoveTrailingWhitespaceRenderer implements ListCellRenderer {
421
422
        private final ListCellRenderer defaultRenderer;
423
424
        public RemoveTrailingWhitespaceRenderer(ListCellRenderer defaultRenderer) {
425
            this.defaultRenderer = defaultRenderer;
426
        }
427
428
        @Override
429
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
430
            return defaultRenderer.getListCellRendererComponent(
431
                    list,
432
                    NbBundle.getMessage(GeneralEditorPanel.class, "RTW_" + value), //NOI18N
433
                    index,
434
                    isSelected,
435
                    cellHasFocus);
436
        }
437
438
    } // End of RemoveTrailingWhitespaceRendererRenderer class
349
}
439
}
(-)a/options.editor/src/org/netbeans/modules/options/generaleditor/Model.java (-1 / +12 lines)
Lines 50-55 Link Here
50
import java.util.Set;
50
import java.util.Set;
51
import java.util.prefs.Preferences;
51
import java.util.prefs.Preferences;
52
import org.netbeans.api.editor.mimelookup.MimeLookup;
52
import org.netbeans.api.editor.mimelookup.MimeLookup;
53
import org.netbeans.api.editor.mimelookup.MimePath;
53
import org.netbeans.api.editor.settings.SimpleValueNames;
54
import org.netbeans.api.editor.settings.SimpleValueNames;
54
import org.netbeans.modules.editor.settings.storage.api.EditorSettings;
55
import org.netbeans.modules.editor.settings.storage.api.EditorSettings;
55
import org.openide.util.Lookup;
56
import org.openide.util.Lookup;
Lines 122-128 Link Here
122
    void setCamelCaseNavigation(boolean value) {
123
    void setCamelCaseNavigation(boolean value) {
123
        NbPreferences.root ().putBoolean("useCamelCaseStyleNavigation", value); // NOI18N
124
        NbPreferences.root ().putBoolean("useCamelCaseStyleNavigation", value); // NOI18N
124
    }
125
    }
125
        
126
127
    String getRemoveTrailingWhitespace() {
128
        Preferences prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
129
        return prefs.get(SimpleValueNames.ON_SAVE_REMOVE_TRAILING_WHITESPACE, "never");
130
    }
131
132
    void setRemoveTrailingWhitespace(String value) {
133
        Preferences prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
134
        prefs.put(SimpleValueNames.ON_SAVE_REMOVE_TRAILING_WHITESPACE, value);
135
    }
136
126
    // private helper methods ..................................................
137
    // private helper methods ..................................................
127
    
138
    
128
    private static final List<String> PRIVILEDGED_MIME_TYPES = Arrays.asList(new String [] {
139
    private static final List<String> PRIVILEDGED_MIME_TYPES = Arrays.asList(new String [] {

Return to bug 157561