Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 189638 | Differences between
and this patch

Collapse All | Expand All

(-)a/apisupport.project/nbproject/project.xml (-2 / +2 lines)
 Lines 139-146    Link Here 
139
                    <build-prerequisite/>
139
                    <build-prerequisite/>
140
                    <compile-dependency/>
140
                    <compile-dependency/>
141
                    <run-dependency>
141
                    <run-dependency>
142
                        <release-version>2</release-version>
142
                        <release-version>3</release-version>
143
                        <specification-version>2.1</specification-version>
143
                        <specification-version>3.1</specification-version>
144
                    </run-dependency>
144
                    </run-dependency>
145
                </dependency>
145
                </dependency>
146
                <dependency>
146
                <dependency>
(-)a/beans/nbproject/project.xml (-2 / +2 lines)
 Lines 116-123    Link Here 
116
                    <build-prerequisite/>
116
                    <build-prerequisite/>
117
                    <compile-dependency/>
117
                    <compile-dependency/>
118
                    <run-dependency>
118
                    <run-dependency>
119
                        <release-version>2</release-version>
119
                        <release-version>3</release-version>
120
                        <specification-version>2.1</specification-version>
120
                        <specification-version>3.1</specification-version>
121
                    </run-dependency>
121
                    </run-dependency>
122
                </dependency>
122
                </dependency>
123
                <dependency>
123
                <dependency>
(-)a/bpel.debugger.ui/nbproject/project.xml (-2 / +2 lines)
 Lines 96-103    Link Here 
96
                    <build-prerequisite/>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
97
                    <compile-dependency/>
98
                    <run-dependency>
98
                    <run-dependency>
99
                        <release-version>2</release-version>
99
                        <release-version>3</release-version>
100
                        <specification-version>2.1</specification-version>
100
                        <specification-version>3.1</specification-version>
101
                    </run-dependency>
101
                    </run-dependency>
102
                </dependency>
102
                </dependency>
103
                <dependency>
103
                <dependency>
(-)a/bugtracking.bridge/nbproject/project.xml (-2 / +2 lines)
 Lines 36-43    Link Here 
36
                    <build-prerequisite/>
36
                    <build-prerequisite/>
37
                    <compile-dependency/>
37
                    <compile-dependency/>
38
                    <run-dependency>
38
                    <run-dependency>
39
                        <release-version>2</release-version>
39
                        <release-version>3</release-version>
40
                        <specification-version>2.1</specification-version>
40
                        <specification-version>3.1</specification-version>
41
                    </run-dependency>
41
                    </run-dependency>
42
                </dependency>
42
                </dependency>
43
                <dependency>
43
                <dependency>
(-)a/cnd.asm/nbproject/project.xml (-3 / +3 lines)
 Lines 27-33    Link Here 
27
                    <compile-dependency/>
27
                    <compile-dependency/>
28
                    <run-dependency>
28
                    <run-dependency>
29
                        <release-version>3</release-version>
29
                        <release-version>3</release-version>
30
                        <specification-version>1.41</specification-version>
30
                        <specification-version>1.53</specification-version>
31
                    </run-dependency>
31
                    </run-dependency>
32
                </dependency>
32
                </dependency>
33
                <dependency>
33
                <dependency>
 Lines 44-51    Link Here 
44
                    <build-prerequisite/>
44
                    <build-prerequisite/>
45
                    <compile-dependency/>
45
                    <compile-dependency/>
46
                    <run-dependency>
46
                    <run-dependency>
47
                        <release-version>2</release-version>
47
                        <release-version>3</release-version>
48
                        <specification-version>2.1</specification-version>
48
                        <specification-version>3.1</specification-version>
49
                    </run-dependency>
49
                    </run-dependency>
50
                </dependency>
50
                </dependency>
51
                <dependency>
51
                <dependency>
(-)a/cnd.completion/nbproject/project.xml (-3 / +3 lines)
 Lines 87-93    Link Here 
87
                    <compile-dependency/>
87
                    <compile-dependency/>
88
                    <run-dependency>
88
                    <run-dependency>
89
                        <release-version>3</release-version>
89
                        <release-version>3</release-version>
90
                        <specification-version>1.41</specification-version>
90
                        <specification-version>1.53</specification-version>
91
                    </run-dependency>
91
                    </run-dependency>
92
                </dependency>
92
                </dependency>
93
                <dependency>
93
                <dependency>
 Lines 122-129    Link Here 
122
                    <build-prerequisite/>
122
                    <build-prerequisite/>
123
                    <compile-dependency/>
123
                    <compile-dependency/>
124
                    <run-dependency>
124
                    <run-dependency>
125
                        <release-version>2</release-version>
125
                        <release-version>3</release-version>
126
                        <specification-version>2.1</specification-version>
126
                        <specification-version>3.1</specification-version>
127
                    </run-dependency>
127
                    </run-dependency>
128
                </dependency>
128
                </dependency>
129
                <dependency>
129
                <dependency>
(-)a/cnd.debugger.common/nbproject/project.xml (-2 / +2 lines)
 Lines 79-86    Link Here 
79
                    <build-prerequisite/>
79
                    <build-prerequisite/>
80
                    <compile-dependency/>
80
                    <compile-dependency/>
81
                    <run-dependency>
81
                    <run-dependency>
82
                        <release-version>2</release-version>
82
                        <release-version>3</release-version>
83
                        <specification-version>2.7</specification-version>
83
                        <specification-version>3.1</specification-version>
84
                    </run-dependency>
84
                    </run-dependency>
85
                </dependency>
85
                </dependency>
86
                <dependency>
86
                <dependency>
(-)a/cnd.debugger.gdb/nbproject/project.xml (-2 / +2 lines)
 Lines 124-131    Link Here 
124
                    <build-prerequisite/>
124
                    <build-prerequisite/>
125
                    <compile-dependency/>
125
                    <compile-dependency/>
126
                    <run-dependency>
126
                    <run-dependency>
127
                        <release-version>2</release-version>
127
                        <release-version>3</release-version>
128
                        <specification-version>2.7</specification-version>
128
                        <specification-version>3.1</specification-version>
129
                    </run-dependency>
129
                    </run-dependency>
130
                </dependency>
130
                </dependency>
131
                <dependency>
131
                <dependency>
(-)a/cnd.editor/nbproject/project.xml (-3 / +3 lines)
 Lines 36-42    Link Here 
36
                    <compile-dependency/>
36
                    <compile-dependency/>
37
                    <run-dependency>
37
                    <run-dependency>
38
                        <release-version>3</release-version>
38
                        <release-version>3</release-version>
39
                        <specification-version>1.41</specification-version>
39
                        <specification-version>1.53</specification-version>
40
                    </run-dependency>
40
                    </run-dependency>
41
                </dependency>
41
                </dependency>
42
                <dependency>
42
                <dependency>
 Lines 71-78    Link Here 
71
                    <build-prerequisite/>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
72
                    <compile-dependency/>
73
                    <run-dependency>
73
                    <run-dependency>
74
                        <release-version>2</release-version>
74
                        <release-version>3</release-version>
75
                        <specification-version>2.1</specification-version>
75
                        <specification-version>3.1</specification-version>
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/CCKit.java (-40 / +38 lines)
 Lines 47-53    Link Here 
47
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionEvent;
48
import javax.swing.Action;
48
import javax.swing.Action;
49
import javax.swing.text.Caret;
49
import javax.swing.text.Caret;
50
import javax.swing.text.Position;
51
import javax.swing.text.Document;
50
import javax.swing.text.Document;
52
import javax.swing.text.JTextComponent;
51
import javax.swing.text.JTextComponent;
53
import javax.swing.text.TextAction;
52
import javax.swing.text.TextAction;
 Lines 228-279    Link Here 
228
                    return;
227
                    return;
229
                }
228
                }
230
229
231
                final BaseDocument doc = (BaseDocument) target.getDocument();
230
		final BaseDocument doc = (BaseDocument)target.getDocument();
231
                final Reformat formatter = Reformat.get(doc);
232
232
                // Set hourglass cursor
233
                // Set hourglass cursor
233
                Cursor origCursor = target.getCursor();
234
                Cursor origCursor = target.getCursor();
234
                target.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
235
                target.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
236
                
237
                formatter.lock();
238
                try {
239
                    doc.runAtomic(new Runnable() {
235
240
236
                doc.runAtomicAsUser(new Runnable() {
241
                        public void run() {
242
                            try {
243
                                Caret caret = target.getCaret();
237
244
238
                    public void run() {
245
                                int caretLine = Utilities.getLineOffset(doc, caret.getDot());
239
                        try {
246
                                int start;
240
                            Caret caret = target.getCaret();
247
                                int end;
248
                                //if (caret.isSelectionVisible()) {
249
                                if (Utilities.isSelectionShowing(caret)) {
250
                                    start = target.getSelectionStart();
251
                                    end = target.getSelectionEnd();
252
                                } else {
253
                                    start = 0;
254
                                    end = doc.getLength();
255
                                }
241
256
242
                            int caretLine = Utilities.getLineOffset(doc, caret.getDot());
257
                                formatter.reformat(start, end);
243
                            int startPos;
258
244
                            Position endPosition;
259
                                // Restore the line
245
                            //if (caret.isSelectionVisible()) {
260
                                int pos = Utilities.getRowStartFromLineOffset(doc, caretLine);
246
                            if (Utilities.isSelectionShowing(caret)) {
261
                                if (pos >= 0) {
247
                                startPos = target.getSelectionStart();
262
                                    caret.setDot(pos);
248
                                endPosition = doc.createPosition(target.getSelectionEnd());
263
                                }
249
                            } else {
264
                            } catch (BadLocationException e) {
250
                                startPos = 0;
265
                                //failed to format
251
                                endPosition = doc.createPosition(doc.getLength());
252
                            }
266
                            }
267
                        }
268
                    });
269
                } finally {
270
                    formatter.unlock();
271
                }
253
272
254
                            int pos = startPos;
255
                            Reformat reformat = Reformat.get(doc);
256
                            reformat.lock();
257
                            try {
258
                                reformat.reformat(pos, endPosition.getOffset());
259
                            } finally {
260
                                reformat.unlock();
261
                            }
262
263
                            // Restore the line
264
                            pos = Utilities.getRowStartFromLineOffset(doc, caretLine);
265
                            if (pos >= 0) {
266
                                caret.setDot(pos);
267
                            }
268
                        } catch (BadLocationException e) {
269
                            //failed to format
270
                        }
271
                    }
272
                });
273
                target.setCursor(origCursor);
273
                target.setCursor(origCursor);
274
274
	    }
275
            }
275
	}
276
        }
277
    }
276
    }
278
277
279
    public static class CCDefaultKeyTypedAction extends ExtDefaultKeyTypedAction {
278
    public static class CCDefaultKeyTypedAction extends ExtDefaultKeyTypedAction {
 Lines 372-379    Link Here 
372
                        }
371
                        }
373
                        doc.insertString(end, "\n" + insString, null); // NOI18N
372
                        doc.insertString(end, "\n" + insString, null); // NOI18N
374
                        // Lock does not need because method is invoked from BaseKit that already lock indent.
373
                        // Lock does not need because method is invoked from BaseKit that already lock indent.
375
                        Indent indent = Indent.get(doc);
374
                        Indent.get(doc).indentNewLine(end);
376
                        indent.reindent(end + 1);
377
                        caret.setDot(dotPos);
375
                        caret.setDot(dotPos);
378
                        return Boolean.TRUE;
376
                        return Boolean.TRUE;
379
                    }
377
                    }
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/InsertSemicolonAction.java (-15 / +20 lines)
 Lines 38-43    Link Here 
38
import org.netbeans.editor.BaseDocument;
38
import org.netbeans.editor.BaseDocument;
39
import org.netbeans.editor.Utilities;
39
import org.netbeans.editor.Utilities;
40
import org.netbeans.modules.editor.indent.api.Indent;
40
import org.netbeans.modules.editor.indent.api.Indent;
41
import org.openide.util.Exceptions;
41
import org.openide.util.NbBundle;
42
import org.openide.util.NbBundle;
42
43
43
/**
44
/**
 Lines 72-101    Link Here 
72
            return;
73
            return;
73
        }
74
        }
74
        final BaseDocument doc = (BaseDocument) target.getDocument();
75
        final BaseDocument doc = (BaseDocument) target.getDocument();
76
        final Indent indenter = Indent.get(doc);
75
        final class R implements Runnable {
77
        final class R implements Runnable {
76
            public void run() {
78
            public void run() {
77
                Caret caret = target.getCaret();
78
                int dotpos = caret.getDot();
79
                try {
79
                try {
80
                    Caret caret = target.getCaret();
81
                    int dotpos = caret.getDot();
80
                    int eoloffset = Utilities.getRowEnd(target, dotpos);
82
                    int eoloffset = Utilities.getRowEnd(target, dotpos);
81
                    String insertString = "" + what;
83
                    doc.insertString(eoloffset, "" + what, null); //NOI18N
82
                    doc.insertString(eoloffset, insertString, null); //NOI18N
83
                    if (withNewline) {
84
                    if (withNewline) {
84
                        Indent indent = Indent.get(doc);
85
                        //This is code from the editor module, but it is
85
                        indent.lock();
86
                        //a pretty strange way to do this:
86
                        try {
87
                        doc.insertString(dotpos, "-", null); //NOI18N
87
                            int eolDot = Utilities.getRowEnd(target, caret.getDot());
88
                        doc.remove(dotpos, 1);
88
                            doc.insertString(eolDot, "\n", null); // NOI18N
89
                        int eolDot = Utilities.getRowEnd(target, caret.getDot());
89
                            caret.setDot(eolDot+1);
90
                        int newDotPos = indenter.indentNewLine(eolDot);
90
                            indent.reindent(eolDot+1);
91
                        caret.setDot(newDotPos);
91
                        } finally {
92
                            indent.unlock();
93
                        }
94
                    }
92
                    }
95
                } catch (BadLocationException ex) {
93
                } catch (BadLocationException ex) {
94
                    Exceptions.printStackTrace(ex);
96
                }
95
                }
97
            }
96
            }
98
        }
97
        }
99
        doc.runAtomicAsUser(new R());
98
99
        indenter.lock();
100
        try {
101
            doc.runAtomicAsUser(new R());
102
        } finally {
103
            indenter.lock();
104
        }
100
    }
105
    }
101
}
106
}
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/EditorPropertySheet.java (-129 / +3 lines)
 Lines 55-60    Link Here 
55
import java.util.Collections;
55
import java.util.Collections;
56
import java.util.List;
56
import java.util.List;
57
import java.util.Map;
57
import java.util.Map;
58
import java.util.logging.Level;
59
import java.util.logging.Logger;
58
import java.util.prefs.PreferenceChangeEvent;
60
import java.util.prefs.PreferenceChangeEvent;
59
import java.util.prefs.PreferenceChangeListener;
61
import java.util.prefs.PreferenceChangeListener;
60
import java.util.prefs.Preferences;
62
import java.util.prefs.Preferences;
 Lines 62-75    Link Here 
62
import javax.swing.JEditorPane;
64
import javax.swing.JEditorPane;
63
import javax.swing.SwingUtilities;
65
import javax.swing.SwingUtilities;
64
import javax.swing.text.BadLocationException;
66
import javax.swing.text.BadLocationException;
65
import org.netbeans.api.editor.mimelookup.MimeLookup;
66
import org.netbeans.api.editor.settings.SimpleValueNames;
67
import org.netbeans.api.editor.settings.SimpleValueNames;
67
import org.netbeans.editor.BaseDocument;
68
import org.netbeans.editor.BaseDocument;
68
import org.netbeans.modules.cnd.editor.api.CodeStyle;
69
import org.netbeans.modules.cnd.editor.api.CodeStyle;
69
import org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter;
70
import org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter;
70
import org.netbeans.modules.cnd.editor.reformat.Reformatter;
71
import org.netbeans.modules.cnd.editor.reformat.Reformatter;
71
import org.netbeans.modules.cnd.utils.MIMENames;
72
import org.netbeans.modules.editor.indent.api.IndentUtils;
73
import org.openide.DialogDescriptor;
72
import org.openide.DialogDescriptor;
74
import org.openide.DialogDisplayer;
73
import org.openide.DialogDisplayer;
75
import org.openide.explorer.propertysheet.PropertySheet;
74
import org.openide.explorer.propertysheet.PropertySheet;
 Lines 98-104    Link Here 
98
    private PreviewPreferencesModel preferencesModel;
97
    private PreviewPreferencesModel preferencesModel;
99
    private Filter filter;
98
    private Filter filter;
100
    private PropertySheet holder;
99
    private PropertySheet holder;
101
    private Object[] originalEditorProperties = null;
102
100
103
    EditorPropertySheet(EditorOptionsPanelController topControler, CodeStyle.Language language, PreviewPreferencesModel preferencesModel, Filter filter) {
101
    EditorPropertySheet(EditorOptionsPanelController topControler, CodeStyle.Language language, PreviewPreferencesModel preferencesModel, Filter filter) {
104
        this.topController = topControler;
102
        this.topController = topControler;
 Lines 383-391    Link Here 
383
381
384
    void load() {
382
    void load() {
385
        loaded = false;
383
        loaded = false;
386
        if (filter == Filter.All) {
387
            originalEditorProperties = preserveEditorProperties();
388
        }
389
        initLanguageMap();
384
        initLanguageMap();
390
        initLanguageCategory();
385
        initLanguageCategory();
391
        loaded = true;
386
        loaded = true;
 Lines 449-458    Link Here 
449
        if (filter != Filter.All) {
444
        if (filter != Filter.All) {
450
            return;
445
            return;
451
        }
446
        }
452
        if (originalEditorProperties != null) {
453
            restoreEditorProperties(originalEditorProperties);
454
            originalEditorProperties = null;
455
        }
456
        preferencesModel.clear(language);
447
        preferencesModel.clear(language);
457
    }
448
    }
458
449
 Lines 581-587    Link Here 
581
                    is.close();
572
                    is.close();
582
                }
573
                }
583
            } catch (IOException ioe) {
574
            } catch (IOException ioe) {
584
                ioe.printStackTrace();
575
                Logger.getLogger(EditorPropertySheet.class.getName()).log(Level.FINE, null, ioe);
585
            }
576
            }
586
            return sb.toString();
577
            return sb.toString();
587
        } else {
578
        } else {
 Lines 593-719    Link Here 
593
        pane.setText(getPreviewText());
584
        pane.setText(getPreviewText());
594
        BaseDocument bd = (BaseDocument) pane.getDocument();
585
        BaseDocument bd = (BaseDocument) pane.getDocument();
595
        CodeStyle codeStyle = EditorOptions.createCodeStyle(language, p, false);
586
        CodeStyle codeStyle = EditorOptions.createCodeStyle(language, p, false);
596
        setEditorProperties(p);
597
        try {
587
        try {
598
            if (TRACE) {
599
                System.err.println("Refreshing preview"); // NOI18N
600
                System.err.println("          tabSize=" + IndentUtils.tabSize(bd)+"/"+codeStyle.getTabSize()); // NOI18N
601
                System.err.println("       expandTabs=" + IndentUtils.isExpandTabs(bd)+"/"+codeStyle.expandTabToSpaces()); // NOI18N
602
                System.err.println("  indentLevelSize=" + IndentUtils.indentLevelSize(bd)+"/"+codeStyle.indentSize()); // NOI18N
603
                System.err.println("  doc=" + bd); //NOI18N
604
            }
605
            new Reformatter(bd, codeStyle).reformat();
588
            new Reformatter(bd, codeStyle).reformat();
606
        } catch (BadLocationException ex) {
589
        } catch (BadLocationException ex) {
607
            Exceptions.printStackTrace(ex);
590
            Exceptions.printStackTrace(ex);
608
        } catch (Throwable ex) {
609
            ex.printStackTrace();
610
        }
611
    }
612
613
    private void setEditorProperties(Preferences p) {
614
        Preferences def = null;
615
        switch (language){
616
            case C:
617
                def = MimeLookup.getLookup(MIMENames.C_MIME_TYPE).lookup(Preferences.class);
618
                break;
619
            case HEADER:
620
                def = MimeLookup.getLookup(MIMENames.HEADER_MIME_TYPE).lookup(Preferences.class);
621
                break;
622
            case CPP:
623
            default:
624
                def = MimeLookup.getLookup(MIMENames.CPLUSPLUS_MIME_TYPE).lookup(Preferences.class);
625
                break;
626
        }
627
        if (def != null) {
628
            def.putInt(SimpleValueNames.TAB_SIZE, p.getInt(EditorOptions.tabSize, EditorOptions.tabSizeDefault));
629
            def.putInt(SimpleValueNames.SPACES_PER_TAB, p.getInt(EditorOptions.tabSize, EditorOptions.tabSizeDefault));
630
            def.putBoolean(SimpleValueNames.EXPAND_TABS, p.getBoolean(EditorOptions.expandTabToSpaces, EditorOptions.expandTabToSpacesDefault));
631
            def.putInt(SimpleValueNames.INDENT_SHIFT_WIDTH, p.getInt(EditorOptions.indentSize, EditorOptions.indentSizeDefault));
632
        }
633
    }
634
635
    private Object[] preserveEditorProperties() {
636
        Preferences def = null;
637
        Object oldValues[] = null;
638
        switch (language){
639
            case C:
640
                def = MimeLookup.getLookup(MIMENames.C_MIME_TYPE).lookup(Preferences.class);
641
                break;
642
            case HEADER:
643
                def = MimeLookup.getLookup(MIMENames.HEADER_MIME_TYPE).lookup(Preferences.class);
644
                break;
645
            case CPP:
646
            default:
647
                def = MimeLookup.getLookup(MIMENames.CPLUSPLUS_MIME_TYPE).lookup(Preferences.class);
648
                break;
649
        }
650
        if (def != null) {
651
            oldValues = new Object[]{null, null, null, null};
652
            if (null != def.get(SimpleValueNames.TAB_SIZE, null)) {
653
                oldValues[0] = def.getInt(SimpleValueNames.TAB_SIZE, EditorOptions.tabSizeDefault);
654
            }
655
            if (null != def.get(SimpleValueNames.SPACES_PER_TAB, null)) {
656
                oldValues[1] = def.getInt(SimpleValueNames.SPACES_PER_TAB, EditorOptions.tabSizeDefault);
657
            }
658
            if (null != def.get(SimpleValueNames.EXPAND_TABS, null)) {
659
                oldValues[2] = def.getBoolean(SimpleValueNames.EXPAND_TABS, EditorOptions.expandTabToSpacesDefault);
660
            }
661
            if (null != def.get(SimpleValueNames.INDENT_SHIFT_WIDTH, null)) {
662
                oldValues[3] = def.getInt(SimpleValueNames.INDENT_SHIFT_WIDTH, EditorOptions.indentSizeDefault);
663
            }
664
            if (TRACE) {
665
                System.err.println("Preserving editor properties:"); //NOI18N
666
                System.err.println("           tabSize=" + oldValues[0]); //NOI18N
667
                System.err.println("      spacesPerTab=" + oldValues[1]); //NOI18N
668
                System.err.println("        expandTabs=" + oldValues[2]); //NOI18N
669
                System.err.println("  indentShiftWidth=" + oldValues[3]); //NOI18N
670
            }
671
        }
672
        return oldValues;
673
    }
674
675
    private void restoreEditorProperties(Object[] oldValues) {
676
        Preferences def = null;
677
        switch (language){
678
            case C:
679
                def = MimeLookup.getLookup(MIMENames.C_MIME_TYPE).lookup(Preferences.class);
680
                break;
681
            case HEADER:
682
                def = MimeLookup.getLookup(MIMENames.HEADER_MIME_TYPE).lookup(Preferences.class);
683
                break;
684
            case CPP:
685
            default:
686
                def = MimeLookup.getLookup(MIMENames.CPLUSPLUS_MIME_TYPE).lookup(Preferences.class);
687
                break;
688
        }
689
        if (def != null && oldValues != null) {
690
            if (TRACE) {
691
                System.err.println("Restoring editor properties:"); //NOI18N
692
                System.err.println("           tabSize=" + oldValues[0]); //NOI18N
693
                System.err.println("      spacesPerTab=" + oldValues[1]); //NOI18N
694
                System.err.println("        expandTabs=" + oldValues[2]); //NOI18N
695
                System.err.println("  indentShiftWidth=" + oldValues[3]); //NOI18N
696
            }
697
            if (oldValues[0] == null) {
698
                def.remove(SimpleValueNames.TAB_SIZE);
699
            } else {
700
                def.putInt(SimpleValueNames.TAB_SIZE, ((Integer)oldValues[0]).intValue());
701
            }
702
            if (oldValues[1] == null) {
703
                def.remove(SimpleValueNames.SPACES_PER_TAB);
704
            } else {
705
                def.putInt(SimpleValueNames.SPACES_PER_TAB, ((Integer)oldValues[1]).intValue());
706
            }
707
            if (oldValues[2] == null) {
708
                def.remove(SimpleValueNames.EXPAND_TABS);
709
            } else {
710
                def.putBoolean(SimpleValueNames.EXPAND_TABS, ((Boolean)oldValues[2]).booleanValue());
711
            }
712
            if (oldValues[3] == null) {
713
                def.remove(SimpleValueNames.INDENT_SHIFT_WIDTH);
714
            } else {
715
                def.putInt(SimpleValueNames.INDENT_SHIFT_WIDTH, ((Integer)oldValues[3]).intValue());
716
            }
717
        }
591
        }
718
    }
592
    }
719
593
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/BracketCompletionTestCase.java (+2 lines)
 Lines 33-38    Link Here 
33
33
34
import org.netbeans.modules.cnd.editor.api.CodeStyle;
34
import org.netbeans.modules.cnd.editor.api.CodeStyle;
35
import org.netbeans.modules.cnd.editor.options.EditorOptions;
35
import org.netbeans.modules.cnd.editor.options.EditorOptions;
36
import org.netbeans.modules.editor.indent.api.Indent;
37
import org.openide.util.Exceptions;
36
38
37
/**
39
/**
38
 * Class was taken from java
40
 * Class was taken from java
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/EditorBase.java (-4 / +13 lines)
 Lines 42-47    Link Here 
42
import org.netbeans.modules.cnd.editor.reformat.Reformatter;
42
import org.netbeans.modules.cnd.editor.reformat.Reformatter;
43
import org.netbeans.modules.cnd.test.base.BaseDocumentUnitTestCase;
43
import org.netbeans.modules.cnd.test.base.BaseDocumentUnitTestCase;
44
import org.netbeans.modules.editor.indent.api.Indent;
44
import org.netbeans.modules.editor.indent.api.Indent;
45
import org.netbeans.modules.editor.indent.api.Reformat;
45
import org.openide.util.Exceptions;
46
import org.openide.util.Exceptions;
46
47
47
/**
48
/**
 Lines 145-158    Link Here 
145
    /**
146
    /**
146
     * Perform reformatting of the whole document's text.
147
     * Perform reformatting of the whole document's text.
147
     */
148
     */
148
    protected final void reformat() {
149
    protected void reformat() {
149
        Reformatter f = new Reformatter(getDocument(), CodeStyle.getDefault(getDocument()));
150
        Reformat f = Reformat.get(getDocument());
151
        f.lock();
150
        try {
152
        try {
151
            f.reformat();
153
            getDocument().atomicLock();
154
            try {
155
                f.reformat(0, getDocument().getLength());
156
            } finally {
157
                getDocument().atomicUnlock();
158
            }
152
        } catch (BadLocationException e) {
159
        } catch (BadLocationException e) {
153
            e.printStackTrace(getLog());
160
            e.printStackTrace(getLog());
154
            fail(e.getMessage());
161
            fail(e.getMessage());
155
    	}
162
        } finally {
163
            f.unlock();
164
        }
156
    }
165
    }
157
166
158
    // ------- help methods -------------
167
    // ------- help methods -------------
(-)a/cnd.gizmo/nbproject/project.xml (-2 / +2 lines)
 Lines 152-159    Link Here 
152
                    <build-prerequisite/>
152
                    <build-prerequisite/>
153
                    <compile-dependency/>
153
                    <compile-dependency/>
154
                    <run-dependency>
154
                    <run-dependency>
155
                        <release-version>2</release-version>
155
                        <release-version>3</release-version>
156
                        <specification-version>2.1</specification-version>
156
                        <specification-version>3.1</specification-version>
157
                    </run-dependency>
157
                    </run-dependency>
158
                </dependency>
158
                </dependency>
159
                <dependency>
159
                <dependency>
(-)a/cnd.gotodeclaration/nbproject/project.xml (+27 lines)
 Lines 50-55    Link Here 
50
                    </run-dependency>
50
                    </run-dependency>
51
                </dependency>
51
                </dependency>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.modules.editor.completion</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
58
                        <specification-version>1.6.12</specification-version>
59
                    </run-dependency>
60
                </dependency>
61
                <dependency>
62
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
65
                    <run-dependency>
66
                        <release-version>3</release-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
69
                </dependency>
70
                <dependency>
71
                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
72
                    <build-prerequisite/>
73
                    <compile-dependency/>
74
                    <run-dependency>
75
                        <release-version>1</release-version>
76
                        <specification-version>1.4.12</specification-version>
77
                    </run-dependency>
78
                </dependency>
79
                <dependency>
53
                    <code-name-base>org.netbeans.modules.jumpto</code-name-base>
80
                    <code-name-base>org.netbeans.modules.jumpto</code-name-base>
54
                    <build-prerequisite/>
81
                    <build-prerequisite/>
55
                    <compile-dependency/>
82
                    <compile-dependency/>
(-)a/cnd.highlight/nbproject/project.xml (-2 / +2 lines)
 Lines 106-113    Link Here 
106
                    <build-prerequisite/>
106
                    <build-prerequisite/>
107
                    <compile-dependency/>
107
                    <compile-dependency/>
108
                    <run-dependency>
108
                    <run-dependency>
109
                        <release-version>2</release-version>
109
                        <release-version>3</release-version>
110
                        <specification-version>2.1</specification-version>
110
                        <specification-version>3.1</specification-version>
111
                    </run-dependency>
111
                    </run-dependency>
112
                </dependency>
112
                </dependency>
113
                <dependency>
113
                <dependency>
(-)a/cnd.modelimpl/nbproject/project.xml (-2 / +2 lines)
 Lines 105-112    Link Here 
105
                    <build-prerequisite/>
105
                    <build-prerequisite/>
106
                    <compile-dependency/>
106
                    <compile-dependency/>
107
                    <run-dependency>
107
                    <run-dependency>
108
                        <release-version>2</release-version>
108
                        <release-version>3</release-version>
109
                        <specification-version>2.10</specification-version>
109
                        <specification-version>3.1</specification-version>
110
                    </run-dependency>
110
                    </run-dependency>
111
                </dependency>
111
                </dependency>
112
                <dependency>
112
                <dependency>
(-)a/cnd.modelutil/nbproject/project.xml (-3 / +3 lines)
 Lines 46-52    Link Here 
46
                    <compile-dependency/>
46
                    <compile-dependency/>
47
                    <run-dependency>
47
                    <run-dependency>
48
                        <release-version>3</release-version>
48
                        <release-version>3</release-version>
49
                        <specification-version>1.41</specification-version>
49
                        <specification-version>1.53</specification-version>
50
                    </run-dependency>
50
                    </run-dependency>
51
                </dependency>
51
                </dependency>
52
                <dependency>
52
                <dependency>
 Lines 54-61    Link Here 
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.1</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/cnd.navigation/nbproject/project.xml (-3 / +3 lines)
 Lines 54-60    Link Here 
54
                    <compile-dependency/>
54
                    <compile-dependency/>
55
                    <run-dependency>
55
                    <run-dependency>
56
                        <release-version>3</release-version>
56
                        <release-version>3</release-version>
57
                        <specification-version>1.42</specification-version>
57
                        <specification-version>1.53</specification-version>
58
                    </run-dependency>
58
                    </run-dependency>
59
                </dependency>
59
                </dependency>
60
                <dependency>
60
                <dependency>
 Lines 62-69    Link Here 
62
                    <build-prerequisite/>
62
                    <build-prerequisite/>
63
                    <compile-dependency/>
63
                    <compile-dependency/>
64
                    <run-dependency>
64
                    <run-dependency>
65
                        <release-version>2</release-version>
65
                        <release-version>3</release-version>
66
                        <specification-version>2.1</specification-version>
66
                        <specification-version>3.1</specification-version>
67
                    </run-dependency>
67
                    </run-dependency>
68
                </dependency>
68
                </dependency>
69
                <dependency>
69
                <dependency>
(-)a/cnd.refactoring/nbproject/project.xml (-3 / +3 lines)
 Lines 73-79    Link Here 
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>3</release-version>
75
                        <release-version>3</release-version>
76
                        <specification-version>1.41</specification-version>
76
                        <specification-version>1.53</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
 Lines 90-97    Link Here 
90
                    <build-prerequisite/>
90
                    <build-prerequisite/>
91
                    <compile-dependency/>
91
                    <compile-dependency/>
92
                    <run-dependency>
92
                    <run-dependency>
93
                        <release-version>2</release-version>
93
                        <release-version>3</release-version>
94
                        <specification-version>2.1</specification-version>
94
                        <specification-version>3.1</specification-version>
95
                    </run-dependency>
95
                    </run-dependency>
96
                </dependency>
96
                </dependency>
97
                <dependency>
97
                <dependency>
(-)a/cnd.script/nbproject/project.xml (-3 / +3 lines)
 Lines 37-43    Link Here 
37
                    <compile-dependency/>
37
                    <compile-dependency/>
38
                    <run-dependency>
38
                    <run-dependency>
39
                        <release-version>3</release-version>
39
                        <release-version>3</release-version>
40
                        <specification-version>1.48</specification-version>
40
                        <specification-version>1.53</specification-version>
41
                    </run-dependency>
41
                    </run-dependency>
42
                </dependency>
42
                </dependency>
43
                <dependency>
43
                <dependency>
 Lines 54-61    Link Here 
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.2</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/cnd.testrunner/nbproject/project.xml (-2 / +2 lines)
 Lines 95-102    Link Here 
95
                    <build-prerequisite/>
95
                    <build-prerequisite/>
96
                    <compile-dependency/>
96
                    <compile-dependency/>
97
                    <run-dependency>
97
                    <run-dependency>
98
                        <release-version>2</release-version>
98
                        <release-version>3</release-version>
99
                        <specification-version>2.1</specification-version>
99
                        <specification-version>3.1</specification-version>
100
                    </run-dependency>
100
                    </run-dependency>
101
                </dependency>
101
                </dependency>
102
                <dependency>
102
                <dependency>
(-)a/cnd/nbproject/project.xml (-1 / +28 lines)
 Lines 61-67    Link Here 
61
                    <compile-dependency/>
61
                    <compile-dependency/>
62
                    <run-dependency>
62
                    <run-dependency>
63
                        <release-version>2</release-version>
63
                        <release-version>2</release-version>
64
                        <specification-version>1.9</specification-version>
64
                        <specification-version>1.10</specification-version>
65
                    </run-dependency>
66
                </dependency>
67
                <dependency>
68
                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
69
                    <build-prerequisite/>
70
                    <compile-dependency/>
71
                    <run-dependency>
72
                        <release-version>1</release-version>
73
                        <specification-version>1.10</specification-version>
74
                    </run-dependency>
75
                </dependency>
76
                <dependency>
77
                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
78
                    <build-prerequisite/>
79
                    <compile-dependency/>
80
                    <run-dependency>
81
                        <release-version>1</release-version>
82
                        <specification-version>1.22</specification-version>
65
                    </run-dependency>
83
                    </run-dependency>
66
                </dependency>
84
                </dependency>
67
                <dependency>
85
                <dependency>
 Lines 70-75    Link Here 
70
                    <compile-dependency/>
88
                    <compile-dependency/>
71
                    <run-dependency>
89
                    <run-dependency>
72
                        <release-version>2</release-version>
90
                        <release-version>2</release-version>
91
                        <specification-version>1.22</specification-version>
92
                    </run-dependency>
93
                </dependency>
94
                <dependency>
95
                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
98
                    <run-dependency>
99
                        <release-version>2</release-version>
73
                        <specification-version>1.16</specification-version>
100
                        <specification-version>1.16</specification-version>
74
                    </run-dependency>
101
                    </run-dependency>
75
                </dependency>
102
                </dependency>
(-)a/collab.channel.chat/nbproject/project.xml (-4 / +4 lines)
 Lines 65-71    Link Here 
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>3</release-version>
67
                        <release-version>3</release-version>
68
                    <specification-version>1.41</specification-version>
68
                    <specification-version>1.53</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>
 Lines 73-80    Link Here 
73
                    <build-prerequisite/>
73
                    <build-prerequisite/>
74
                    <compile-dependency/>
74
                    <compile-dependency/>
75
                    <run-dependency>
75
                    <run-dependency>
76
                        <release-version>2</release-version>
76
                        <release-version>3</release-version>
77
                    <specification-version>2.1</specification-version>
77
                    <specification-version>3.1</specification-version>
78
                    </run-dependency>
78
                    </run-dependency>
79
                </dependency>
79
                </dependency>
80
                <dependency>
80
                <dependency>
 Lines 125-131    Link Here 
125
                        <specification-version>6.2</specification-version>
125
                        <specification-version>6.2</specification-version>
126
                    </run-dependency>
126
                    </run-dependency>
127
                </dependency>
127
                </dependency>
128
                </module-dependencies>
128
            </module-dependencies>
129
            <public-packages>
129
            <public-packages>
130
                <package>org.netbeans.modules.collab.channel.chat</package>
130
                <package>org.netbeans.modules.collab.channel.chat</package>
131
                <package>org.netbeans.modules.collab.channel.chat.messagetype</package>
131
                <package>org.netbeans.modules.collab.channel.chat.messagetype</package>
(-)a/compapp.casaeditor/nbproject/project.xml (-2 / +2 lines)
 Lines 123-130    Link Here 
123
                    <build-prerequisite/>
123
                    <build-prerequisite/>
124
                    <compile-dependency/>
124
                    <compile-dependency/>
125
                    <run-dependency>
125
                    <run-dependency>
126
                        <release-version>2</release-version>
126
                        <release-version>3</release-version>
127
                        <specification-version>2.1</specification-version>
127
                        <specification-version>3.1</specification-version>
128
                    </run-dependency>
128
                    </run-dependency>
129
                </dependency>
129
                </dependency>
130
                <dependency>
130
                <dependency>
(-)a/compapp.projects.base/nbproject/project.xml (-2 / +2 lines)
 Lines 64-71    Link Here 
64
                    <build-prerequisite/>
64
                    <build-prerequisite/>
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>2</release-version>
67
                        <release-version>3</release-version>
68
                        <specification-version>2.1</specification-version>
68
                        <specification-version>3.1</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>
(-)a/compapp.projects.jbi/nbproject/project.xml (-2 / +2 lines)
 Lines 174-181    Link Here 
174
                    <build-prerequisite/>
174
                    <build-prerequisite/>
175
                    <compile-dependency/>
175
                    <compile-dependency/>
176
                    <run-dependency>
176
                    <run-dependency>
177
                        <release-version>2</release-version>
177
                        <release-version>3</release-version>
178
                        <specification-version>2.1</specification-version>
178
                        <specification-version>3.1</specification-version>
179
                    </run-dependency>
179
                    </run-dependency>
180
                </dependency>
180
                </dependency>
181
                <dependency>
181
                <dependency>
(-)a/csl.api/nbproject/project.xml (-3 / +3 lines)
 Lines 56-62    Link Here 
56
                    <compile-dependency/>
56
                    <compile-dependency/>
57
                    <run-dependency>
57
                    <run-dependency>
58
                        <release-version>3</release-version>
58
                        <release-version>3</release-version>
59
                        <specification-version>1.41</specification-version>
59
                        <specification-version>1.53</specification-version>
60
                    </run-dependency>
60
                    </run-dependency>
61
                </dependency>
61
                </dependency>
62
                <dependency>
62
                <dependency>
 Lines 118-125    Link Here 
118
                    <build-prerequisite/>
118
                    <build-prerequisite/>
119
                    <compile-dependency/>
119
                    <compile-dependency/>
120
                    <run-dependency>
120
                    <run-dependency>
121
                        <release-version>2</release-version>
121
                        <release-version>3</release-version>
122
                        <specification-version>2.1</specification-version>
122
                        <specification-version>3.1</specification-version>
123
                    </run-dependency>
123
                    </run-dependency>
124
                </dependency>
124
                </dependency>
125
                <dependency>
125
                <dependency>
(-)a/css.editor/nbproject/project.xml (-3 / +3 lines)
 Lines 29-35    Link Here 
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>3</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>1.41</specification-version>
32
                        <specification-version>1.53</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
 Lines 55-62    Link Here 
55
                    <build-prerequisite/>
55
                    <build-prerequisite/>
56
                    <compile-dependency/>
56
                    <compile-dependency/>
57
                    <run-dependency>
57
                    <run-dependency>
58
                        <release-version>2</release-version>
58
                        <release-version>3</release-version>
59
                        <specification-version>2.1</specification-version>
59
                        <specification-version>3.1</specification-version>
60
                    </run-dependency>
60
                    </run-dependency>
61
                </dependency>
61
                </dependency>
62
                <dependency>
62
                <dependency>
(-)a/css.visual/nbproject/project.xml (-3 / +12 lines)
 Lines 82-88    Link Here 
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>3</release-version>
84
                        <release-version>3</release-version>
85
                        <specification-version>1.41</specification-version>
85
                        <specification-version>1.53</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
 Lines 95-106    Link Here 
95
                    </run-dependency>
95
                    </run-dependency>
96
                </dependency>
96
                </dependency>
97
                <dependency>
97
                <dependency>
98
                    <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
99
                    <build-prerequisite/>
100
                    <compile-dependency/>
101
                    <run-dependency>
102
                        <release-version>2</release-version>
103
                        <specification-version>1.9</specification-version>
104
                    </run-dependency>
105
                </dependency>
106
                <dependency>
98
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
107
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
99
                    <build-prerequisite/>
108
                    <build-prerequisite/>
100
                    <compile-dependency/>
109
                    <compile-dependency/>
101
                    <run-dependency>
110
                    <run-dependency>
102
                        <release-version>2</release-version>
111
                        <release-version>3</release-version>
103
                        <specification-version>2.1</specification-version>
112
                        <specification-version>3.1</specification-version>
104
                    </run-dependency>
113
                    </run-dependency>
105
                </dependency>
114
                </dependency>
106
                <dependency>
115
                <dependency>
(-)a/css.visual/src/org/netbeans/modules/css/editor/CssEditorSupport.java (-9 / +18 lines)
 Lines 63-68    Link Here 
63
import org.netbeans.modules.css.visual.ui.preview.CssPreviewable;
63
import org.netbeans.modules.css.visual.ui.preview.CssPreviewable;
64
import org.netbeans.modules.css.visual.ui.preview.CssPreviewable.Listener;
64
import org.netbeans.modules.css.visual.ui.preview.CssPreviewable.Listener;
65
import org.netbeans.modules.editor.NbEditorDocument;
65
import org.netbeans.modules.editor.NbEditorDocument;
66
import org.netbeans.modules.editor.indent.api.IndentUtils;
67
import org.openide.cookies.EditorCookie;
68
import org.openide.filesystems.FileObject;
66
import org.openide.filesystems.FileUtil;
69
import org.openide.filesystems.FileUtil;
67
70
68
/**
71
/**
 Lines 139-145    Link Here 
139
                            } else if (oldRule == null && newRule != null) {
142
                            } else if (oldRule == null && newRule != null) {
140
                                //add the new rule at the end of the rule block:
143
                                //add the new rule at the end of the rule block:
141
                                List<CssRuleItem> items = myRule.items();
144
                                List<CssRuleItem> items = myRule.items();
142
                                final int INDENT = doc.getFormatter().getShiftWidth();
145
                                final int INDENT = IndentUtils.indentLevelSize(document);
143
                                int insertOffset = myRule.getRuleCloseBracketOffset();
146
                                int insertOffset = myRule.getRuleCloseBracketOffset();
144
147
145
                                boolean initialNewLine = false;
148
                                boolean initialNewLine = false;
 Lines 160-166    Link Here 
160
                                }
163
                                }
161
164
162
                                String text = (initialNewLine ? LINE_SEPARATOR : "") +
165
                                String text = (initialNewLine ? LINE_SEPARATOR : "") +
163
                                        makeIndentString(INDENT) +
166
// XXX: see the method comment
167
//                                        makeIndentString(INDENT) +
168
                                        IndentUtils.createIndentString(document, INDENT) +
164
                                        newRule.key().name() + ": " + newRule.value().name() + ";" +
169
                                        newRule.key().name() + ": " + newRule.value().name() + ";" +
165
                                        LINE_SEPARATOR;
170
                                        LINE_SEPARATOR;
166
171
 Lines 189-201    Link Here 
189
        }
194
        }
190
    };
195
    };
191
196
192
    private String makeIndentString(int level) {
197
    // XXX: This is most likely wrong! Unless CSS only allows spaces for indentation.
193
        StringBuffer sb = new StringBuffer();
198
    // But even then the same should be achieved by correctly setting the indentation
194
        for (int i = 0; i < level; i++) {
199
    // settings. Otherwise a simple Reformat.get(doc).reformat(...) call on a CSS document
195
            sb.append(' ');
200
    // could break its structure.
196
        }
201
//    private String makeIndentString(int level) {
197
        return sb.toString();
202
//        StringBuffer sb = new StringBuffer();
198
    }
203
//        for (int i = 0; i < level; i++) {
204
//            sb.append(' ');
205
//        }
206
//        return sb.toString();
207
//    }
199
208
200
    void parsed(final CssParserResult result, final int caretOffset) {
209
    void parsed(final CssParserResult result, final int caretOffset) {
201
        d("model updated");
210
        d("model updated");
(-)a/db.core/nbproject/project.xml (-2 / +2 lines)
 Lines 80-87    Link Here 
80
                    <build-prerequisite/>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
81
                    <compile-dependency/>
82
                    <run-dependency>
82
                    <run-dependency>
83
                        <release-version>2</release-version>
83
                        <release-version>3</release-version>
84
                        <specification-version>2.1</specification-version>
84
                        <specification-version>3.1</specification-version>
85
                    </run-dependency>
85
                    </run-dependency>
86
                </dependency>
86
                </dependency>
87
                <dependency>
87
                <dependency>
(-)a/db.sql.editor/nbproject/project.xml (-3 / +12 lines)
 Lines 98-104    Link Here 
98
                    <compile-dependency/>
98
                    <compile-dependency/>
99
                    <run-dependency>
99
                    <run-dependency>
100
                        <release-version>3</release-version>
100
                        <release-version>3</release-version>
101
                        <specification-version>1.41</specification-version>
101
                    <specification-version>1.53</specification-version>
102
                    </run-dependency>
102
                    </run-dependency>
103
                </dependency>
103
                </dependency>
104
                <dependency>
104
                <dependency>
 Lines 115-122    Link Here 
115
                    <build-prerequisite/>
115
                    <build-prerequisite/>
116
                    <compile-dependency/>
116
                    <compile-dependency/>
117
                    <run-dependency>
117
                    <run-dependency>
118
                        <release-version>2</release-version>
118
                        <release-version>3</release-version>
119
                        <specification-version>2.1</specification-version>
119
                        <specification-version>3.1</specification-version>
120
                    </run-dependency>
120
                    </run-dependency>
121
                </dependency>
121
                </dependency>
122
                <dependency>
122
                <dependency>
 Lines 232-237    Link Here 
232
                        <specification-version>8.0</specification-version>
232
                        <specification-version>8.0</specification-version>
233
                    </run-dependency>
233
                    </run-dependency>
234
                </dependency>
234
                </dependency>
235
                <dependency>
236
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
237
                    <build-prerequisite/>
238
                    <compile-dependency/>
239
                    <run-dependency>
240
                        <release-version>0-1</release-version>
241
                        <specification-version>1.0</specification-version>
242
                    </run-dependency>
243
                </dependency>
235
            </module-dependencies>
244
            </module-dependencies>
236
            <test-dependencies>
245
            <test-dependencies>
237
                <test-type>
246
                <test-type>
(-)a/debugger.jpda.ant/nbproject/project.xml (-5 / +5 lines)
 Lines 101-108    Link Here 
101
                    <build-prerequisite/>
101
                    <build-prerequisite/>
102
                    <compile-dependency/>
102
                    <compile-dependency/>
103
                    <run-dependency>
103
                    <run-dependency>
104
                        <release-version>2</release-version>
104
                        <release-version>3</release-version>
105
                        <specification-version>2.1</specification-version>
105
                        <specification-version>3.1</specification-version>
106
                    </run-dependency>
106
                    </run-dependency>
107
                </dependency>
107
                </dependency>
108
                <dependency>
108
                <dependency>
 Lines 147-155    Link Here 
147
                    <code-name-base>org.openide.util.lookup</code-name-base>
147
                    <code-name-base>org.openide.util.lookup</code-name-base>
148
                    <build-prerequisite/>
148
                    <build-prerequisite/>
149
                    <compile-dependency/>
149
                    <compile-dependency/>
150
		    <run-dependency>
150
                    <run-dependency>
151
                       <specification-version>8.0</specification-version>
151
                        <specification-version>8.0</specification-version>
152
	             </run-dependency>
152
                    </run-dependency>
153
                </dependency>
153
                </dependency>
154
            </module-dependencies>
154
            </module-dependencies>
155
            <public-packages/>
155
            <public-packages/>
(-)a/debugger.jpda.projects/nbproject/project.xml (-2 / +2 lines)
 Lines 96-103    Link Here 
96
                    <build-prerequisite/>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
97
                    <compile-dependency/>
98
                    <run-dependency>
98
                    <run-dependency>
99
                        <release-version>2</release-version>
99
                        <release-version>3</release-version>
100
                        <specification-version>2.10</specification-version>
100
                        <specification-version>3.1</specification-version>
101
                    </run-dependency>
101
                    </run-dependency>
102
                </dependency>
102
                </dependency>
103
                <dependency>
103
                <dependency>
(-)a/debugger.jpda.ui/nbproject/project.xml (-2 / +2 lines)
 Lines 103-110    Link Here 
103
                    <build-prerequisite/>
103
                    <build-prerequisite/>
104
                    <compile-dependency/>
104
                    <compile-dependency/>
105
                    <run-dependency>
105
                    <run-dependency>
106
                        <release-version>2</release-version>
106
                        <release-version>3</release-version>
107
                        <specification-version>2.1</specification-version>
107
                        <specification-version>3.1</specification-version>
108
                    </run-dependency>
108
                    </run-dependency>
109
                </dependency>
109
                </dependency>
110
                <dependency>
110
                <dependency>
(-)a/debugger.jpda/nbproject/project.xml (-2 / +2 lines)
 Lines 96-103    Link Here 
96
                    <build-prerequisite/>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
97
                    <compile-dependency/>
98
                    <run-dependency>
98
                    <run-dependency>
99
                        <release-version>2</release-version>
99
                        <release-version>3</release-version>
100
                        <specification-version>2.1</specification-version>
100
                        <specification-version>3.1</specification-version>
101
                    </run-dependency>
101
                    </run-dependency>
102
                </dependency>
102
                </dependency>
103
                <dependency>
103
                <dependency>
(-)a/diff/nbproject/project.xml (-2 / +2 lines)
 Lines 87-94    Link Here 
87
                    <build-prerequisite/>
87
                    <build-prerequisite/>
88
                    <compile-dependency/>
88
                    <compile-dependency/>
89
                    <run-dependency>
89
                    <run-dependency>
90
                        <release-version>2</release-version>
90
                        <release-version>3</release-version>
91
                        <specification-version>2.1</specification-version>
91
                        <specification-version>3.1</specification-version>
92
                    </run-dependency>
92
                    </run-dependency>
93
                </dependency>
93
                </dependency>
94
                <dependency>
94
                <dependency>
(-)a/dlight.annotationsupport/nbproject/project.xml (-2 / +2 lines)
 Lines 60-67    Link Here 
60
                    <build-prerequisite/>
60
                    <build-prerequisite/>
61
                    <compile-dependency/>
61
                    <compile-dependency/>
62
                    <run-dependency>
62
                    <run-dependency>
63
                        <release-version>2</release-version>
63
                        <release-version>3</release-version>
64
                        <specification-version>2.1</specification-version>
64
                        <specification-version>3.1</specification-version>
65
                    </run-dependency>
65
                    </run-dependency>
66
                </dependency>
66
                </dependency>
67
                <dependency>
67
                <dependency>
(-)a/editor.actions/nbproject/project.xml (-2 / +2 lines)
 Lines 54-61    Link Here 
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.1</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/editor.bookmarks/nbproject/project.xml (-4 / +4 lines)
 Lines 55-61    Link Here 
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>3</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>1.41</specification-version>
58
                        <specification-version>1.53</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
 Lines 63-70    Link Here 
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
 Lines 152-158    Link Here 
152
                    <build-prerequisite/>
152
                    <build-prerequisite/>
153
                    <compile-dependency/>
153
                    <compile-dependency/>
154
                    <run-dependency>
154
                    <run-dependency>
155
                        <specification-version>8.0</specification-version>
155
                        <specification-version>8.4</specification-version>
156
                    </run-dependency>
156
                    </run-dependency>
157
                </dependency>
157
                </dependency>
158
            </module-dependencies>
158
            </module-dependencies>
(-)a/editor.bracesmatching/nbproject/project.xml (-3 / +3 lines)
 Lines 20-26    Link Here 
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>3</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>1.41</specification-version>
23
                        <specification-version>1.53</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
 Lines 28-35    Link Here 
28
                    <build-prerequisite/>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>2</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>2.1</specification-version>
32
                        <specification-version>3.1</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
(-)a/editor.codetemplates/nbproject/project.xml (-3 / +12 lines)
 Lines 64-70    Link Here 
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>3</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>1.41</specification-version>
67
                        <specification-version>1.53</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
 Lines 76-87    Link Here 
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
79
                    <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
82
                    <run-dependency>
83
                        <release-version>2</release-version>
84
                        <specification-version>1.9</specification-version>
85
                    </run-dependency>
86
                </dependency>
87
                <dependency>
79
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
88
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
80
                    <build-prerequisite/>
89
                    <build-prerequisite/>
81
                    <compile-dependency/>
90
                    <compile-dependency/>
82
                    <run-dependency>
91
                    <run-dependency>
83
                        <release-version>2</release-version>
92
                        <release-version>3</release-version>
84
                        <specification-version>2.1</specification-version>
93
                        <specification-version>3.1</specification-version>
85
                    </run-dependency>
94
                    </run-dependency>
86
                </dependency>
95
                </dependency>
87
                <dependency>
96
                <dependency>
(-)a/editor.codetemplates/src/org/netbeans/lib/editor/codetemplates/CodeTemplateInsertHandler.java (-22 / +10 lines)
 Lines 61-67    Link Here 
61
import javax.swing.undo.CannotUndoException;
61
import javax.swing.undo.CannotUndoException;
62
import org.netbeans.api.editor.completion.Completion;
62
import org.netbeans.api.editor.completion.Completion;
63
import org.netbeans.editor.BaseDocument;
63
import org.netbeans.editor.BaseDocument;
64
import org.netbeans.editor.Formatter;
65
import org.netbeans.editor.Utilities;
64
import org.netbeans.editor.Utilities;
66
import org.netbeans.lib.editor.codetemplates.api.CodeTemplate;
65
import org.netbeans.lib.editor.codetemplates.api.CodeTemplate;
67
import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateInsertRequest;
66
import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateInsertRequest;
 Lines 77-82    Link Here 
77
import org.netbeans.lib.editor.util.CharSequenceUtilities;
76
import org.netbeans.lib.editor.util.CharSequenceUtilities;
78
import org.netbeans.lib.editor.util.CharacterConversions;
77
import org.netbeans.lib.editor.util.CharacterConversions;
79
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
78
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
79
import org.netbeans.modules.editor.indent.api.Reformat;
80
80
81
/**
81
/**
82
 * Code template allows the client to paste itself into the given
82
 * Code template allows the client to paste itself into the given
 Lines 125-131    Link Here 
125
125
126
    private String completeInsertString;
126
    private String completeInsertString;
127
127
128
    private Formatter formatter;
128
    private Reformat formatter;
129
    
129
    
130
    private TextSyncGroup textSyncGroup;
130
    private TextSyncGroup textSyncGroup;
131
    
131
    
 Lines 247-276    Link Here 
247
        // Build insert string outside of the atomic lock
247
        // Build insert string outside of the atomic lock
248
        completeInsertString = getInsertText();
248
        completeInsertString = getInsertText();
249
249
250
        BaseDocument bdoc = (doc instanceof BaseDocument)
250
251
                ? (BaseDocument)doc
252
                : null;
253
        // Need to lock formatter first because CT's multiline text will be reformatted
251
        // Need to lock formatter first because CT's multiline text will be reformatted
254
        formatter = null;
252
        formatter = Reformat.get(doc);
255
        if (bdoc != null) {
253
        formatter.lock();
256
            formatter = bdoc.getFormatter();
257
            if (formatter != null) {
258
                formatter.reformatLock();
259
            }
260
        }
261
        try {
254
        try {
262
            if (bdoc != null) {
255
            if (doc instanceof BaseDocument) {
263
                bdoc.runAtomicAsUser(this);
256
                ((BaseDocument) doc).runAtomicAsUser(this);
264
            } else { // Otherwise run without atomic locking
257
            } else { // Otherwise run without atomic locking
265
                this.run();
258
                this.run();
266
            }
259
            }
267
        } finally {
260
        } finally {
268
            if (bdoc != null) {
261
            formatter.unlock();
269
                if (formatter != null) {
262
            formatter = null;
270
                    formatter.reformatUnlock();
271
                }
272
                formatter = null;
273
            }
274
            completeInsertString = null;
263
            completeInsertString = null;
275
        }
264
        }
276
    }
265
    }
 Lines 344-351    Link Here 
344
            this.inserted = true;
333
            this.inserted = true;
345
            
334
            
346
            if (bdoc != null) {
335
            if (bdoc != null) {
347
                formatter.reformat(bdoc, pos.getOffset(),
336
                formatter.reformat(pos.getOffset(), pos.getOffset() + completeInsertString.length());
348
                        pos.getOffset() + completeInsertString.length());
349
            }
337
            }
350
338
351
            if (!released) {
339
            if (!released) {
(-)a/editor.completion/nbproject/project.xml (-3 / +3 lines)
 Lines 55-61    Link Here 
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>3</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>1.41</specification-version>
58
                        <specification-version>1.53</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
 Lines 63-70    Link Here 
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/editor.deprecated.pre61completion/nbproject/project.xml (-2 / +2 lines)
 Lines 19-26    Link Here 
19
                    <build-prerequisite/>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>2</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>2.1</specification-version>
23
                        <specification-version>3.1</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
(-)a/editor.deprecated.pre61settings/nbproject/project.xml (-1 / +10 lines)
 Lines 59-69    Link Here 
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
62
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
65
                    <run-dependency>
66
                        <release-version>0-1</release-version>
67
                        <specification-version>1.0</specification-version>
68
                    </run-dependency>
69
                </dependency>
70
                <dependency>
62
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
71
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
63
                    <build-prerequisite/>
72
                    <build-prerequisite/>
64
                    <compile-dependency/>
73
                    <compile-dependency/>
65
                    <run-dependency>
74
                    <run-dependency>
66
                        <release-version>2</release-version>
75
                        <release-version>3</release-version>
67
                        <implementation-version/>
76
                        <implementation-version/>
68
                    </run-dependency>
77
                    </run-dependency>
69
                </dependency>
78
                </dependency>
(-)a/editor.deprecated.pre65formatting/build.xml (+5 lines)
Line 0    Link Here 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="netbeans" name="editor.deprecated.pre65formatting">
3
    <description>Builds, tests, and runs the project org.netbeans.modules.editor.deprecated.pre65formatting</description>
4
    <import file="../nbbuild/templates/projectized.xml"/>
5
</project>
(-)a/editor.deprecated.pre65formatting/manifest.mf (+6 lines)
Line 0    Link Here 
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor.deprecated.pre65formatting/0
3
OpenIDE-Module-Implementation-Version: 1
4
OpenIDE-Module-Layer: org/netbeans/modules/editor/deprecated/pre65formatting/layer.xml
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/deprecated/pre65formatting/Bundle.properties
6
OpenIDE-Module-Deprecated: true
(-)a/editor.deprecated.pre65formatting/nbproject/project.properties (+4 lines)
Line 0    Link Here 
1
is.autoload=true
2
javac.source=1.5
3
javac.compilerargs=-Xlint -Xlint:-serial
4
spec.version.base=1.0
(-)a/editor.deprecated.pre65formatting/nbproject/project.xml (+103 lines)
Line 0    Link Here 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://www.netbeans.org/ns/project/1">
3
    <type>org.netbeans.modules.apisupport.project</type>
4
    <configuration>
5
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
6
            <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
7
            <module-dependencies>
8
                <dependency>
9
                    <code-name-base>org.netbeans.modules.editor</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <release-version>3</release-version>
14
                        <implementation-version/>
15
                    </run-dependency>
16
                </dependency>
17
                <dependency>
18
                    <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <release-version>2</release-version>
23
                        <specification-version>1.10</specification-version>
24
                    </run-dependency>
25
                </dependency>
26
                <dependency>
27
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
30
                    <run-dependency>
31
                        <release-version>3</release-version>
32
                        <implementation-version/>
33
                    </run-dependency>
34
                </dependency>
35
                <dependency>
36
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
39
                    <run-dependency>
40
                        <release-version>1</release-version>
41
                        <implementation-version/>
42
                    </run-dependency>
43
                </dependency>
44
                <dependency>
45
                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
46
                    <build-prerequisite/>
47
                    <compile-dependency/>
48
                    <run-dependency>
49
                        <release-version>1</release-version>
50
                        <specification-version>1.10</specification-version>
51
                    </run-dependency>
52
                </dependency>
53
                <dependency>
54
                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
55
                    <build-prerequisite/>
56
                    <compile-dependency/>
57
                    <run-dependency>
58
                        <release-version>1</release-version>
59
                        <specification-version>1.22</specification-version>
60
                    </run-dependency>
61
                </dependency>
62
                <dependency>
63
                    <code-name-base>org.netbeans.modules.editor.util</code-name-base>
64
                    <build-prerequisite/>
65
                    <compile-dependency/>
66
                    <run-dependency>
67
                        <release-version>1</release-version>
68
                        <specification-version>1.25</specification-version>
69
                    </run-dependency>
70
                </dependency>
71
                <dependency>
72
                    <code-name-base>org.openide.text</code-name-base>
73
                    <build-prerequisite/>
74
                    <compile-dependency/>
75
                    <run-dependency>
76
                        <specification-version>6.21</specification-version>
77
                    </run-dependency>
78
                </dependency>
79
                <dependency>
80
                    <code-name-base>org.openide.util</code-name-base>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
83
                    <run-dependency>
84
                        <specification-version>7.18</specification-version>
85
                    </run-dependency>
86
                </dependency>
87
                <dependency>
88
                    <code-name-base>org.openide.util.lookup</code-name-base>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
91
                    <run-dependency>
92
                        <specification-version>8.4</specification-version>
93
                    </run-dependency>
94
                </dependency>
95
            </module-dependencies>
96
            <public-packages>
97
                <package>org.netbeans.editor</package>
98
                <package>org.netbeans.editor.ext</package>
99
                <package>org.netbeans.modules.editor</package>
100
            </public-packages>
101
        </data>
102
    </configuration>
103
</project>
(-)a/editor.lib/src/org/netbeans/editor/Formatter.java (-48 / +29 lines)
 Lines 48-57    Link Here 
48
import java.io.IOException;
48
import java.io.IOException;
49
import java.io.Writer;
49
import java.io.Writer;
50
import java.io.CharArrayWriter;
50
import java.io.CharArrayWriter;
51
import java.lang.ref.Reference;
52
import java.lang.ref.WeakReference;
51
import java.lang.ref.WeakReference;
53
import java.lang.reflect.Method;
52
import java.lang.reflect.Method;
54
import java.util.Stack;
55
import java.util.WeakHashMap;
53
import java.util.WeakHashMap;
56
import java.util.prefs.PreferenceChangeEvent;
54
import java.util.prefs.PreferenceChangeEvent;
57
import java.util.prefs.PreferenceChangeListener;
55
import java.util.prefs.PreferenceChangeListener;
 Lines 64-69    Link Here 
64
import org.netbeans.api.editor.settings.SimpleValueNames;
62
import org.netbeans.api.editor.settings.SimpleValueNames;
65
import org.netbeans.lib.editor.util.CharSequenceUtilities;
63
import org.netbeans.lib.editor.util.CharSequenceUtilities;
66
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
64
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
65
import org.netbeans.modules.editor.deprecated.pre65formatting.LegacyFormattersProvider;
67
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
66
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
68
import org.netbeans.modules.editor.lib.KitsTracker;
67
import org.netbeans.modules.editor.lib.KitsTracker;
69
import org.netbeans.modules.editor.lib.SettingsConversions;
68
import org.netbeans.modules.editor.lib.SettingsConversions;
 Lines 106-112    Link Here 
106
        } else {
105
        } else {
107
            Formatter formatter = kitClass2Formatter.get(kitClass);
106
            Formatter formatter = kitClass2Formatter.get(kitClass);
108
            if (formatter == null) {
107
            if (formatter == null) {
109
                formatter = BaseKit.getKit(kitClass).createFormatter();
108
                BaseKit kit = BaseKit.getKit(kitClass);
109
                formatter = callCreateFormatterMethod(kit);
110
                kitClass2Formatter.put(kitClass, formatter);
110
                kitClass2Formatter.put(kitClass, formatter);
111
            }
111
            }
112
            return formatter;
112
            return formatter;
 Lines 130-138    Link Here 
130
        if (formatter == null) {
130
        if (formatter == null) {
131
            EditorKit editorKit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
131
            EditorKit editorKit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
132
            if (editorKit instanceof BaseKit) {
132
            if (editorKit instanceof BaseKit) {
133
                formatter = ((BaseKit) editorKit).createFormatter();
133
                formatter = callCreateFormatterMethod((BaseKit) editorKit);
134
            } else {
134
            } else {
135
                formatter = BaseKit.getKit(BaseKit.class).createFormatter();
135
                formatter = callCreateFormatterMethod(BaseKit.getKit(BaseKit.class));
136
            }
136
            }
137
            mimePath2Formatter.put(mimePath, formatter);
137
            mimePath2Formatter.put(mimePath, formatter);
138
        }
138
        }
 Lines 264-270    Link Here 
264
     * @see BaseDocument.getTabSize()
264
     * @see BaseDocument.getTabSize()
265
     */
265
     */
266
    public int getTabSize() {
266
    public int getTabSize() {
267
        Document doc = getFormattingContextDocument();
267
        Document doc = LegacyFormattersProvider.getFormattingContextDocument();
268
        if (doc != null) {
268
        if (doc != null) {
269
            Object ret = callIndentUtils("tabSize", doc); //NOI18N
269
            Object ret = callIndentUtils("tabSize", doc); //NOI18N
270
            if (ret instanceof Integer) {
270
            if (ret instanceof Integer) {
 Lines 300-306    Link Here 
300
     * @see getSpacesPerTab()
300
     * @see getSpacesPerTab()
301
     */
301
     */
302
    public int getShiftWidth() {
302
    public int getShiftWidth() {
303
        Document doc = getFormattingContextDocument();
303
        Document doc = LegacyFormattersProvider.getFormattingContextDocument();
304
        if (doc != null) {
304
        if (doc != null) {
305
            Object ret = callIndentUtils("indentLevelSize", doc); //NOI18N
305
            Object ret = callIndentUtils("indentLevelSize", doc); //NOI18N
306
            if (ret instanceof Integer) {
306
            if (ret instanceof Integer) {
 Lines 329-335    Link Here 
329
329
330
    /** Should the typed tabs be expanded to the spaces? */
330
    /** Should the typed tabs be expanded to the spaces? */
331
    public boolean expandTabs() {
331
    public boolean expandTabs() {
332
        Document doc = getFormattingContextDocument();
332
        Document doc = LegacyFormattersProvider.getFormattingContextDocument();
333
        if (doc != null) {
333
        if (doc != null) {
334
            Object ret = callIndentUtils("isExpandTabs", doc); //NOI18N
334
            Object ret = callIndentUtils("isExpandTabs", doc); //NOI18N
335
            if (ret instanceof Boolean) {
335
            if (ret instanceof Boolean) {
 Lines 353-359    Link Here 
353
    * instead of one typed tab.
353
    * instead of one typed tab.
354
    */
354
    */
355
    public int getSpacesPerTab() {
355
    public int getSpacesPerTab() {
356
        Document doc = getFormattingContextDocument();
356
        Document doc = LegacyFormattersProvider.getFormattingContextDocument();
357
        if (doc != null) {
357
        if (doc != null) {
358
            Object ret = callIndentUtils("indentLevelSize", doc); //NOI18N
358
            Object ret = callIndentUtils("indentLevelSize", doc); //NOI18N
359
            if (ret instanceof Integer) {
359
            if (ret instanceof Integer) {
 Lines 378-388    Link Here 
378
    // ------------------------------------------------------------------------
378
    // ------------------------------------------------------------------------
379
379
380
    public String getIndentString(BaseDocument doc, int indent) {
380
    public String getIndentString(BaseDocument doc, int indent) {
381
        pushFormattingContextDocument(doc);
381
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
382
        try {
382
        try {
383
            return getIndentString(indent, expandTabs(), doc.getTabSize());
383
            return getIndentString(indent, expandTabs(), doc.getTabSize());
384
        } finally {
384
        } finally {
385
            popFormattingContextDocument(doc);
385
            LegacyFormattersProvider.popFormattingContextDocument(doc);
386
        }
386
        }
387
    }
387
    }
388
        
388
        
 Lines 403-409    Link Here 
403
     */
403
     */
404
    public void insertTabString (final BaseDocument doc, final int dotPos)
404
    public void insertTabString (final BaseDocument doc, final int dotPos)
405
    throws BadLocationException {
405
    throws BadLocationException {
406
        pushFormattingContextDocument(doc);
406
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
407
        try {
407
        try {
408
            final BadLocationException[] badLocationExceptions = new BadLocationException [1];
408
            final BadLocationException[] badLocationExceptions = new BadLocationException [1];
409
            doc.runAtomic (new Runnable () {
409
            doc.runAtomic (new Runnable () {
 Lines 436-442    Link Here 
436
            if (badLocationExceptions[0] != null)
436
            if (badLocationExceptions[0] != null)
437
                throw badLocationExceptions [0];
437
                throw badLocationExceptions [0];
438
        } finally {
438
        } finally {
439
            popFormattingContextDocument(doc);
439
            LegacyFormattersProvider.popFormattingContextDocument(doc);
440
        }
440
        }
441
    }
441
    }
442
442
 Lines 445-451    Link Here 
445
    */
445
    */
446
    public void changeRowIndent (final BaseDocument doc, final int pos, final int newIndent)
446
    public void changeRowIndent (final BaseDocument doc, final int pos, final int newIndent)
447
    throws BadLocationException {
447
    throws BadLocationException {
448
        pushFormattingContextDocument(doc);
448
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
449
        try {
449
        try {
450
            final BadLocationException[] badLocationExceptions = new BadLocationException [1];
450
            final BadLocationException[] badLocationExceptions = new BadLocationException [1];
451
            doc.runAtomic (new Runnable () {
451
            doc.runAtomic (new Runnable () {
 Lines 484-490    Link Here 
484
            if (badLocationExceptions[0] != null)
484
            if (badLocationExceptions[0] != null)
485
                throw badLocationExceptions [0];
485
                throw badLocationExceptions [0];
486
        } finally {
486
        } finally {
487
            popFormattingContextDocument(doc);
487
            LegacyFormattersProvider.popFormattingContextDocument(doc);
488
        }
488
        }
489
    }
489
    }
490
490
 Lines 498-504    Link Here 
498
    */
498
    */
499
    public void changeBlockIndent (final BaseDocument doc, final int startPos, final int endPos,
499
    public void changeBlockIndent (final BaseDocument doc, final int startPos, final int endPos,
500
                                  final int shiftCnt) throws BadLocationException {
500
                                  final int shiftCnt) throws BadLocationException {
501
        pushFormattingContextDocument(doc);
501
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
502
        try {
502
        try {
503
            GuardedDocument gdoc = (doc instanceof GuardedDocument)
503
            GuardedDocument gdoc = (doc instanceof GuardedDocument)
504
                                   ? (GuardedDocument)doc : null;
504
                                   ? (GuardedDocument)doc : null;
 Lines 538-551    Link Here 
538
            if (badLocationExceptions[0] != null)
538
            if (badLocationExceptions[0] != null)
539
                throw badLocationExceptions [0];
539
                throw badLocationExceptions [0];
540
        } finally {
540
        } finally {
541
            popFormattingContextDocument(doc);
541
            LegacyFormattersProvider.popFormattingContextDocument(doc);
542
        }
542
        }
543
    }
543
    }
544
544
545
    /** Shift line either left or right */
545
    /** Shift line either left or right */
546
    public void shiftLine(BaseDocument doc, int dotPos, boolean right)
546
    public void shiftLine(BaseDocument doc, int dotPos, boolean right)
547
    throws BadLocationException {
547
    throws BadLocationException {
548
        pushFormattingContextDocument(doc);
548
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
549
        try {
549
        try {
550
            int ind = doc.getShiftWidth();
550
            int ind = doc.getShiftWidth();
551
            if (!right) {
551
            if (!right) {
 Lines 560-566    Link Here 
560
            ind = Math.max(ind, 0);
560
            ind = Math.max(ind, 0);
561
            changeRowIndent(doc, dotPos, ind);
561
            changeRowIndent(doc, dotPos, ind);
562
        } finally {
562
        } finally {
563
            popFormattingContextDocument(doc);
563
            LegacyFormattersProvider.popFormattingContextDocument(doc);
564
        }
564
        }
565
    }
565
    }
566
566
 Lines 572-578    Link Here 
572
    */
572
    */
573
    public int reformat(BaseDocument doc, int startOffset, int endOffset)
573
    public int reformat(BaseDocument doc, int startOffset, int endOffset)
574
    throws BadLocationException {
574
    throws BadLocationException {
575
        pushFormattingContextDocument(doc);
575
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
576
        try {
576
        try {
577
            try {
577
            try {
578
                CharArrayWriter cw = new CharArrayWriter();
578
                CharArrayWriter cw = new CharArrayWriter();
 Lines 594-600    Link Here 
594
                return 0;
594
                return 0;
595
            }
595
            }
596
        } finally {
596
        } finally {
597
            popFormattingContextDocument(doc);
597
            LegacyFormattersProvider.popFormattingContextDocument(doc);
598
        }
598
        }
599
    }
599
    }
600
600
 Lines 772-804    Link Here 
772
    // private implementation
772
    // private implementation
773
    // ------------------------------------------------------------------------
773
    // ------------------------------------------------------------------------
774
774
775
    private static ThreadLocal<Stack<Reference<Document>>> FORMATTING_CONTEXT_DOCUMENT = new ThreadLocal<Stack<Reference<Document>>>() {
776
        @Override
777
        protected Stack<Reference<Document>> initialValue() {
778
            return new Stack<Reference<Document>>();
779
        }
780
    };
781
782
    private static Document getFormattingContextDocument() {
783
        Stack<Reference<Document>> stack = FORMATTING_CONTEXT_DOCUMENT.get();
784
        return stack.isEmpty() ? null : stack.peek().get();
785
    }
786
787
    /* package */ static void pushFormattingContextDocument(Document doc) {
788
        FORMATTING_CONTEXT_DOCUMENT.get().push(new WeakReference<Document>(doc));
789
    }
790
791
    /* package */ static void popFormattingContextDocument(Document doc) {
792
        Stack<Reference<Document>> stack = FORMATTING_CONTEXT_DOCUMENT.get();
793
        assert !stack.empty() : "Calling popFormattingContextDocument without pushFormattingContextDocument"; //NOI18N
794
795
        Reference<Document> ref = stack.pop();
796
        Document docFromStack = ref.get();
797
        assert docFromStack == doc : "Popping " + doc + ", but the stack contains " + docFromStack;
798
799
        ref.clear();
800
    }
801
802
    private static boolean noIndentUtils = false;
775
    private static boolean noIndentUtils = false;
803
    private static WeakReference<Class> indentUtilsClassRef = null;
776
    private static WeakReference<Class> indentUtilsClassRef = null;
804
    private static Object callIndentUtils(String methodName, Document doc) {
777
    private static Object callIndentUtils(String methodName, Document doc) {
 Lines 861-864    Link Here 
861
        }
834
        }
862
    }
835
    }
863
836
837
    private static Formatter callCreateFormatterMethod(BaseKit kit) {
838
        try {
839
            Method m = kit.getClass().getMethod("createFormatter"); //NOI18N
840
            return (Formatter) m.invoke(kit);
841
        } catch (Exception e) {
842
            return new Formatter(kit.getClass());
843
        }
844
    }
864
}
845
}
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/Bundle.properties (+38 lines)
Line 0    Link Here 
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
4
#
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License.  When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
22
#
23
# If you wish your version of this file to be governed by only the CDDL
24
# or only the GPL Version 2, indicate your decision by adding
25
# "[Contributor] elects to include this software in this distribution
26
# under the [CDDL or GPL Version 2] license." If you do not indicate a
27
# single choice of license, a recipient has the option to distribute
28
# your version of this file under either the CDDL, the GPL Version 2 or
29
# to extend the choice of license to its licensees as provided above.
30
# However, if you add GPL Version 2 code and therefore, elected the GPL
31
# Version 2 license, then the option applies only if the new code is
32
# made subject to such option by the copyright holder.
33
#
34
# Contributor(s):
35
#
36
# Portions Copyrighted 2008 Sun Microsystems, Inc.
37
38
MSG_NegativeValue=Negative value is not allowed
(-)a/editor/src/org/netbeans/modules/editor/FormatterIndentEngine.java (-2 / +13 lines)
 Lines 44-55    Link Here 
44
44
45
package org.netbeans.modules.editor;
45
package org.netbeans.modules.editor;
46
46
47
import java.awt.Toolkit;
47
import java.io.*;
48
import java.io.*;
48
import javax.swing.text.Document;
49
import javax.swing.text.Document;
49
import org.netbeans.api.editor.settings.SimpleValueNames;
50
import org.netbeans.api.editor.settings.SimpleValueNames;
50
import org.netbeans.editor.BaseKit;
51
import org.netbeans.editor.BaseKit;
51
import org.netbeans.editor.ext.ExtFormatter;
52
import org.netbeans.editor.ext.ExtFormatter;
53
import org.openide.ErrorManager;
52
import org.openide.text.IndentEngine;
54
import org.openide.text.IndentEngine;
55
import org.openide.util.Lookup;
56
import org.openide.util.NbBundle;
53
57
54
/**
58
/**
55
 * Indent engine that delegates to formatter
59
 * Indent engine that delegates to formatter
 Lines 168-175    Link Here 
168
172
169
    public void setSpacesPerTab(int spacesPerTab) {
173
    public void setSpacesPerTab(int spacesPerTab) {
170
        if (spacesPerTab <= 0) {
174
        if (spacesPerTab <= 0) {
171
            NbEditorUtilities.invalidArgument("MSG_NegativeValue"); // NOI18N
175
            IllegalArgumentException iae = new IllegalArgumentException("Invalid argument"); //NOI18N
172
            return; // value unchanged
176
            ErrorManager errMan = Lookup.getDefault().lookup(ErrorManager.class);
177
178
            if (errMan != null) {
179
                Toolkit.getDefaultToolkit().beep();
180
                errMan.annotate(iae, ErrorManager.USER, iae.getMessage(), NbBundle.getMessage(FormatterIndentEngine.class, "MSG_NegativeValue"), null, null); //NOI18N
181
            } else {
182
                throw iae;
183
            }
173
        }
184
        }
174
185
175
        int old = getFormatter().getSpacesPerTab();
186
        int old = getFormatter().getSpacesPerTab();
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/Bundle.properties (+2 lines)
Line 0    Link Here 
1
OpenIDE-Module-Display-Category=Editing
2
OpenIDE-Module-Name=Editor Formatting Prior 6.5 Separation
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/ComplexValueSettingsFactory.java (+85 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.editor.deprecated.pre65formatting;
44
45
import javax.swing.text.EditorKit;
46
import org.netbeans.api.editor.mimelookup.MimeLookup;
47
import org.netbeans.api.editor.mimelookup.MimePath;
48
import org.netbeans.modules.editor.FormatterIndentEngine;
49
import org.netbeans.modules.editor.IndentEngineFormatter;
50
import org.netbeans.modules.editor.NbEditorDocument;
51
import org.openide.text.IndentEngine;
52
53
/**
54
 *
55
 * @author vita
56
 */
57
public final class ComplexValueSettingsFactory {
58
59
    private ComplexValueSettingsFactory() {
60
        // no-op
61
    }
62
    
63
    // -----------------------------------------------------------------------
64
    // 'formatter' setting
65
    // -----------------------------------------------------------------------
66
67
    public static Object getFormatterValue(MimePath mimePath, String settingName) {
68
        assert settingName.equals(NbEditorDocument.FORMATTER) : "The getFormatter factory called for '" + settingName + "'"; //NOI18N
69
70
        IndentEngine eng = org.netbeans.modules.editor.impl.ComplexValueSettingsFactory.getIndentEngine(mimePath);
71
72
        if (eng != null) {
73
            if (eng instanceof FormatterIndentEngine) {
74
                return ((FormatterIndentEngine)eng).getFormatter();
75
            } else {
76
                EditorKit kit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
77
                if (kit != null) {
78
                    return new IndentEngineFormatter(kit.getClass(), eng);
79
                }
80
            }
81
        }
82
        
83
        return null;
84
    }
85
}
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/LegacyFormattersProvider.java (+379 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.deprecated.pre65formatting;
41
42
import java.io.IOException;
43
import java.lang.ref.Reference;
44
import java.lang.ref.WeakReference;
45
import java.lang.reflect.Method;
46
import java.util.Map;
47
import java.util.Stack;
48
import java.util.WeakHashMap;
49
import java.util.logging.Level;
50
import java.util.logging.Logger;
51
import javax.swing.text.BadLocationException;
52
import javax.swing.text.Document;
53
import javax.swing.text.EditorKit;
54
import javax.swing.text.Element;
55
import javax.swing.text.Position;
56
import javax.swing.text.StyledDocument;
57
import org.netbeans.api.editor.mimelookup.MimeLookup;
58
import org.netbeans.api.editor.mimelookup.MimePath;
59
import org.netbeans.editor.BaseDocument;
60
import org.netbeans.editor.Formatter;
61
import org.netbeans.editor.Utilities;
62
import org.netbeans.editor.ext.ExtFormatter;
63
import org.netbeans.modules.editor.indent.spi.Context;
64
import org.netbeans.modules.editor.indent.spi.ExtraLock;
65
import org.netbeans.modules.editor.indent.spi.IndentTask;
66
import org.netbeans.modules.editor.indent.spi.ReformatTask;
67
import org.netbeans.modules.editor.lib.KitsTracker;
68
import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
69
import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor;
70
import org.openide.util.Lookup;
71
import org.openide.util.lookup.Lookups;
72
73
/**
74
 *
75
 * @author vita
76
 */
77
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.editor.mimelookup.MimeDataProvider.class)
78
public final class LegacyFormattersProvider implements MimeDataProvider {
79
80
    public LegacyFormattersProvider() {
81
        // no-op
82
    }
83
84
    // ------------------------------------------------------------------------
85
    // MimeDataProvider implementation
86
    // ------------------------------------------------------------------------
87
88
    public Lookup getLookup(MimePath mimePath) {
89
        if (mimePath.size() == 1) {
90
            IndentReformatTaskFactoriesProvider provider = IndentReformatTaskFactoriesProvider.get(mimePath);
91
            if (provider != null) {
92
                IndentTask.Factory legacyIndenter = provider.getIndentTaskFactory();
93
                ReformatTask.Factory legacyFormatter = provider.getReformatTaskFactory();
94
                TypedTextInterceptor.Factory legacyAutoIndenter = provider.getTypedTextInterceptorFactory();
95
96
                if (LOG.isLoggable(Level.FINE)) {
97
                    LOG.fine("'" + mimePath.getPath() + "' uses legacyIndenter=" + legacyIndenter //NOI18N
98
                            + ", legacyFormatter=" + legacyFormatter //NOI18N
99
                            + ", legacyAutoIndenter=" + legacyAutoIndenter); //NOI18N
100
                }
101
102
                return Lookups.fixed(legacyIndenter, legacyFormatter, legacyAutoIndenter);
103
            }
104
        }
105
106
        return null;
107
    }
108
109
    // ------------------------------------------------------------------------
110
    // Formatting context manipulation methods
111
    // ------------------------------------------------------------------------
112
113
    public static Document getFormattingContextDocument() {
114
        Stack<Reference<Document>> stack = FORMATTING_CONTEXT_DOCUMENT.get();
115
        return stack.isEmpty() ? null : stack.peek().get();
116
    }
117
118
    public static void pushFormattingContextDocument(Document doc) {
119
        FORMATTING_CONTEXT_DOCUMENT.get().push(new WeakReference<Document>(doc));
120
    }
121
122
    public static void popFormattingContextDocument(Document doc) {
123
        Stack<Reference<Document>> stack = FORMATTING_CONTEXT_DOCUMENT.get();
124
        assert !stack.empty() : "Calling popFormattingContextDocument without pushFormattingContextDocument"; //NOI18N
125
126
        Reference<Document> ref = stack.pop();
127
        Document docFromStack = ref.get();
128
        assert docFromStack == doc : "Popping " + doc + ", but the stack contains " + docFromStack;
129
130
        ref.clear();
131
    }
132
133
    // ------------------------------------------------------------------------
134
    // Private implementation
135
    // ------------------------------------------------------------------------
136
137
    private static final Logger LOG = Logger.getLogger(LegacyFormattersProvider.class.getName());
138
    
139
    private static ThreadLocal<Stack<Reference<Document>>> FORMATTING_CONTEXT_DOCUMENT = new ThreadLocal<Stack<Reference<Document>>>() {
140
        @Override
141
        protected Stack<Reference<Document>> initialValue() {
142
            return new Stack<Reference<Document>>();
143
        }
144
    };
145
146
    private static final class IndentReformatTaskFactoriesProvider {
147
148
        public static IndentReformatTaskFactoriesProvider get(MimePath mimePath) {
149
            Reference<IndentReformatTaskFactoriesProvider> ref = cache.get(mimePath);
150
            IndentReformatTaskFactoriesProvider provider = ref == null ? null : ref.get();
151
            if (provider == null) {
152
                try {
153
                    Class kitClass = KitsTracker.getInstance().findKitClass(mimePath.getPath());
154
                    Method createFormatterMethod = kitClass.getDeclaredMethod("createFormatter"); //NOI18N
155
                    provider = new IndentReformatTaskFactoriesProvider(mimePath);
156
                    cache.put(mimePath, new WeakReference<IndentReformatTaskFactoriesProvider>(provider));
157
                } catch (Exception e) {
158
                    // ignore
159
                }
160
            }
161
            return provider;
162
        }
163
164
        public IndentTask.Factory getIndentTaskFactory() {
165
            if (indentTaskFactory == null) {
166
                indentTaskFactory = new IndentTask.Factory() {
167
                    public IndentTask createTask(Context context) {
168
                        Formatter formatter = getFormatter();
169
                        if (formatter != null && context.document() instanceof BaseDocument) {
170
                            return new Indenter(context, formatter);
171
                        } else {
172
                            return null;
173
                        }
174
                    }
175
                };
176
            }
177
            return indentTaskFactory;
178
        }
179
180
        public ReformatTask.Factory getReformatTaskFactory() {
181
            if (reformatTaskFactory == null) {
182
                reformatTaskFactory = new ReformatTask.Factory() {
183
                    public ReformatTask createTask(Context context) {
184
                        Formatter formatter = getFormatter();
185
                        if (formatter != null && context.document() instanceof BaseDocument) {
186
                            return new Reformatter(context, formatter);
187
                        } else {
188
                            return null;
189
                        }
190
                    }
191
                };
192
            }
193
            return reformatTaskFactory;
194
        }
195
196
        public TypedTextInterceptor.Factory getTypedTextInterceptorFactory() {
197
            if (typedTextInterceptorFactory == null) {
198
                typedTextInterceptorFactory = new TypedTextInterceptor.Factory() {
199
                    public TypedTextInterceptor createTypedTextInterceptor(MimePath mimePath) {
200
                        Formatter formatter = getFormatter();
201
                        if (formatter instanceof ExtFormatter) {
202
                            return new AutoIndenter((ExtFormatter)formatter);
203
                        } else {
204
                            return null;
205
                        }
206
                    }
207
                };
208
            }
209
            return typedTextInterceptorFactory;
210
        }
211
212
        // -------------------------------------------------------------------
213
        // private implementation
214
        // -------------------------------------------------------------------
215
216
        private static final Map<MimePath, Reference<IndentReformatTaskFactoriesProvider>> cache = new WeakHashMap<MimePath, Reference<IndentReformatTaskFactoriesProvider>>();
217
        private static final String NO_FORMATTER = new String("NO_FORMATTER"); //NOI18N
218
219
        private final MimePath mimePath;
220
221
        private IndentTask.Factory indentTaskFactory;
222
        private ReformatTask.Factory reformatTaskFactory;
223
        private TypedTextInterceptor.Factory typedTextInterceptorFactory;
224
        private Object legacyFormatter;
225
226
        private IndentReformatTaskFactoriesProvider(MimePath mimePath) {
227
            this.mimePath = mimePath;
228
        }
229
230
        private Formatter getFormatter() {
231
            if (legacyFormatter == null) {
232
                EditorKit kit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
233
                if (kit != null) {
234
                    try {
235
                        Method createFormatterMethod = kit.getClass().getDeclaredMethod("createFormatter"); //NOI18N
236
                        legacyFormatter = createFormatterMethod.invoke(kit);
237
                    } catch (Exception e) {
238
                        legacyFormatter = e;
239
                    }
240
                } else {
241
                    legacyFormatter = NO_FORMATTER;
242
                }
243
            }
244
            return legacyFormatter instanceof Formatter ? (Formatter) legacyFormatter : null;
245
        }
246
247
    } // End of IndentReformatTaskFactoriesProvider class
248
249
    private static final class Indenter implements IndentTask {
250
251
        private final Context context;
252
        private final Formatter formatter;
253
254
        public Indenter(Context context, Formatter formatter) {
255
            this.context = context;
256
            this.formatter = formatter;
257
        }
258
259
        public void reindent() throws BadLocationException {
260
            Document doc = context.document();
261
            int startOffset = context.startOffset();
262
            int endOffset = context.endOffset();
263
            
264
            pushFormattingContextDocument(doc);
265
            try {
266
                // Original formatter does not have reindentation of multiple lines
267
                // so reformat start line and continue for each line.
268
                Element lineRootElem = lineRootElement(doc);
269
                Position endPos = doc.createPosition(endOffset);
270
                do {
271
                    startOffset = formatter.indentLine(doc, startOffset);
272
                    int startLineIndex = lineRootElem.getElementIndex(startOffset) + 1;
273
                    if (startLineIndex >= lineRootElem.getElementCount())
274
                        break;
275
                    Element lineElem = lineRootElem.getElement(startLineIndex);
276
                    startOffset = lineElem.getStartOffset(); // Move to next line
277
                } while (startOffset < endPos.getOffset());
278
            } finally {
279
                popFormattingContextDocument(doc);
280
            }
281
        }
282
283
        public ExtraLock indentLock() {
284
            return new ExtraLock() {
285
                public void lock() {
286
                    formatter.indentLock();
287
                }
288
289
                public void unlock() {
290
                    formatter.indentUnlock();
291
                }
292
            };
293
        }
294
295
        private static Element lineRootElement(Document doc) {
296
            return (doc instanceof StyledDocument)
297
                ? ((StyledDocument)doc).getParagraphElement(0).getParentElement()
298
                : doc.getDefaultRootElement();
299
        }
300
    } // End of Indenter class
301
302
    private static final class Reformatter implements ReformatTask {
303
304
        private final Context context;
305
        private final Formatter formatter;
306
307
        public Reformatter(Context context, Formatter formatter) {
308
            this.context = context;
309
            this.formatter = formatter;
310
        }
311
312
        public void reformat() throws BadLocationException {
313
            pushFormattingContextDocument(context.document());
314
            try {
315
                formatter.reformat((BaseDocument) context.document(), context.startOffset(), context.endOffset());
316
            } finally {
317
                popFormattingContextDocument(context.document());
318
            }
319
        }
320
321
        public ExtraLock reformatLock() {
322
            return new ExtraLock() {
323
                public void lock() {
324
                    formatter.reformatLock();
325
                }
326
327
                public void unlock() {
328
                    formatter.reformatUnlock();
329
                }
330
            };
331
        }
332
    } // End of Reformatter class
333
334
    private static final class AutoIndenter implements TypedTextInterceptor {
335
336
        private final ExtFormatter formatter;
337
338
        public AutoIndenter(ExtFormatter formatter) {
339
            this.formatter = formatter;
340
        }
341
342
        public boolean beforeInsert(Context context) throws BadLocationException {
343
            // no-op
344
            return false;
345
        }
346
347
        public void insert(MutableContext context) throws BadLocationException {
348
            // no-op
349
        }
350
351
        public void afterInsert(Context context) throws BadLocationException {
352
            if (context.getDocument() instanceof BaseDocument) {
353
                BaseDocument doc = (BaseDocument) context.getDocument();
354
                int [] fmtBlk = formatter.getReformatBlock(context.getComponent(), context.getText());
355
                if (fmtBlk != null) {
356
                    try {
357
358
                        fmtBlk[0] = Utilities.getRowStart(doc, fmtBlk[0]);
359
                        fmtBlk[1] = Utilities.getRowEnd(doc, fmtBlk[1]);
360
361
                        //this was the of #18922, that causes the bug #20198
362
                        //ef.reformat(doc, fmtBlk[0], fmtBlk[1]);
363
364
                        //bugfix of the bug #20198. Bug #18922 is fixed too as well as #6968
365
                        formatter.reformat(doc, fmtBlk[0], fmtBlk[1], true);
366
367
                    } catch (BadLocationException e) {
368
                    } catch (IOException e) {
369
                    }
370
                }
371
            }
372
        }
373
374
        public void cancelled(Context context) {
375
            // no-op
376
        }
377
378
    } // End of AutoIndenter class
379
}
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/layer.xml (+55 lines)
Line 0    Link Here 
1
<?xml version="1.0"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
9
10
11
The contents of this file are subject to the terms of either the GNU
12
General Public License Version 2 only ("GPL") or the Common
13
Development and Distribution License("CDDL") (collectively, the
14
"License"). You may not use this file except in compliance with the
15
License. You can obtain a copy of the License at
16
http://www.netbeans.org/cddl-gplv2.html
17
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18
specific language governing permissions and limitations under the
19
License.  When distributing the software, include this License Header
20
Notice in each file and include the License file at
21
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
22
particular file as subject to the "Classpath" exception as provided
23
by Oracle in the GPL Version 2 section of the License file that
24
accompanied this code. If applicable, add the following below the
25
License Header, with the fields enclosed by brackets [] replaced by
26
your own identifying information:
27
"Portions Copyrighted [year] [name of copyright owner]"
28
29
Contributor(s):
30
31
The Original Software is NetBeans. The Initial Developer of the Original
32
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
33
Microsystems, Inc. All Rights Reserved.
34
35
If you wish your version of this file to be governed by only the CDDL
36
or only the GPL Version 2, indicate your decision by adding
37
"[Contributor] elects to include this software in this distribution
38
under the [CDDL or GPL Version 2] license." If you do not indicate a
39
single choice of license, a recipient has the option to distribute
40
your version of this file under either the CDDL, the GPL Version 2 or
41
to extend the choice of license to its licensees as provided above.
42
However, if you add GPL Version 2 code and therefore, elected the GPL
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
45
-->
46
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.0//EN" "http://www.netbeans.org/dtds/filesystem-1_0.dtd">
47
<filesystem>
48
    <folder name="Editors">
49
        <folder name="Preferences">
50
            <folder name="Defaults">
51
                <file name="org-netbeans-modules-editor-deprecated-pre65formatting-preferences.xml" url="preferences.xml"/>
52
            </folder>
53
        </folder>
54
    </folder>
55
</filesystem>
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/preferences.xml (+52 lines)
Line 0    Link Here 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
9
10
11
The contents of this file are subject to the terms of either the GNU
12
General Public License Version 2 only ("GPL") or the Common
13
Development and Distribution License("CDDL") (collectively, the
14
"License"). You may not use this file except in compliance with the
15
License. You can obtain a copy of the License at
16
http://www.netbeans.org/cddl-gplv2.html
17
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18
specific language governing permissions and limitations under the
19
License.  When distributing the software, include this License Header
20
Notice in each file and include the License file at
21
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
22
particular file as subject to the "Classpath" exception as provided
23
by Oracle in the GPL Version 2 section of the License file that
24
accompanied this code. If applicable, add the following below the
25
License Header, with the fields enclosed by brackets [] replaced by
26
your own identifying information:
27
"Portions Copyrighted [year] [name of copyright owner]"
28
29
Contributor(s):
30
31
The Original Software is NetBeans. The Initial Developer of the Original
32
Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
33
Microsystems, Inc. All Rights Reserved.
34
35
If you wish your version of this file to be governed by only the CDDL
36
or only the GPL Version 2, indicate your decision by adding
37
"[Contributor] elects to include this software in this distribution
38
under the [CDDL or GPL Version 2] license." If you do not indicate a
39
single choice of license, a recipient has the option to distribute
40
your version of this file under either the CDDL, the GPL Version 2 or
41
to extend the choice of license to its licensees as provided above.
42
However, if you add GPL Version 2 code and therefore, elected the GPL
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
45
-->
46
<!DOCTYPE editor-preferences PUBLIC "-//NetBeans//DTD Editor Preferences 1.0//EN" "http://www.netbeans.org/dtds/EditorPreferences-1_0.dtd">
47
48
<editor-preferences>
49
    <entry category="deprecated" javaType="methodvalue" name="formatter" xml:space="preserve">
50
        <value><![CDATA[org.netbeans.modules.editor.deprecated.pre65formatting.ComplexValueSettingsFactory.getFormatterValue]]></value>
51
    </entry>
52
</editor-preferences>
(-)a/editor.errorstripe/nbproject/project.xml (-2 / +2 lines)
 Lines 71-78    Link Here 
71
                    <build-prerequisite/>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
72
                    <compile-dependency/>
73
                    <run-dependency>
73
                    <run-dependency>
74
                        <release-version>2</release-version>
74
                        <release-version>3</release-version>
75
                        <specification-version>2.1</specification-version>
75
                        <specification-version>3.1</specification-version>
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
(-)a/editor.highlights/nbproject/project.xml (-2 / +11 lines)
 Lines 54-61    Link Here 
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>1.27</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
 Lines 115-120    Link Here 
115
                        <specification-version>1.0</specification-version>
115
                        <specification-version>1.0</specification-version>
116
                    </run-dependency>
116
                    </run-dependency>
117
                </dependency>
117
                </dependency>
118
            <dependency>
119
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
120
                    <build-prerequisite/>
121
                    <compile-dependency/>
122
                    <run-dependency>
123
                        <release-version>0-1</release-version>
124
                        <specification-version>1.0</specification-version>
125
                    </run-dependency>
126
                </dependency>
118
            </module-dependencies>
127
            </module-dependencies>
119
            <test-dependencies>
128
            <test-dependencies>
120
                <test-type>
129
                <test-type>
(-)a/editor.indent/apichanges.xml (+30 lines)
 Lines 108-113    Link Here 
108
108
109
    <changes>
109
    <changes>
110
110
111
        <change id="AutomatedIndentation.added">
112
            <summary>Adding org.netbeans.modules.editor.indent.spi.support.AutomatedIndenting</summary>
113
            <version major="1" minor="20"/>
114
            <date day="23" month="10" year="2008"/>
115
            <author login="vstejskal"/>
116
            <compatibility source="compatible" binary="compatible" deletion="no" addition="yes" modification="no"/>
117
            <description>
118
                The <code>AutomatedIndenting</code> support class provides regex-based
119
                automatic re-indentation of lines as user types. This is a replacement for
120
                the deprecated <code>ExtFormatter.getReformatBlock</code> and <code>INDENT_HOT_CHARS_ACCEPTOR</code>
121
                setting.
122
            </description>
123
            <class package="org.netbeans.modules.editor.indent.spi.support" name="AutomatedIndenting"/>
124
            <issue number="120357"/>
125
        </change>
126
127
        <change id="Indent.indentNewLine.added">
128
            <summary>Adding org.netbeans.modules.editor.indent.api.Indent.indentNewLine</summary>
129
            <version major="1" minor="19"/>
130
            <date day="15" month="10" year="2008"/>
131
            <author login="vstejskal"/>
132
            <compatibility source="compatible" binary="compatible" deletion="no" addition="yes" modification="no"/>
133
            <description>
134
                The new method <code>int Indent.indentNewLine(int)</code> was added as
135
                a replacement for the old <code>int Formatter.indentNewLine(BaseDocument, int)</code>.
136
            </description>
137
            <class package="org.netbeans.modules.editor.indent.api" name="Indent"/>
138
            <issue number="120357"/>
139
        </change>
140
111
        <change id="CodeStylePreferences.Provider">
141
        <change id="CodeStylePreferences.Provider">
112
            <summary>Adding CodeStylePreferences.Provider</summary>
142
            <summary>Adding CodeStylePreferences.Provider</summary>
113
            <version major="1" minor="18"/>
143
            <version major="1" minor="18"/>
(-)a/editor.indent/manifest.mf (+1 lines)
 Lines 4-6    Link Here 
4
OpenIDE-Module-Layer: org/netbeans/modules/editor/indent/resources/layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/editor/indent/resources/layer.xml
5
AutoUpdate-Show-In-Client: false
5
AutoUpdate-Show-In-Client: false
6
OpenIDE-Module-Recommends: org.netbeans.modules.editor.indent.spi.CodeStylePreferences.Provider
6
OpenIDE-Module-Recommends: org.netbeans.modules.editor.indent.spi.CodeStylePreferences.Provider
7
OpenIDE-Module-Specification-Version: 1.20.0
(-)a/editor.indent/nbproject/project.properties (-1 lines)
 Lines 42-48    Link Here 
42
42
43
javac.source=1.6
43
javac.source=1.6
44
javac.compilerargs=-Xlint:unchecked
44
javac.compilerargs=-Xlint:unchecked
45
spec.version.base=1.20.0
46
45
47
javadoc.arch=${basedir}/arch.xml
46
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
47
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/editor.indent/nbproject/project.xml (-3 / +4 lines)
 Lines 50-61    Link Here 
50
            <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
50
            <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
53
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>1</release-version>
58
                        <implementation-version/>
58
                        <specification-version>1.31</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
 Lines 176-181    Link Here 
176
            <public-packages>
176
            <public-packages>
177
                <package>org.netbeans.modules.editor.indent.api</package>
177
                <package>org.netbeans.modules.editor.indent.api</package>
178
                <package>org.netbeans.modules.editor.indent.spi</package>
178
                <package>org.netbeans.modules.editor.indent.spi</package>
179
                <package>org.netbeans.modules.editor.indent.spi.support</package>
179
            </public-packages>
180
            </public-packages>
180
        </data>
181
        </data>
181
    </configuration>
182
    </configuration>
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/FormatterImpl.java (-218 lines)
 Lines 1-218    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.modules.editor.indent;
46
47
import java.io.IOException;
48
import java.io.Writer;
49
import java.lang.reflect.Method;
50
import javax.swing.text.BadLocationException;
51
import javax.swing.text.Document;
52
import javax.swing.text.JTextComponent;
53
import org.netbeans.editor.BaseDocument;
54
import org.netbeans.editor.Formatter;
55
import org.netbeans.editor.GuardedException;
56
import org.netbeans.editor.ext.ExtFormatter;
57
import org.netbeans.modules.editor.indent.api.IndentUtils;
58
59
/**
60
 * Indentation and code reformatting services for a swing text document.
61
 *
62
 * @author Miloslav Metelka
63
 */
64
public final class FormatterImpl extends ExtFormatter {
65
    
66
    private final Document doc;
67
    private final Formatter defaultFormatter;
68
    private final IndentImpl indentImpl;
69
    
70
    private final boolean tabSizeOverriden;
71
    private final boolean shiftWidthOverriden;
72
    private final boolean expandTabsOverriden;
73
    
74
    FormatterImpl(Formatter defaultFormatter, Document doc) {
75
        super(defaultFormatter.getKitClass());
76
        
77
        this.defaultFormatter = defaultFormatter;
78
        this.tabSizeOverriden = isOverriden(defaultFormatter.getClass(), "getTabSize"); //NOI18N
79
        this.shiftWidthOverriden = isOverriden(defaultFormatter.getClass(), "getShiftWidth"); //NOI18N
80
        this.expandTabsOverriden = isOverriden(defaultFormatter.getClass(), "expandTabs"); //NOI18N
81
82
        this.doc = doc;
83
        assert doc != null;
84
        
85
        this.indentImpl = IndentImpl.get(doc);
86
        indentImpl.setDefaultFormatter(defaultFormatter);
87
    }
88
    
89
    @Override
90
    public int[] getReformatBlock(JTextComponent target, String typedText) {
91
        return (defaultFormatter instanceof ExtFormatter)
92
                ? ((ExtFormatter)defaultFormatter).getReformatBlock(target, typedText)
93
                : null;
94
    }
95
    
96
    @Override
97
    public void indentLock() {
98
        indentImpl.indentLock();
99
    }
100
    
101
    @Override
102
    public void indentUnlock() {
103
        indentImpl.indentUnlock();
104
    }
105
    
106
    @Override
107
    public void reformatLock() {
108
        indentImpl.reformatLock();
109
    }
110
    
111
    @Override
112
    public void reformatUnlock() {
113
        indentImpl.reformatUnlock();
114
    }
115
116
    @Override
117
    public int getTabSize() {
118
        if (tabSizeOverriden) {
119
            return defaultFormatter.getTabSize();
120
        } else {
121
            return IndentUtils.tabSize(doc);
122
        }
123
    }
124
125
    @Override
126
    public int getSpacesPerTab() {
127
        return defaultFormatter.getSpacesPerTab();
128
    }
129
130
    @Override
131
    public int getShiftWidth() {
132
        if (shiftWidthOverriden) {
133
            return defaultFormatter.getShiftWidth();
134
        } else {
135
            return IndentUtils.indentLevelSize(doc);
136
        }
137
    }
138
139
    @Override
140
    public boolean expandTabs() {
141
        if (expandTabsOverriden) {
142
            return defaultFormatter.expandTabs();
143
        } else {
144
            return IndentUtils.isExpandTabs(doc);
145
        }
146
    }
147
148
    @Override
149
    public int indentLine(Document doc, int offset) {
150
        return indentLine(doc, offset, false);
151
    }
152
153
    /** Inserts new line at given position and indents the new line with
154
    * spaces.
155
    *
156
    * @param doc the document to work on
157
    * @param offset the offset of a character on the line
158
    * @return new offset to place cursor to
159
    */
160
    @Override
161
    public int indentNewLine(Document doc, int offset) {
162
        return indentLine(doc, offset, true);
163
    }
164
165
    private int indentLine(Document doc, int offset, boolean indentNewLine) {
166
        try {
167
            return indentImpl.reindent(offset, offset, offset, indentNewLine);
168
        } catch (GuardedException e) {
169
            java.awt.Toolkit.getDefaultToolkit().beep();
170
        } catch (BadLocationException e) {
171
            throw new IllegalStateException(e);
172
        }
173
        return offset;
174
    }
175
176
    @Override
177
    public Writer reformat(BaseDocument doc, int startOffset, int endOffset,
178
    boolean indentOnly) throws BadLocationException, IOException {
179
        // TBD delegate somehow
180
        return (defaultFormatter instanceof ExtFormatter)
181
                ? ((ExtFormatter)defaultFormatter).reformat(doc, startOffset, endOffset, indentOnly)
182
                : null;
183
    }
184
    
185
    @Override
186
    public int reformat(BaseDocument doc, int startOffset, int endOffset)
187
    throws BadLocationException {
188
        if (doc != indentImpl.document())
189
            return endOffset - startOffset; // should not happen in reality
190
        indentImpl.reformat(startOffset, endOffset);
191
        TaskHandler handler = indentImpl.reformatHandler();
192
        return (handler != null && handler.hasItems())
193
                ? Math.max(handler.endPos().getOffset() - startOffset, 0)
194
                : endOffset - startOffset;
195
    }
196
197
    @Override
198
    public Writer createWriter(Document doc, int offset, Writer writer) {
199
        if (doc != indentImpl.document()) {
200
            throw new IllegalStateException("Unexpected document doc=" + doc); //NOI18N
201
        }
202
        return new FormatterWriterImpl(indentImpl, offset, writer);
203
    }
204
205
    private static boolean isOverriden(Class clazz, String methodName) {
206
        while (clazz != Formatter.class && clazz != ExtFormatter.class) {
207
            for(Method m : clazz.getDeclaredMethods()) {
208
                if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) {
209
                    return true;
210
                }
211
            }
212
213
            clazz = clazz.getSuperclass();
214
        }
215
216
        return false;
217
    }
218
}
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/FormatterOverrideImpl.java (-64 lines)
 Lines 1-64    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.modules.editor.indent;
46
47
import javax.swing.text.Document;
48
import org.netbeans.editor.Formatter;
49
import org.netbeans.modules.editor.lib.FormatterOverride;
50
51
/**
52
 * Indentation and code reformatting services for a swing text document.
53
 *
54
 * @author Miloslav Metelka
55
 */
56
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.modules.editor.lib.FormatterOverride.class)
57
public final class FormatterOverrideImpl implements FormatterOverride {
58
59
    public Formatter getFormatter(Document doc, Formatter defaultFormatter) {
60
        // Always override and possibly delegate to default formatter
61
        return new FormatterImpl(defaultFormatter, doc);
62
    }
63
64
}
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/IndentImpl.java (-58 / +65 lines)
 Lines 49-60    Link Here 
49
import javax.swing.text.BadLocationException;
49
import javax.swing.text.BadLocationException;
50
import javax.swing.text.Document;
50
import javax.swing.text.Document;
51
import javax.swing.text.Element;
51
import javax.swing.text.Element;
52
import javax.swing.text.Position;
53
import javax.swing.text.StyledDocument;
52
import javax.swing.text.StyledDocument;
54
import org.netbeans.modules.editor.indent.api.Indent;
53
import org.netbeans.modules.editor.indent.api.Indent;
55
import org.netbeans.modules.editor.indent.api.Reformat;
54
import org.netbeans.modules.editor.indent.api.Reformat;
56
import org.netbeans.editor.BaseDocument;
57
import org.netbeans.editor.Formatter;
58
55
59
/**
56
/**
60
 * Indentation and code reformatting services for a swing text document.
57
 * Indentation and code reformatting services for a swing text document.
 Lines 72-78    Link Here 
72
            indentImpl = new IndentImpl(doc);
69
            indentImpl = new IndentImpl(doc);
73
            doc.putProperty(IndentImpl.class, indentImpl);
70
            doc.putProperty(IndentImpl.class, indentImpl);
74
        }
71
        }
75
        indentImpl.refresh();
72
// XXX: formatting infra cleanup
73
//        indentImpl.refresh();
76
        return indentImpl;
74
        return indentImpl;
77
    }
75
    }
78
    
76
    
 Lines 85-93    Link Here 
85
    private TaskHandler indentHandler;
83
    private TaskHandler indentHandler;
86
    
84
    
87
    private TaskHandler reformatHandler;
85
    private TaskHandler reformatHandler;
86
87
// XXX: formatting infra cleanup
88
//    private Formatter defaultFormatter;
88
    
89
    
89
    private Formatter defaultFormatter;
90
91
    private Thread lockThread;
90
    private Thread lockThread;
92
91
93
    private int lockExtraDepth;
92
    private int lockExtraDepth;
 Lines 116-132    Link Here 
116
        this.reformat = reformat;
115
        this.reformat = reformat;
117
    }
116
    }
118
    
117
    
119
    void setDefaultFormatter(Formatter defaultFormatter) {
118
// XXX: formatting infra cleanup
120
        this.defaultFormatter = defaultFormatter;
119
//    void setDefaultFormatter(Formatter defaultFormatter) {
121
    }
120
//        this.defaultFormatter = defaultFormatter;
122
    
121
//    }
123
    void refresh() {
122
//
124
        if (defaultFormatter == null) {
123
//    void refresh() {
125
            if (doc instanceof BaseDocument) {
124
//        if (defaultFormatter == null) {
126
                defaultFormatter = ((BaseDocument)doc).getLegacyFormatter();
125
//            if (doc instanceof BaseDocument) {
127
            }
126
//                defaultFormatter = ((BaseDocument)doc).getLegacyFormatter();
128
        }
127
//            }
129
    }
128
//        }
129
//    }
130
    
130
    
131
    public synchronized void indentLock() {
131
    public synchronized void indentLock() {
132
        if (LOG.isLoggable(Level.FINE)) {
132
        if (LOG.isLoggable(Level.FINE)) {
 Lines 221-227    Link Here 
221
            // Find begining of line
221
            // Find begining of line
222
            Element lineRootElem = lineRootElement(doc);
222
            Element lineRootElem = lineRootElement(doc);
223
            // Correct the start offset to point to the begining of the start line
223
            // Correct the start offset to point to the begining of the start line
224
            boolean done = false;
224
// XXX: formatting infra cleanup
225
//            boolean done = false;
225
            if (indentHandler.hasItems()) {
226
            if (indentHandler.hasItems()) {
226
                // When indenting newline first insert a plain newline
227
                // When indenting newline first insert a plain newline
227
                if (indentNewLine) {
228
                if (indentNewLine) {
 Lines 257-293    Link Here 
257
258
258
                // Perform whole reindent on top and possibly embedded levels
259
                // Perform whole reindent on top and possibly embedded levels
259
                indentHandler.runTasks();
260
                indentHandler.runTasks();
260
                done = true;
261
// XXX: formatting infra cleanup
262
//                done = true;
261
            }
263
            }
262
264
263
            // Fallback to Formatter
265
// XXX: formatting infra cleanup
264
            if (!done && doc instanceof BaseDocument && defaultFormatter != null) {
266
//            // Fallback to Formatter
265
                if (indentNewLine) {
267
//            if (!done && doc instanceof BaseDocument && defaultFormatter != null) {
266
                    if (LOG.isLoggable(Level.FINE)) {
268
//                if (indentNewLine) {
267
                        LOG.fine("Defaulting reindent() to indentNewLine() in legacy formatter " + // NOI18N
269
//                    if (LOG.isLoggable(Level.FINE)) {
268
                                defaultFormatter + '\n');
270
//                        LOG.fine("Defaulting reindent() to indentNewLine() in legacy formatter " + // NOI18N
269
                    }
271
//                                defaultFormatter + '\n');
270
                    // Fallback to indentNewLine() will insert '\n'
272
//                    }
271
                    int newCaretOffset = defaultFormatter.indentNewLine(doc, caretOffset);
273
//                    // Fallback to indentNewLine() will insert '\n'
272
                    indentHandler.setCaretOffset(newCaretOffset);
274
//                    int newCaretOffset = defaultFormatter.indentNewLine(doc, caretOffset);
273
                } else { // Indent line
275
//                    indentHandler.setCaretOffset(newCaretOffset);
274
                    // Original formatter does not have reindentation of multiple lines
276
//                } else { // Indent line
275
                    // so reformat start line and continue for each line.
277
//                    // Original formatter does not have reindentation of multiple lines
276
                    Position endPos = doc.createPosition(endOffset);
278
//                    // so reformat start line and continue for each line.
277
                    if (LOG.isLoggable(Level.FINE)) {
279
//                    Position endPos = doc.createPosition(endOffset);
278
                        LOG.fine("Defaulting reindent() to indentLine() in legacy formatter " + // NOI18N
280
//                    if (LOG.isLoggable(Level.FINE)) {
279
                                defaultFormatter + '\n');
281
//                        LOG.fine("Defaulting reindent() to indentLine() in legacy formatter " + // NOI18N
280
                    }
282
//                                defaultFormatter + '\n');
281
                    do {
283
//                    }
282
                        startOffset = defaultFormatter.indentLine(doc, startOffset);
284
//                    do {
283
                        int startLineIndex = lineRootElem.getElementIndex(startOffset) + 1;
285
//                        startOffset = defaultFormatter.indentLine(doc, startOffset);
284
                        if (startLineIndex >= lineRootElem.getElementCount())
286
//                        int startLineIndex = lineRootElem.getElementIndex(startOffset) + 1;
285
                            break;
287
//                        if (startLineIndex >= lineRootElem.getElementCount())
286
                        Element lineElem = lineRootElem.getElement(startLineIndex);
288
//                            break;
287
                        startOffset = lineElem.getStartOffset(); // Move to next line
289
//                        Element lineElem = lineRootElem.getElement(startLineIndex);
288
                    } while (startOffset < endPos.getOffset());
290
//                        startOffset = lineElem.getStartOffset(); // Move to next line
289
                }
291
//                    } while (startOffset < endPos.getOffset());
290
            }
292
//                }
293
//            }
294
291
            return indentHandler.caretOffset();
295
            return indentHandler.caretOffset();
292
        } finally {
296
        } finally {
293
            if (runUnlocked)
297
            if (runUnlocked)
 Lines 310-316    Link Here 
310
            if (runUnlocked) {
314
            if (runUnlocked) {
311
                reformatHandler.collectTasks();
315
                reformatHandler.collectTasks();
312
            }
316
            }
313
            boolean done = false;
317
// XXX: formatting infra cleanup
318
//            boolean done = false;
314
            if (reformatHandler.hasItems()) {
319
            if (reformatHandler.hasItems()) {
315
                reformatHandler.setGlobalBounds(
320
                reformatHandler.setGlobalBounds(
316
                        doc.createPosition(startOffset),
321
                        doc.createPosition(startOffset),
 Lines 320-337    Link Here 
320
                reformatHandler.runTasks();
325
                reformatHandler.runTasks();
321
326
322
                // Perform reformatting of the top section and possible embedded sections
327
                // Perform reformatting of the top section and possible embedded sections
323
                done = true;
328
// XXX: formatting infra cleanup
329
//                done = true;
324
            }
330
            }
325
331
326
            // Fallback to Formatter
332
// XXX: formatting infra cleanup
327
            if (!done && doc instanceof BaseDocument && defaultFormatter != null) {
333
//            // Fallback to Formatter
328
                if (LOG.isLoggable(Level.FINE)) {
334
//            if (!done && doc instanceof BaseDocument && defaultFormatter != null) {
329
                    LOG.fine("Defaulting reformat() to reformat() in legacy formatter " + // NOI18N
335
//                if (LOG.isLoggable(Level.FINE)) {
330
                            defaultFormatter + '\n');
336
//                    LOG.fine("Defaulting reformat() to reformat() in legacy formatter " + // NOI18N
331
                }
337
//                            defaultFormatter + '\n');
332
                BaseDocument bdoc = (BaseDocument)doc;
338
//                }
333
                defaultFormatter.reformat(bdoc, startOffset, endOffset);
339
//                BaseDocument bdoc = (BaseDocument)doc;
334
            }
340
//                defaultFormatter.reformat(bdoc, startOffset, endOffset);
341
//            }
335
        } finally {
342
        } finally {
336
            if (runUnlocked)
343
            if (runUnlocked)
337
                reformatHandler = null;
344
                reformatHandler = null;
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/TaskHandler.java (-6 / +5 lines)
 Lines 62-68    Link Here 
62
import org.netbeans.api.lexer.LanguagePath;
62
import org.netbeans.api.lexer.LanguagePath;
63
import org.netbeans.api.lexer.TokenHierarchy;
63
import org.netbeans.api.lexer.TokenHierarchy;
64
import org.netbeans.api.lexer.TokenSequence;
64
import org.netbeans.api.lexer.TokenSequence;
65
import org.netbeans.editor.GuardedDocument;
66
import org.netbeans.lib.editor.util.swing.MutablePositionRegion;
65
import org.netbeans.lib.editor.util.swing.MutablePositionRegion;
67
import org.netbeans.modules.editor.indent.spi.Context;
66
import org.netbeans.modules.editor.indent.spi.Context;
68
import org.netbeans.modules.editor.indent.spi.ExtraLock;
67
import org.netbeans.modules.editor.indent.spi.ExtraLock;
 Lines 464-473    Link Here 
464
                }
463
                }
465
                
464
                
466
                // Filter out guarded regions
465
                // Filter out guarded regions
467
                if (indentRegions.size() > 0 && doc instanceof GuardedDocument) {
466
//                if (indentRegions.size() > 0 && doc instanceof GuardedDocument) {
468
                    MutablePositionRegion region = IndentSpiPackageAccessor.get().positionRegion(indentRegions.get(0));
467
//                    MutablePositionRegion region = IndentSpiPackageAccessor.get().positionRegion(indentRegions.get(0));
469
                    int regionStartOffset = region.getStartOffset();
468
//                    int regionStartOffset = region.getStartOffset();
470
                    GuardedDocument gdoc = (GuardedDocument)doc;
469
//                    GuardedDocument gdoc = (GuardedDocument)doc;
471
//                    int gbStartOffset = guardedBlocks.adjustToBlockEnd(region.getEndOffset());
470
//                    int gbStartOffset = guardedBlocks.adjustToBlockEnd(region.getEndOffset());
472
//                    MarkBlockChain guardedBlocks = gdoc.getGuardedBlockChain();
471
//                    MarkBlockChain guardedBlocks = gdoc.getGuardedBlockChain();
473
//                    if (guardedBlocks != null && guardedBlocks.getChain() != null) {
472
//                    if (guardedBlocks != null && guardedBlocks.getChain() != null) {
 Lines 500-506    Link Here 
500
//                            }
499
//                            }
501
//                        }
500
//                        }
502
//                    }
501
//                    }
503
                }
502
//                }
504
            } catch (BadLocationException e) {
503
            } catch (BadLocationException e) {
505
                Exceptions.printStackTrace(e);
504
                Exceptions.printStackTrace(e);
506
                indentRegions = Collections.emptyList();
505
                indentRegions = Collections.emptyList();
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/api/Indent.java (+19 lines)
 Lines 171-174    Link Here 
171
        impl.reindent(startOffset, endOffset, startOffset, false);
171
        impl.reindent(startOffset, endOffset, startOffset, false);
172
    }
172
    }
173
173
174
    /**
175
     * Creates new line at <code>offset</code> and reindents it.
176
     *
177
     * <p>This method will insert a line break (ie EOL character) at the specified
178
     * offset and then reindent the newly created line. The method will return the
179
     * offset of the indented beginning of the new line. That is the offset where
180
     * the new text should appear when typing in the document.
181
     *
182
     * @param offset The document offset where the new line will be created.
183
     *
184
     * @return The offset of the first non-white character (or the EOL character)
185
     *   on the new line. This is basically where the caret should be moved to.
186
     * @throws javax.swing.text.BadLocationException
187
     * @since 1.10
188
     */
189
    public int indentNewLine(int offset) throws BadLocationException {
190
        return impl.reindent(offset, offset, offset, true);
191
    }
192
174
}
193
}
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/spi/support/AutomatedIndenting.java (+238 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.indent.spi.support;
41
42
import java.lang.reflect.Method;
43
import java.util.ArrayList;
44
import java.util.Map;
45
import java.util.logging.Level;
46
import java.util.logging.Logger;
47
import java.util.regex.Pattern;
48
import java.util.regex.PatternSyntaxException;
49
import javax.swing.text.BadLocationException;
50
import javax.swing.text.Document;
51
import javax.swing.text.Element;
52
import org.netbeans.api.editor.mimelookup.MimePath;
53
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
54
import org.netbeans.modules.editor.indent.api.Indent;
55
import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor;
56
57
/**
58
 * This class contains factory methods for typing interceptor implementations
59
 * that can be used for automated text indenting.
60
 *
61
 * <p>The interceptors provided by this class are implementations of Typing Hooks SPI
62
 * interfaces that can be registered in <code>MimeLookup</code>. Typically there are
63
 * two factory methods for each interceptor implementation. One factory method creates
64
 * the implementated interceptor and is suitable for direct use from java code. The
65
 * other factory method creates a factory object that can be registred in an XML layer
66
 * as an <code>.instance</code> file.
67
 *
68
 * @author Vita Stejskal
69
 * @since 1.11
70
 */
71
public final class AutomatedIndenting {
72
73
    /**
74
     * Creates <code>TypedTextInterceptor</code> that automatically
75
     * indents a line depending on text typed on that line.
76
     *
77
     * <p>The text patterns recognized by the intercetor are defined in form
78
     * of regular expressions passed to this method. The interceptor will match
79
     * all text before the caret on the line where a user is typing (including
80
     * the last typed character) against the regular expression patterns. If the text
81
     * matches at least one pattern the interceptor will reindent the line by
82
     * calling {@link Indent#reindent(int)} method.
83
     *
84
     * @param linePatterns The regular expressions that will be used for matching
85
     *   text typed on a line. Any matching pattern will trigger the line reindentation.
86
     *
87
     * @return The interceptor that checks text typed on a line and reindents the line
88
     *   if it matches any of the <code>linePatterns</code>.
89
     *
90
     * @since 1.11
91
     */
92
    public static TypedTextInterceptor createHotCharsIndenter(Pattern... linePatterns) {
93
        return new RegExBasedIndenter(linePatterns);
94
    }
95
96
    /**
97
     * This is a version of {@link #createHotCharsIndenter(java.util.regex.Pattern[])} method suitable
98
     * for XML layers registration.
99
     *
100
     * <div class="nonnormative">
101
     * <p>Here is an example of an XML layer registration done
102
     * for <code>text/x-java</code> mime type. The registered interceptor will indent
103
     * any line that contains whitespace followed by 'else'. The ending 'e' character is
104
     * the last character typed on the line.
105
     *
106
     * <pre>
107
     * &lt;folder name="Editors"&gt;
108
     *  &lt;folder name="text"&gt;
109
     *   &lt;folder name="x-java"&gt;
110
     *    &lt;file name="org-something-AutoIndenter.instance"&gt;
111
     *     &lt;attr name="instanceOf" stringvalue="org.netbeans.spi.editor.typinghooks.TypedTextInterceptor"/&gt;
112
     *     &lt;attr name="instanceCreate"
113
     *              methodvalue="org.netbeans.modules.editor.indent.spi.support.AutomatedIndenting.createHotCharsIndenter"/&gt;
114
     *     &lt;attr name="regex1" stringvalue="\s*else"/&gt;
115
     *    &lt;/file&gt;
116
     *   &lt;/folder&gt;
117
     *  &lt;/folder&gt;
118
     * &lt;/folder&gt;
119
     * </pre>
120
     * </div>
121
     *
122
     * @param fileAttributes The map of <code>FileObject</code> attributes. This method
123
     *   will recognize any attributes, which name starts with <code>regex</code> and will
124
     *   try to interpret their value as a regular expression. These regular expressions
125
     *   will then be used as <code>linePatterns</code> when calling <code>createHotCharsIndenter(Pattern...)</code> method.
126
     * 
127
     * @return The interceptor factory that will provide a regular expressions based
128
     *   automated indenter returned from the {@link #createHotCharsIndenter(java.util.regex.Pattern[])} method.
129
     *   The list of line patterns will be recovered from the <code>fileAttributes</code>.
130
     * 
131
     * @since 1.11
132
     */
133
    public static TypedTextInterceptor.Factory createHotCharsIndenter(Map<Object, Object> fileAttributes) {
134
        final ArrayList<Pattern> linePatterns = new ArrayList<Pattern>();
135
136
        for(Object key : fileAttributes.keySet()) {
137
            if (key.toString().startsWith("regex")) { //NOI18N
138
                Object value = fileAttributes.get(key);
139
                try {
140
                    Pattern pattern = Pattern.compile(value.toString());
141
                    linePatterns.add(pattern);
142
                } catch (PatternSyntaxException pse) {
143
                    LOG.log(Level.WARNING, null, pse);
144
                }
145
            }
146
        }
147
148
        return new TypedTextInterceptor.Factory() {
149
            public TypedTextInterceptor createTypedTextInterceptor(MimePath mimePath) {
150
                return createHotCharsIndenter(linePatterns.toArray(new Pattern [linePatterns.size()]));
151
            }
152
        };
153
    }
154
155
    // ------------------------------------------------------------------------
156
    // private
157
    // ------------------------------------------------------------------------
158
159
    private static final Logger LOG = Logger.getLogger(AutomatedIndenting.class.getName());
160
    
161
    private static final class RegExBasedIndenter implements TypedTextInterceptor {
162
163
        private final Pattern [] linePatterns;
164
165
        public RegExBasedIndenter(Pattern... linePatterns) {
166
            this.linePatterns = linePatterns;
167
        }
168
169
        public boolean beforeInsert(Context context) {
170
            // no-op
171
            return false;
172
        }
173
174
        public void insert(MutableContext context) {
175
            // no-op
176
        }
177
178
        public void afterInsert(Context context) {
179
            int textLen = context.getText().length();
180
            if (textLen > 0) {
181
                CharSequence lineText;
182
                final int lineStartOffset;
183
                final int lineEndOffset;
184
185
                try {
186
                    Element lineElement = DocumentUtilities.getParagraphElement(context.getDocument(), context.getOffset());
187
                    lineText = DocumentUtilities.getText(context.getDocument(),
188
                        lineElement.getStartOffset(),
189
                        context.getOffset() - lineElement.getStartOffset() + textLen);
190
                    lineStartOffset = lineElement.getStartOffset();
191
                    lineEndOffset = Math.max(lineStartOffset, lineElement.getEndOffset() - 1); // without EOL
192
                } catch (Exception e) {
193
                    LOG.log(Level.INFO, null, e);
194
                    return;
195
                }
196
197
                for(Pattern p : linePatterns) {
198
                    if (p.matcher(lineText).matches()) {
199
                        if (LOG.isLoggable(Level.FINE)) {
200
                            LOG.fine("The line '" + lineText + "' matches '" + p.pattern() //NOI18N
201
                                + "' -> calling Indent.reindent(" + lineStartOffset + ", " + lineEndOffset + ")"); //NOI18N
202
                        }
203
204
                        final Indent indenter = Indent.get(context.getDocument());
205
                        indenter.lock();
206
                        try {
207
                            runAtomicAsUser(context.getDocument(), new Runnable() {
208
                                public void run() {
209
                                    try {
210
                                        indenter.reindent(lineStartOffset, lineEndOffset);
211
                                    } catch (BadLocationException ble) {
212
                                        LOG.log(Level.INFO, null, ble);
213
                                    }
214
                                }
215
                            });
216
                        } finally {
217
                            indenter.unlock();
218
                        }
219
                        break;
220
                    }
221
                }
222
            }
223
        }
224
225
        public void cancelled(Context context) {
226
            // no-op
227
        }
228
229
        private static void runAtomicAsUser(Document doc, Runnable run) {
230
            try {
231
                Method runAtomicAsUserMethod = doc.getClass().getMethod("runAtomicAsUser", Runnable.class); //NOI18N
232
                runAtomicAsUserMethod.invoke(doc, run);
233
            } catch (Exception e) {
234
                LOG.log(Level.INFO, null, e);
235
            }
236
        }
237
    } // End of RegExBasedIndenter class
238
}
(-)a/editor.lib/apichanges.xml (+84 lines)
 Lines 107-112    Link Here 
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
111
        <change id="deprecating-formatting">
112
            <summary>Deprecating old formatting API</summary>
113
            <version major="3" minor="1"/>
114
            <date day="24" month="8" year="2010"/>
115
            <author login="vstejskal"/>
116
            <compatibility binary="incompatible" source="incompatible" semantic="incompatible" addition="yes" deprecation="yes" deletion="yes" modification="yes"/>
117
            <description>
118
                <p>
119
                    The old formatting API (<code>org.netbeans.editor.Formatter</code> &amp; co.)
120
                    has been deprecated and moved to <code>editor.deprecated.pre65formatting</code> module.
121
                </p>
122
                <p>The exact API changes are listed in the sigtest report below.</p>
123
<pre>
124
-sigtest-init:
125
     [echo] sigtest check: editor.lib; cnb: org-netbeans-modules-editor-lib; email: api-changes@netbeans.org; type: check
126
127
check-sigtest:
128
    [mkdir] Created dir: /work/netbeans/main2m/editor.lib/build/test/sigtest/results
129
  [sigtest] /work/netbeans/main2m/editor.lib/build/test/sigtest/results/org.netbeans.modules.editor.lib
130
  [sigtest] Packages: org.netbeans.editor.*, org.netbeans.editor.ext.*, org.netbeans.editor.view.spi.*, org.netbeans.lib.editor.hyperlink.spi.*, org.netbeans.lib.editor.view.*
131
  [sigtest] Missing /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/rt.jar
132
  [sigtest] 
133
  [sigtest] email: api-changes@netbeans.org
134
  [sigtest] SignatureTest report
135
  [sigtest] Base version: 2.11.0
136
  [sigtest] Tested version: 2.11.0
137
  [sigtest] Check mode: bin [throws removed]
138
  [sigtest] Constant checking: on
139
  [sigtest] 
140
  [sigtest] 
141
  [sigtest] Class org.netbeans.editor.BaseDocument
142
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseDocument.getFormatter()
143
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseDocument.getLegacyFormatter()
144
  [sigtest] 
145
  [sigtest] Class org.netbeans.editor.BaseKit
146
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseKit.createFormatter()
147
  [sigtest] 
148
  [sigtest] Class org.netbeans.editor.BaseKit$PasteAction
149
  [sigtest]   "E1.2 - API type removed" : method public static void org.netbeans.editor.BaseKit$PasteAction.indentBlock(org.netbeans.editor.BaseDocument,int,int)
150
  [sigtest] 
151
  [sigtest] Class org.netbeans.editor.Formatter
152
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.Formatter
153
  [sigtest] 
154
  [sigtest] Class org.netbeans.editor.GuardedDocument
155
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseDocument.getFormatter()
156
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseDocument.getLegacyFormatter()
157
  [sigtest] 
158
  [sigtest] Class org.netbeans.editor.ext.AbstractFormatLayer
159
  [sigtest]   "E1.2 - API type removed" : CLASS public abstract org.netbeans.editor.ext.AbstractFormatLayer
160
  [sigtest] 
161
  [sigtest] Class org.netbeans.editor.ext.ExtFormatSupport
162
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.ext.ExtFormatSupport
163
  [sigtest] 
164
  [sigtest] Class org.netbeans.editor.ext.ExtFormatter
165
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.ext.ExtFormatter
166
  [sigtest] 
167
  [sigtest] Class org.netbeans.editor.ext.ExtFormatter$Simple
168
  [sigtest]   "E1.2 - API type removed" : CLASS public static org.netbeans.editor.ext.ExtFormatter$Simple
169
  [sigtest] 
170
  [sigtest] Class org.netbeans.editor.ext.ExtKit
171
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseKit.createFormatter()
172
  [sigtest] 
173
  [sigtest] Class org.netbeans.editor.ext.FormatLayer
174
  [sigtest]   "E1.2 - API type removed" : CLASS public abstract interface org.netbeans.editor.ext.FormatLayer
175
  [sigtest] 
176
  [sigtest] Class org.netbeans.editor.ext.FormatSupport
177
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.ext.FormatSupport
178
  [sigtest] 
179
  [sigtest] Class org.netbeans.editor.ext.FormatTokenPosition
180
  [sigtest]   "E1.2 - API type removed" : CLASS public abstract interface org.netbeans.editor.ext.FormatTokenPosition
181
  [sigtest] 
182
  [sigtest] Class org.netbeans.editor.ext.FormatWriter
183
  [sigtest]   "E1.2 - API type removed" : CLASS public final org.netbeans.editor.ext.FormatWriter
184
  [sigtest] 
185
  [sigtest] /work/netbeans/main2m/editor.lib/build/test/sigtest/results/org-netbeans-modules-editor-lib.xml: 1 failures in /work/netbeans/main2m/editor.lib/nbproject/org-netbeans-modules-editor-lib.sig
186
187
BUILD FAILED
188
Signature tests return code is wrong (1), check the messages above
189
</pre>                
190
            </description>
191
            <issue number="189638"/>
192
        </change>
193
        
110
        <change id="ToolTipSupport-heavyweight-tooltips">
194
        <change id="ToolTipSupport-heavyweight-tooltips">
111
            <summary>Support for heavyweight tooltips</summary>
195
            <summary>Support for heavyweight tooltips</summary>
112
            <version major="2" minor="10"/>
196
            <version major="2" minor="10"/>
(-)a/editor.lib/manifest.mf (-2 / +2 lines)
 Lines 1-4    Link Here 
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor.lib/2
2
OpenIDE-Module: org.netbeans.modules.editor.lib/3
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib/Bundle.properties
4
OpenIDE-Module-Implementation-Version: 10
4
OpenIDE-Module-Implementation-Version: 11
(-)a/editor.lib/module-auto-deps.xml (-1 / +3 lines)
 Lines 48-54    Link Here 
48
48
49
<transformations version="1.0">
49
<transformations version="1.0">
50
    <transformationgroup>
50
    <transformationgroup>
51
        <description>Old editor settings and completion APIs have been deprecated, see http://wiki.netbeans.org/EditorSettingsUpgrade and update your module.</description>
51
        <description>The old editor settings and completion APIs have been deprecated, see http://wiki.netbeans.org/EditorSettingsUpgrade and update your module.</description>
52
        <transformation>
52
        <transformation>
53
            <trigger-dependency type="older">
53
            <trigger-dependency type="older">
54
                <module-dependency codenamebase="org.netbeans.modules.editor.lib" major="1" spec="1.27"/>
54
                <module-dependency codenamebase="org.netbeans.modules.editor.lib" major="1" spec="1.27"/>
 Lines 56-61    Link Here 
56
            <implies>
56
            <implies>
57
                <result>
57
                <result>
58
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61completion" major="0" spec="1.0"/>
58
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61completion" major="0" spec="1.0"/>
59
                </result>
60
                <result>
59
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61settings" major="0" spec="1.0"/>
61
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61settings" major="0" spec="1.0"/>
60
                </result>
62
                </result>
61
            </implies>
63
            </implies>
(-)a/editor.lib/nbproject/project.properties (-1 / +1 lines)
 Lines 42-48    Link Here 
42
42
43
javac.compilerargs=-Xlint:unchecked
43
javac.compilerargs=-Xlint:unchecked
44
javac.source=1.6
44
javac.source=1.6
45
spec.version.base=2.11.0
45
spec.version.base=3.1
46
is.autoload=true
46
is.autoload=true
47
47
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml
(-)a/editor.lib/nbproject/project.xml (+17 lines)
 Lines 67-72    Link Here 
67
                    </run-dependency>
67
                    </run-dependency>
68
                </dependency>
68
                </dependency>
69
                <dependency>
69
                <dependency>
70
                    <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
73
                    <run-dependency>
74
                        <release-version>2</release-version>
75
                        <specification-version>1.9</specification-version>
76
                    </run-dependency>
77
                </dependency>
78
                <dependency>
70
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
79
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
71
                    <build-prerequisite/>
80
                    <build-prerequisite/>
72
                    <compile-dependency/>
81
                    <compile-dependency/>
 Lines 136-141    Link Here 
136
                    </run-dependency>
145
                    </run-dependency>
137
                </dependency>
146
                </dependency>
138
                <dependency>
147
                <dependency>
148
                    <code-name-base>org.openide.filesystems</code-name-base>
149
                    <build-prerequisite/>
150
                    <compile-dependency/>
151
                    <run-dependency>
152
                        <specification-version>7.13</specification-version>
153
                    </run-dependency>
154
                </dependency>
155
                <dependency>
139
                    <code-name-base>org.openide.util</code-name-base>
156
                    <code-name-base>org.openide.util</code-name-base>
140
                    <build-prerequisite/>
157
                    <build-prerequisite/>
141
                    <compile-dependency/>
158
                    <compile-dependency/>
(-)a/editor.lib/src/org/netbeans/editor/Abbrev.java (-4 / +10 lines)
 Lines 56-61    Link Here 
56
import javax.swing.text.Caret;
56
import javax.swing.text.Caret;
57
import org.netbeans.lib.editor.util.CharSequenceUtilities;
57
import org.netbeans.lib.editor.util.CharSequenceUtilities;
58
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
58
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
59
import org.netbeans.modules.editor.indent.api.Reformat;
59
60
60
/** 
61
/** 
61
 * Abbreviation support allowing to expand defined character sequences
62
 * Abbreviation support allowing to expand defined character sequences
 Lines 296-307    Link Here 
296
            }
297
            }
297
298
298
            if(ins.indexOf("\n") != -1) { // NOI18N
299
            if(ins.indexOf("\n") != -1) { // NOI18N
299
                Formatter formatter = doc.getFormatter();
300
                Reformat formatter = Reformat.get(doc);
300
                formatter.reformatLock();
301
                formatter.lock();
301
                try {
302
                try {
302
                    formatter.reformat(doc, dotPos, dotPos + ins.length());
303
                    doc.atomicLock();
304
                    try {
305
                        formatter.reformat(dotPos, dotPos + ins.length());
306
                    } finally {
307
                        doc.atomicUnlock();
308
                    }
303
                } finally {
309
                } finally {
304
                    formatter.reformatUnlock();
310
                    formatter.unlock();
305
                }
311
                }
306
            }
312
            }
307
            
313
            
(-)a/editor.lib/src/org/netbeans/editor/ActionFactory.java (-48 / +142 lines)
 Lines 45-50    Link Here 
45
package org.netbeans.editor;
45
package org.netbeans.editor;
46
46
47
import java.awt.Component;
47
import java.awt.Component;
48
import java.awt.Cursor;
48
import java.awt.Rectangle;
49
import java.awt.Rectangle;
49
import java.awt.event.ActionEvent;
50
import java.awt.event.ActionEvent;
50
import java.beans.PropertyChangeEvent;
51
import java.beans.PropertyChangeEvent;
 Lines 52-57    Link Here 
52
import java.util.Map;
53
import java.util.Map;
53
import java.util.HashMap;
54
import java.util.HashMap;
54
import java.util.HashSet;
55
import java.util.HashSet;
56
import java.util.logging.Level;
55
import javax.swing.Action;
57
import javax.swing.Action;
56
import javax.swing.ActionMap;
58
import javax.swing.ActionMap;
57
import javax.swing.ButtonModel;
59
import javax.swing.ButtonModel;
 Lines 77-82    Link Here 
77
import java.util.concurrent.atomic.AtomicBoolean;
79
import java.util.concurrent.atomic.AtomicBoolean;
78
import java.util.logging.Level;
80
import java.util.logging.Level;
79
import java.util.logging.Logger;
81
import java.util.logging.Logger;
82
import javax.swing.ImageIcon;
80
import javax.swing.JToggleButton;
83
import javax.swing.JToggleButton;
81
import javax.swing.event.ChangeListener;
84
import javax.swing.event.ChangeListener;
82
import javax.swing.text.AbstractDocument;
85
import javax.swing.text.AbstractDocument;
 Lines 89-94    Link Here 
89
import org.netbeans.api.progress.ProgressUtils;
92
import org.netbeans.api.progress.ProgressUtils;
90
import org.netbeans.modules.editor.lib2.search.EditorFindSupport;
93
import org.netbeans.modules.editor.lib2.search.EditorFindSupport;
91
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
94
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
95
import org.netbeans.modules.editor.indent.api.Indent;
96
import org.netbeans.modules.editor.indent.api.Reformat;
97
import org.netbeans.modules.editor.lib2.typinghooks.TypedBreakInterceptorsManager;
92
import org.openide.util.ImageUtilities;
98
import org.openide.util.ImageUtilities;
93
import org.openide.util.NbBundle;
99
import org.openide.util.NbBundle;
94
import org.openide.util.WeakListeners;
100
import org.openide.util.WeakListeners;
 Lines 107-112    Link Here 
107
113
108
public class ActionFactory {
114
public class ActionFactory {
109
115
116
    // -J-Dorg.netbeans.editor.ActionFactory.level=FINE
117
    private static final Logger LOG = Logger.getLogger(ActionFactory.class.getName());
118
    
110
    private ActionFactory() {
119
    private ActionFactory() {
111
        // no instantiation
120
        // no instantiation
112
    }
121
    }
 Lines 133-144    Link Here 
133
                doc.runAtomicAsUser (new Runnable () {
142
                doc.runAtomicAsUser (new Runnable () {
134
                    public void run () {
143
                    public void run () {
135
                        DocumentUtilities.setTypingModification(doc, true);
144
                        DocumentUtilities.setTypingModification(doc, true);
136
                        Formatter.pushFormattingContextDocument(doc);
137
                        try {
145
                        try {
138
                            if (Utilities.isSelectionShowing(caret)) { // block selected
146
                            if (Utilities.isSelectionShowing(caret)) { // block selected
139
                                try {
147
                                try {
140
                                    doc.getFormatter().changeBlockIndent(doc,
148
                                    BaseKit.changeBlockIndent(
141
                                            target.getSelectionStart(), target.getSelectionEnd(), -1);
149
                                        doc,
150
                                        target.getSelectionStart(),
151
                                        target.getSelectionEnd(),
152
                                        -1);
142
                                } catch (GuardedException e) {
153
                                } catch (GuardedException e) {
143
                                    target.getToolkit().beep();
154
                                    target.getToolkit().beep();
144
                                } catch (BadLocationException e) {
155
                                } catch (BadLocationException e) {
 Lines 150-156    Link Here 
150
                                    int firstNW = Utilities.getRowFirstNonWhite(doc, caret.getDot());
161
                                    int firstNW = Utilities.getRowFirstNonWhite(doc, caret.getDot());
151
                                    int endOffset = Utilities.getRowEnd(doc, caret.getDot());
162
                                    int endOffset = Utilities.getRowEnd(doc, caret.getDot());
152
                                    if (firstNW == -1 || (firstNW >= caret.getDot()))
163
                                    if (firstNW == -1 || (firstNW >= caret.getDot()))
153
                                        doc.getFormatter().changeBlockIndent(doc, startOffset, endOffset, -1);
164
                                        BaseKit.changeBlockIndent(doc, startOffset, endOffset, -1);
154
                                    else {
165
                                    else {
155
                                        // TODO:
166
                                        // TODO:
156
                                        // after we will have action which will do opposite to "tab" action
167
                                        // after we will have action which will do opposite to "tab" action
 Lines 164-170    Link Here 
164
                                }
175
                                }
165
                            }
176
                            }
166
                        } finally {
177
                        } finally {
167
                            Formatter.popFormattingContextDocument(doc);
168
                            DocumentUtilities.setTypingModification(doc, false);
178
                            DocumentUtilities.setTypingModification(doc, false);
169
                        }
179
                        }
170
                    }
180
                    }
 Lines 1447-1468    Link Here 
1447
                doc.runAtomicAsUser (new Runnable () {
1457
                doc.runAtomicAsUser (new Runnable () {
1448
                    public void run () {
1458
                    public void run () {
1449
                        DocumentUtilities.setTypingModification(doc, true);
1459
                        DocumentUtilities.setTypingModification(doc, true);
1450
                        Formatter.pushFormattingContextDocument(doc);
1451
                        try {
1460
                        try {
1452
                            boolean right = BaseKit.shiftLineRightAction.equals(getValue(Action.NAME));
1461
                            boolean right = BaseKit.shiftLineRightAction.equals(getValue(Action.NAME));
1453
                            if (Utilities.isSelectionShowing(caret)) {
1462
                            if (Utilities.isSelectionShowing(caret)) {
1454
                                doc.getFormatter().changeBlockIndent(doc,
1463
                                BaseKit.changeBlockIndent(
1455
                                target.getSelectionStart(), target.getSelectionEnd(),
1464
                                    doc,
1456
                                right ? +1 : -1);
1465
                                    target.getSelectionStart(), target.getSelectionEnd(),
1466
                                    right ? +1 : -1);
1457
                            } else {
1467
                            } else {
1458
                                doc.getFormatter().shiftLine(doc, caret.getDot(), right);
1468
                                BaseKit.shiftLine(doc, caret.getDot(), right);
1459
                            }
1469
                            }
1460
                        } catch (GuardedException e) {
1470
                        } catch (GuardedException e) {
1461
                            target.getToolkit().beep();
1471
                            target.getToolkit().beep();
1462
                        } catch (BadLocationException e) {
1472
                        } catch (BadLocationException e) {
1463
                            e.printStackTrace();
1473
                            e.printStackTrace();
1464
                        } finally {
1474
                        } finally {
1465
                            Formatter.popFormattingContextDocument(doc);
1466
                            DocumentUtilities.setTypingModification(doc, false);
1475
                            DocumentUtilities.setTypingModification(doc, false);
1467
                        }
1476
                        }
1468
                    }
1477
                    }
 Lines 1494-1502    Link Here 
1494
                final GuardedDocument gdoc = (doc instanceof GuardedDocument)
1503
                final GuardedDocument gdoc = (doc instanceof GuardedDocument)
1495
                                       ? (GuardedDocument)doc : null;
1504
                                       ? (GuardedDocument)doc : null;
1496
1505
1497
                final Formatter formatter = doc.getFormatter();
1506
                final Reformat formatter = Reformat.get(doc);
1498
                formatter.reformatLock();
1507
                formatter.lock();
1499
                Formatter.pushFormattingContextDocument(doc);
1500
                try {
1508
                try {
1501
                    doc.runAtomicAsUser (new Runnable () {
1509
                    doc.runAtomicAsUser (new Runnable () {
1502
                        public void run () {
1510
                        public void run () {
 Lines 1527-1534    Link Here 
1527
                                        }
1535
                                        }
1528
                                    }
1536
                                    }
1529
1537
1530
                                    int reformattedLen = formatter.reformat(doc, pos, stopPos);
1538
                                    Position stopPosition = doc.createPosition(stopPos);
1531
                                    pos = pos + reformattedLen;
1539
                                    formatter.reformat(pos, stopPos);
1540
                                    pos = pos + Math.max(stopPosition.getOffset() - pos, 0);
1532
1541
1533
                                    if (gdoc != null) { // adjust to end of current block
1542
                                    if (gdoc != null) { // adjust to end of current block
1534
                                        pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos);
1543
                                        pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos);
 Lines 1542-1549    Link Here 
1542
                        }
1551
                        }
1543
                    });
1552
                    });
1544
                } finally {
1553
                } finally {
1545
                    Formatter.popFormattingContextDocument(doc);
1554
                    formatter.unlock();
1546
                    formatter.reformatUnlock();
1547
                }
1555
                }
1548
            }
1556
            }
1549
        }
1557
        }
 Lines 1637-1651    Link Here 
1637
                    return;
1645
                    return;
1638
                final GuardedDocument gdoc = (doc instanceof GuardedDocument)
1646
                final GuardedDocument gdoc = (doc instanceof GuardedDocument)
1639
                                       ? (GuardedDocument)doc : null;
1647
                                       ? (GuardedDocument)doc : null;
1648
                
1649
                // Set hourglass cursor
1650
                final Cursor origCursor = target.getCursor();
1651
                target.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1640
1652
1641
                try {
1653
                try {
1642
                final AtomicBoolean canceled = new AtomicBoolean();
1654
                final AtomicBoolean canceled = new AtomicBoolean();
1643
                ProgressUtils.runOffEventDispatchThread(new Runnable() {
1655
                ProgressUtils.runOffEventDispatchThread(new Runnable() {
1644
                    public void run() {
1656
                    public void run() {
1645
                        if (canceled.get()) return;
1657
                        if (canceled.get()) return;
1646
                        final Formatter formatter = doc.getFormatter();
1658
                        final Reformat formatter = Reformat.get(doc);
1647
                        formatter.reformatLock();
1659
                        formatter.lock();
1648
                        Formatter.pushFormattingContextDocument(doc);
1649
                        try {
1660
                        try {
1650
                            if (canceled.get()) return;
1661
                            if (canceled.get()) return;
1651
                            doc.runAtomicAsUser (new Runnable () {
1662
                            doc.runAtomicAsUser (new Runnable () {
 Lines 1680-1687    Link Here 
1680
                                            }
1691
                                            }
1681
1692
1682
                                            if (pos < stopPos) {
1693
                                            if (pos < stopPos) {
1683
                                                int reformattedLen = formatter.reformat(doc, pos, stopPos);
1694
                                                Position stopPosition = doc.createPosition(stopPos);
1684
                                                pos = pos + reformattedLen;
1695
                                                formatter.reformat(pos, stopPos);
1696
                                                pos = pos + Math.max(stopPosition.getOffset() - pos, 0);
1685
                                            } else {
1697
                                            } else {
1686
                                                pos++; //ensure to make progress
1698
                                                pos++; //ensure to make progress
1687
                                            }
1699
                                            }
 Lines 1695-1706    Link Here 
1695
                                        target.getToolkit().beep();
1707
                                        target.getToolkit().beep();
1696
                                    } catch (BadLocationException e) {
1708
                                    } catch (BadLocationException e) {
1697
                                        Utilities.annotateLoggable(e);
1709
                                        Utilities.annotateLoggable(e);
1710
                                    } finally {
1711
                                        target.setCursor(origCursor);
1698
                                    }
1712
                                    }
1699
                                }
1713
                                }
1700
                            });
1714
                            });
1701
                        } finally {
1715
                        } finally {
1702
                            Formatter.popFormattingContextDocument(doc);
1716
                            formatter.unlock();
1703
                            formatter.reformatUnlock();
1704
                        }
1717
                        }
1705
                    }
1718
                    }
1706
                }, NbBundle.getMessage(FormatAction.class, "Format_in_progress"), canceled, false); //NOI18N
1719
                }, NbBundle.getMessage(FormatAction.class, "Format_in_progress"), canceled, false); //NOI18N
 Lines 1710-1716    Link Here 
1710
                }
1723
                }
1711
            }
1724
            }
1712
        }
1725
        }
1713
        
1714
    }
1726
    }
1715
1727
1716
    @EditorActionRegistrations({
1728
    @EditorActionRegistrations({
 Lines 2331-2337    Link Here 
2331
        }
2343
        }
2332
    }
2344
    }
2333
    
2345
    
2334
    /** Starts a new line in code. */
2346
    /** 
2347
     * Starts a new line in code.
2348
     * 
2349
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
2350
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
2351
     */
2335
    @EditorActionRegistration(name = BaseKit.startNewLineAction)
2352
    @EditorActionRegistration(name = BaseKit.startNewLineAction)
2336
    public static class StartNewLine extends LocalBaseAction {
2353
    public static class StartNewLine extends LocalBaseAction {
2337
        public StartNewLine(){
2354
        public StartNewLine(){
 Lines 2345-2379    Link Here 
2345
                return;
2362
                return;
2346
            }
2363
            }
2347
            
2364
            
2365
            final int caretOffset;
2366
            final int insertionOffset;
2367
            
2368
            try {
2369
                caretOffset = target.getCaretPosition();
2370
                insertionOffset = Utilities.getRowEnd(target, caretOffset);
2371
            } catch (BadLocationException ble) {
2372
                LOG.log(Level.FINE, null, ble);
2373
                return;
2374
            }
2348
            
2375
            
2349
            final BaseDocument doc = (BaseDocument)target.getDocument();
2376
            final BaseDocument doc = (BaseDocument)target.getDocument();
2350
            final Formatter formatter = doc.getFormatter();
2377
            final TypedBreakInterceptorsManager.Transaction transaction = TypedBreakInterceptorsManager.getInstance().openTransaction(
2351
            formatter.indentLock();
2378
                    target, caretOffset, insertionOffset);
2379
2352
            try {
2380
            try {
2353
                doc.runAtomicAsUser (new Runnable () {
2381
                if (!transaction.beforeInsertion()) {
2354
                    public void run () {
2382
                    final Boolean [] result = new Boolean [] { Boolean.FALSE }; //NOI18N
2355
                        try {
2383
                    final Indent indenter = Indent.get(doc);
2356
                            //target.replaceSelection(""); //NOI18N -fix of issue #52485
2384
                    indenter.lock();
2357
                            Caret caret = target.getCaret();
2385
                    try {
2386
                        doc.runAtomicAsUser (new Runnable () {
2387
                            public void run () {
2388
                                Object [] r = transaction.textTyped();
2389
                                String insertionText = r == null ? "\n" : (String) r[0]; //NOI18N
2390
                                int breakInsertPosition = r == null ? -1 : (Integer) r[1];
2391
                                int caretPosition = r == null ? -1 : (Integer) r[2];
2392
                                int [] reindentBlocks = r == null ? null : (int []) r[3];
2358
2393
2359
                            // insert and remove '-' to remember caret
2394
                                try {
2360
                            // position
2395
                                    performLineBreakInsertion(target, insertionOffset, insertionText, breakInsertPosition, caretPosition, reindentBlocks, indenter);
2361
                            int dotpos = caret.getDot();
2396
                                    result[0] = Boolean.TRUE;
2362
                            doc.insertString(dotpos,"-",null); //NOI18N
2397
                                } catch (BadLocationException ble) {
2363
                            doc.remove(dotpos,1);
2398
                                    LOG.log(Level.FINE, null, ble);
2364
                            int eolDot = Utilities.getRowEnd(target, caret.getDot());
2399
                                    target.getToolkit().beep();
2365
                            int newDotPos = formatter.indentNewLine(doc,eolDot);
2400
                                }
2366
                            caret.setDot(newDotPos);
2401
                            }
2367
                        } catch (BadLocationException ex) {
2402
                        });
2368
                            ex.printStackTrace();
2403
                    } finally {
2369
                        }
2404
                        indenter.unlock();
2370
                    }
2405
                    }
2371
                });
2406
2407
                    if (result[0].booleanValue()) {
2408
                        transaction.afterInsertion();
2409
                    } // else line-break insertion failed
2410
2411
                }
2372
            } finally {
2412
            } finally {
2373
                formatter.indentUnlock();
2413
                transaction.close();
2374
            }
2414
            }
2375
        }
2415
        }
2376
    }
2416
        
2417
        // --------------------------------------------------------------------
2418
        // Private implementation
2419
        // --------------------------------------------------------------------
2420
2421
        private void performLineBreakInsertion(
2422
                JTextComponent target, 
2423
                int insertionOffset, 
2424
                String insertionText, 
2425
                int breakInsertPosition, 
2426
                int caretPosition, 
2427
                int [] reindentBlocks,
2428
                Indent indenter) throws BadLocationException
2429
        {
2430
            BaseDocument doc = (BaseDocument) target.getDocument();
2431
            DocumentUtilities.setTypingModification(doc, true);
2432
            try {
2433
                //target.replaceSelection(""); //NOI18N -fix of issue #52485
2434
                Caret caret = target.getCaret();
2435
2436
                // XXX: WTF is this?
2437
                // insert and remove '-' to remember caret
2438
                // position
2439
                int dotPos = caret.getDot();
2440
                doc.insertString(dotPos, "-", null); //NOI18N
2441
                doc.remove(dotPos, 1);
2442
2443
                // insert new line, caret moves to the new line
2444
//                int eolDot = Utilities.getRowEnd(target, caret.getDot());
2445
//                doc.insertString(eolDot, "\n", null); //NOI18N
2446
                doc.insertString(insertionOffset, insertionText, null);
2447
                dotPos = insertionOffset;
2448
                dotPos += caretPosition != -1 ? caretPosition :
2449
                          breakInsertPosition != -1 ? breakInsertPosition + 1 :
2450
                          insertionText.indexOf('\n') + 1; //NOI18N
2451
2452
                // reindent the new line
2453
                Position newDotPos = doc.createPosition(dotPos);
2454
                if (reindentBlocks != null && reindentBlocks.length > 0) {
2455
                    for(int i = 0; i < reindentBlocks.length / 2; i++) {
2456
                        int startOffset = insertionOffset + reindentBlocks[2 * i];
2457
                        int endOffset = insertionOffset + reindentBlocks[2 * i + 1];
2458
                        indenter.reindent(startOffset, endOffset);
2459
                    }
2460
                } else {
2461
                    indenter.reindent(dotPos);
2462
                }
2463
2464
                caret.setDot(newDotPos.getOffset());
2465
            } finally {
2466
                DocumentUtilities.setTypingModification(doc, false);
2467
            }
2468
        }
2469
        
2470
    } // End of StartNewLine class
2377
    
2471
    
2378
    /**
2472
    /**
2379
     * Cut text from the caret position to either begining or end
2473
     * Cut text from the caret position to either begining or end
(-)a/editor.lib/src/org/netbeans/editor/BaseDocument.java (-47 / +39 lines)
 Lines 100-106    Link Here 
100
import org.netbeans.modules.editor.lib.EditorPackageAccessor;
100
import org.netbeans.modules.editor.lib.EditorPackageAccessor;
101
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
101
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
102
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
102
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
103
import org.netbeans.modules.editor.lib.FormatterOverride;
104
import org.netbeans.modules.editor.lib.TrailingWhitespaceRemove;
103
import org.netbeans.modules.editor.lib.TrailingWhitespaceRemove;
105
import org.netbeans.modules.editor.lib.SettingsConversions;
104
import org.netbeans.modules.editor.lib.SettingsConversions;
106
import org.netbeans.modules.editor.lib.drawing.DrawEngine;
105
import org.netbeans.modules.editor.lib.drawing.DrawEngine;
 Lines 253-263    Link Here 
253
            new Integer(3)
252
            new Integer(3)
254
        };
253
        };
255
254
256
    /** Size of one indentation level. If this variable is null (value
257
     * is not set in Settings, then the default algorithm will be used.
258
     */
259
    private Integer shiftWidth;
260
261
    /** How many times current writer requested writing */
255
    /** How many times current writer requested writing */
262
    private int writeDepth;
256
    private int writeDepth;
263
257
 Lines 353-361    Link Here 
353
347
354
    private Position lastPositionEditedByTyping = null;
348
    private Position lastPositionEditedByTyping = null;
355
349
356
    /** Formatter being used. */
350
    /** Size of one indentation level. If this variable is null (value
357
    private Formatter formatter;
351
     * is not set in Settings, then the default algorithm will be used.
358
352
     */
353
    private int shiftWidth = -1;
359
    private int tabSize;
354
    private int tabSize;
360
355
361
    private Preferences prefs;
356
    private Preferences prefs;
 Lines 367-375    Link Here 
367
            }
362
            }
368
363
369
            if (key == null || SimpleValueNames.INDENT_SHIFT_WIDTH.equals(key)) {
364
            if (key == null || SimpleValueNames.INDENT_SHIFT_WIDTH.equals(key)) {
370
                int shw = prefs.getInt(SimpleValueNames.INDENT_SHIFT_WIDTH, -1);
365
                shiftWidth = prefs.getInt(SimpleValueNames.INDENT_SHIFT_WIDTH, -1);
371
                if (shw >= 0) {
366
            }
372
                    shiftWidth = shw;
367
368
            if (key == null || SimpleValueNames.SPACES_PER_TAB.equals(key)) {
369
                if (shiftWidth == -1) {
370
                    shiftWidth = prefs.getInt(SimpleValueNames.SPACES_PER_TAB, EditorPreferencesDefaults.defaultSpacesPerTab);
373
                }
371
                }
374
            }
372
            }
375
373
 Lines 457-465    Link Here 
457
                putProperty(EditorPreferencesKeys.PREVIOUS_WORD_FINDER, finder != null ? finder : new FinderFactory.PreviousWordBwdFinder(BaseDocument.this, stopOnEOL, false));
455
                putProperty(EditorPreferencesKeys.PREVIOUS_WORD_FINDER, finder != null ? finder : new FinderFactory.PreviousWordBwdFinder(BaseDocument.this, stopOnEOL, false));
458
            }
456
            }
459
457
460
            // Refresh formatter
461
            formatter = null;
462
463
            SettingsConversions.callSettingsChange(BaseDocument.this);
458
            SettingsConversions.callSettingsChange(BaseDocument.this);
464
        }
459
        }
465
    };
460
    };
 Lines 621-651    Link Here 
621
//        }
616
//        }
622
    }
617
    }
623
618
624
    /**
619
// XXX: formatting cleanup
625
     * @deprecated Please use Editor Indentation API instead, for details see
620
//    /**
626
     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
621
//     * @deprecated Please use Editor Indentation API instead, for details see
627
     */
622
//     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
628
    public Formatter getLegacyFormatter() {
623
//     */
629
        if (formatter == null) {
624
//    public Formatter getLegacyFormatter() {
630
            formatter = (Formatter) SettingsConversions.callFactory(prefs, MimePath.parse(mimeType), FORMATTER, null);
625
//        if (formatter == null) {
631
            if (formatter == null) {
626
//            formatter = (Formatter) SettingsConversions.callFactory(prefs, MimePath.parse(mimeType), FORMATTER, null);
632
                formatter = Formatter.getFormatter(mimeType);
627
//            if (formatter == null) {
633
            }
628
//                formatter = Formatter.getFormatter(mimeType);
634
        }
629
//            }
635
        return formatter;
630
//        }
636
    }
631
//        return formatter;
637
632
//    }
638
    /**
633
//
639
     * Gets the formatter for this document.
634
//    /**
640
     *
635
//     * Gets the formatter for this document.
641
     * @deprecated Please use Editor Indentation API instead, for details see
636
//     *
642
     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
637
//     * @deprecated Please use Editor Indentation API instead, for details see
643
     */
638
//     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
644
    public Formatter getFormatter() {
639
//     */
645
        Formatter f = getLegacyFormatter();
640
//    public Formatter getFormatter() {
646
        FormatterOverride fp = Lookup.getDefault().lookup(FormatterOverride.class);
641
//        Formatter f = getLegacyFormatter();
647
        return (fp != null) ? fp.getFormatter(this, f) : f;
642
//        FormatterOverride fp = Lookup.getDefault().lookup(FormatterOverride.class);
648
    }
643
//        return (fp != null) ? fp.getFormatter(this, f) : f;
644
//    }
649
645
650
    /**
646
    /**
651
     * @deprecated Please use Lexer instead, for details see
647
     * @deprecated Please use Lexer instead, for details see
 Lines 1570-1584    Link Here 
1570
     * setting. If so it uses it, otherwise it uses <code>formatter.getSpacesPerTab()</code>.
1566
     * setting. If so it uses it, otherwise it uses <code>formatter.getSpacesPerTab()</code>.
1571
     *
1567
     *
1572
     * @see getTabSize()
1568
     * @see getTabSize()
1573
     * @see Formatter.getSpacesPerTab()
1569
     * @deprecated Please use Editor Indentation API instead, for details see
1570
     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
1574
     */
1571
     */
1575
    public int getShiftWidth() {
1572
    public int getShiftWidth() {
1576
        if (shiftWidth != null) {
1573
        return shiftWidth;
1577
            return shiftWidth.intValue();
1578
1579
        } else {
1580
            return getFormatter().getSpacesPerTab();
1581
        }
1582
    }
1574
    }
1583
1575
1584
    /**
1576
    /**
(-)a/editor.lib/src/org/netbeans/editor/BaseKit.java (-242 / +603 lines)
 Lines 67-76    Link Here 
67
import javax.swing.text.ViewFactory;
67
import javax.swing.text.ViewFactory;
68
import javax.swing.text.Caret;
68
import javax.swing.text.Caret;
69
import javax.swing.text.JTextComponent;
69
import javax.swing.text.JTextComponent;
70
import java.io.CharArrayWriter;
71
import java.lang.reflect.Method;
70
import java.lang.reflect.Method;
72
import java.util.Set;
71
import java.util.Set;
73
import java.util.Vector;
74
import java.util.WeakHashMap;
72
import java.util.WeakHashMap;
75
import java.util.logging.Level;
73
import java.util.logging.Level;
76
import java.util.logging.Logger;
74
import java.util.logging.Logger;
 Lines 87-100    Link Here 
87
import org.netbeans.api.editor.mimelookup.MimeLookup;
85
import org.netbeans.api.editor.mimelookup.MimeLookup;
88
import org.netbeans.api.editor.mimelookup.MimePath;
86
import org.netbeans.api.editor.mimelookup.MimePath;
89
import org.netbeans.api.editor.settings.KeyBindingSettings;
87
import org.netbeans.api.editor.settings.KeyBindingSettings;
88
import org.netbeans.api.editor.settings.SimpleValueNames;
89
import org.netbeans.lib.editor.util.CharSequenceUtilities;
90
import org.netbeans.lib.editor.util.ListenerList;
90
import org.netbeans.lib.editor.util.ListenerList;
91
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
91
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
92
import org.netbeans.modules.editor.indent.api.Indent;
93
import org.netbeans.modules.editor.indent.api.IndentUtils;
94
import org.netbeans.modules.editor.indent.api.Reformat;
95
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
92
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
96
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
93
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
97
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
94
import org.netbeans.modules.editor.lib.KitsTracker;
98
import org.netbeans.modules.editor.lib.KitsTracker;
95
import org.netbeans.modules.editor.lib.NavigationHistory;
99
import org.netbeans.modules.editor.lib.NavigationHistory;
96
import org.netbeans.modules.editor.lib.SettingsConversions;
100
import org.netbeans.modules.editor.lib.SettingsConversions;
97
import org.netbeans.modules.editor.lib2.highlighting.HighlightingManager;
101
import org.netbeans.modules.editor.lib2.highlighting.HighlightingManager;
102
import org.netbeans.modules.editor.lib2.typinghooks.DeletedTextInterceptorsManager;
103
import org.netbeans.modules.editor.lib2.typinghooks.TypedBreakInterceptorsManager;
104
import org.netbeans.modules.editor.lib2.typinghooks.TypedTextInterceptorsManager;
98
import org.openide.awt.StatusDisplayer;
105
import org.openide.awt.StatusDisplayer;
99
import org.openide.util.HelpCtx;
106
import org.openide.util.HelpCtx;
100
import org.openide.util.Lookup;
107
import org.openide.util.Lookup;
 Lines 616-629    Link Here 
616
        return new SyntaxSupport(doc);
623
        return new SyntaxSupport(doc);
617
    }
624
    }
618
625
619
    /** 
626
// XXX: formatting cleanup
620
     * Create the formatter appropriate for this kit
627
//    /**
621
     * @deprecated Please use Editor Indentation API instead, for details see
628
//     * Create the formatter appropriate for this kit
622
     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
629
//     * @deprecated Please use Editor Indentation API instead, for details see
623
     */
630
//     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
624
    public Formatter createFormatter() {
631
//     */
625
        return new Formatter(this.getClass());
632
//    public Formatter createFormatter() {
626
    }
633
//        return new Formatter(this.getClass());
634
//    }
627
635
628
    /** Create text UI */
636
    /** Create text UI */
629
    protected BaseTextUI createTextUI() {
637
    protected BaseTextUI createTextUI() {
 Lines 1020-1030    Link Here 
1020
1028
1021
1029
1022
1030
1023
    /** Default typed action */
1031
    /** 
1032
     * Default typed action
1033
     *
1034
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
1035
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1036
     */
1024
//    @EditorActionRegistration(name = defaultKeyTypedAction)
1037
//    @EditorActionRegistration(name = defaultKeyTypedAction)
1025
    public static class DefaultKeyTypedAction extends LocalBaseAction {
1038
    public static class DefaultKeyTypedAction extends LocalBaseAction {
1026
1039
1027
        static final long serialVersionUID =3069164318144463899L;
1040
        static final long serialVersionUID = 3069164318144463899L;
1028
1041
1029
        public DefaultKeyTypedAction() {
1042
        public DefaultKeyTypedAction() {
1030
            // Construct with defaultKeyTypedAction name to retain full compatibility for extending actions
1043
            // Construct with defaultKeyTypedAction name to retain full compatibility for extending actions
 Lines 1033-1040    Link Here 
1033
            LOG.fine("DefaultKeyTypedAction with enhanced logging, see issue #145306"); //NOI18N
1046
            LOG.fine("DefaultKeyTypedAction with enhanced logging, see issue #145306"); //NOI18N
1034
        }
1047
        }
1035
1048
1036
        private static final boolean isMac = System.getProperty("mrj.version") != null; //NOI18N
1037
1038
        public void actionPerformed (final ActionEvent evt, final JTextComponent target) {
1049
        public void actionPerformed (final ActionEvent evt, final JTextComponent target) {
1039
            if ((target != null) && (evt != null)) {
1050
            if ((target != null) && (evt != null)) {
1040
1051
 Lines 1043-1049    Link Here 
1043
                boolean ctrl = ((mod & ActionEvent.CTRL_MASK) != 0);
1054
                boolean ctrl = ((mod & ActionEvent.CTRL_MASK) != 0);
1044
                // On the mac, norwegian and french keyboards use Alt to do bracket characters.
1055
                // On the mac, norwegian and french keyboards use Alt to do bracket characters.
1045
                // This replicates Apple's modification DefaultEditorKit.DefaultKeyTypedAction
1056
                // This replicates Apple's modification DefaultEditorKit.DefaultKeyTypedAction
1046
                boolean alt = isMac ? ((mod & ActionEvent.META_MASK) != 0) : 
1057
                boolean alt = org.openide.util.Utilities.isMac() ? ((mod & ActionEvent.META_MASK) != 0) :
1047
                    ((mod & ActionEvent.ALT_MASK) != 0);
1058
                    ((mod & ActionEvent.ALT_MASK) != 0);
1048
                
1059
                
1049
                
1060
                
 Lines 1057-1123    Link Here 
1057
                    return;
1068
                    return;
1058
                }
1069
                }
1059
1070
1060
                final Caret caret = target.getCaret();
1061
                final BaseDocument doc = (BaseDocument)target.getDocument();
1062
                final EditorUI editorUI = Utilities.getEditorUI(target);
1063
                // determine if typed char is valid
1071
                // determine if typed char is valid
1064
                final String cmd = evt.getActionCommand();
1072
                final String cmd = evt.getActionCommand();
1065
                if ((cmd != null) && (cmd.length() == 1)) {
1073
                if (cmd != null && cmd.length() == 1 && cmd.charAt(0) >= 0x20 && cmd.charAt(0) != 0x7F) {
1066
                    //          Utilities.clearStatusText(target);
1074
                    if (LOG.isLoggable(Level.FINE)) {
1075
                        LOG.log(Level.FINE, "Processing command char: {0}", Integer.toHexString(cmd.charAt(0))); //NOI18N
1076
                    }
1067
1077
1078
                    final BaseDocument doc = (BaseDocument)target.getDocument();
1079
                    final int insertionOffset = computeInsertionOffset(target.getCaret());
1080
                    final TypedTextInterceptorsManager.Transaction transaction = TypedTextInterceptorsManager.getInstance().openTransaction(
1081
                            target, insertionOffset, cmd);
1082
                    
1068
                    try {
1083
                    try {
1069
                        NavigationHistory.getEdits().markWaypoint(target, caret.getDot(), false, true);
1084
                        if (!transaction.beforeInsertion()) {
1070
                    } catch (BadLocationException e) {
1085
                            final Object [] result = new Object [] { Boolean.FALSE, "" }; //NOI18N
1071
                        LOG.log(Level.WARNING, "Can't add position to the history of edits.", e); //NOI18N
1086
                            doc.runAtomicAsUser (new Runnable () {
1072
                    }
1087
                                public void run () {
1073
                    
1088
                                    Object [] r = transaction.textTyped();
1074
                    doc.runAtomicAsUser (new Runnable () {
1089
                                    String insertionText = r == null ? cmd : (String) r[0];
1075
                        public void run () {
1090
                                    int caretPosition = r == null ? -1 : (Integer) r[1];
1076
                            DocumentUtilities.setTypingModification(doc, true);
1091
                                    
1077
                            try {
1078
                                char ch = cmd.charAt(0);
1079
                                if ((ch >= 0x20) && (ch != 0x7F)) { // valid character
1080
                                    LOG.fine("Processing command char: " + Integer.toHexString(ch)); //NOI18N
1081
1082
                                    editorUI.getWordMatch().clear(); // reset word matching
1083
                                    Boolean overwriteMode = (Boolean)editorUI.getProperty(
1084
                                                                EditorUI.OVERWRITE_MODE_PROPERTY);
1085
                                    try {
1092
                                    try {
1086
                                        boolean doInsert = true; // editorUI.getAbbrev().checkAndExpand(ch, evt);
1093
                                        performTextInsertion(target, insertionOffset, insertionText, caretPosition);
1087
                                        if (doInsert) {
1094
                                        result[0] = Boolean.TRUE;
1088
                                            if (Utilities.isSelectionShowing(caret)) { // valid selection
1095
                                        result[1] = insertionText;
1089
                                                boolean ovr = (overwriteMode != null && overwriteMode.booleanValue());
1096
                                    } catch (BadLocationException ble) {
1090
                                                try {
1097
                                        LOG.log(Level.FINE, null, ble);
1091
                                                    doc.putProperty(DOC_REPLACE_SELECTION_PROPERTY, true);
1092
                                                    replaceSelection(target, caret.getDot(), caret, cmd, ovr);
1093
                                                } finally {
1094
                                                    doc.putProperty(DOC_REPLACE_SELECTION_PROPERTY, null);
1095
                                                }
1096
                                            } else { // no selection
1097
                                                int dotPos = caret.getDot();
1098
                                                if (overwriteMode != null && overwriteMode.booleanValue()
1099
                                                        && dotPos < doc.getLength() && doc.getChars(dotPos, 1)[0] != '\n'
1100
                                                   ) { // overwrite current char
1101
                                                    insertString(doc, dotPos, caret, cmd, true); 
1102
                                                } else { // insert mode
1103
                                                    insertString(doc, dotPos, caret, cmd, false);
1104
                                                }
1105
                                            }
1106
                                        }
1107
                                    } catch (BadLocationException e) {
1108
                                        LOG.log(Level.FINE, null, e);
1109
                                        target.getToolkit().beep();
1098
                                        target.getToolkit().beep();
1110
                                    }
1099
                                    }
1111
                                } else {
1112
                                    LOG.fine("Invalid command char: " + Integer.toHexString(ch)); //NOI18N
1113
                                }
1100
                                }
1101
                            });
1102
                            
1103
                            if (((Boolean)result[0]).booleanValue()) {
1104
                                transaction.afterInsertion();
1114
1105
1115
                                checkIndent(target, cmd);
1106
                                // XXX: this is potentially wrong and we may need to call this with
1116
                            } finally {
1107
                                // the original cmd; or maybe only if insertionText == cmd; but maybe
1117
                                DocumentUtilities.setTypingModification(doc, false);
1108
                                // it does not matter, because nobody seems to be overwriting this method anyway
1118
                            }
1109
                                checkIndent(target, (String)result[1]);
1110
                            } // else text insertion failed
1119
                        }
1111
                        }
1120
                    });
1112
                    } finally {
1113
                        transaction.close();
1114
                    }
1121
                } else {
1115
                } else {
1122
                    if (LOG.isLoggable(Level.FINE)) {
1116
                    if (LOG.isLoggable(Level.FINE)) {
1123
                        StringBuilder sb = new StringBuilder();
1117
                        StringBuilder sb = new StringBuilder();
 Lines 1128-1181    Link Here 
1128
                                sb.append(" ");
1122
                                sb.append(" ");
1129
                            }
1123
                            }
1130
                        }
1124
                        }
1131
                        LOG.fine("Invalid command: '" + sb + "'"); //NOI18N
1125
                        LOG.log(Level.FINE, "Invalid command: {0}", sb); //NOI18N
1132
                    }                    
1126
                    }                    
1133
                }
1127
                }
1134
            }
1128
            }
1135
        }
1129
        }
1136
1130
1137
      /** 
1131
        // --------------------------------------------------------------------
1138
       * Hook to insert the given string at the given position into
1132
        // SPI
1139
       * the given document in insert-mode, no selection, writeable
1133
        // --------------------------------------------------------------------
1140
       * document. Designed to be overridden by subclasses that want
1134
1141
       * to intercept inserted characters.
1135
        /**
1142
       */
1136
         * Hook to insert the given string at the given position into
1143
      protected void insertString(BaseDocument doc,  
1137
         * the given document in insert-mode, no selection, writeable
1138
         * document. Designed to be overridden by subclasses that want
1139
         * to intercept inserted characters.
1140
         *
1141
         * @deprecated Please use Typing Hooks instead, for details see
1142
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1143
         */
1144
        protected void insertString(BaseDocument doc,
1144
				  int dotPos, 
1145
				  int dotPos, 
1145
				  Caret caret,
1146
				  Caret caret,
1146
				  String str, 
1147
				  String str, 
1147
				  boolean overwrite) 
1148
				  boolean overwrite) throws BadLocationException 
1148
	throws BadLocationException 
1149
        {
1149
      {
1150
            if (overwrite) {
1150
	if (overwrite) doc.remove(dotPos, 1);
1151
                doc.remove(dotPos, 1);
1151
	doc.insertString(dotPos, str, null);
1152
            }
1152
      }
1153
            
1154
            doc.insertString(dotPos, str, null);
1155
        }
1153
1156
1154
      /** 
1157
        /**
1155
       * Hook to insert the given string at the given position into
1158
         * Hook to insert the given string at the given position into
1156
       * the given document in insert-mode with selection visible
1159
         * the given document in insert-mode with selection visible
1157
       * Designed to be overridden by subclasses that want
1160
         * Designed to be overridden by subclasses that want
1158
       * to intercept inserted characters.
1161
         * to intercept inserted characters.
1159
       */
1162
         *
1160
      protected void replaceSelection(JTextComponent target,  
1163
         * @deprecated Please use Typing Hooks instead, for details see
1161
				  int dotPos, 
1164
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1162
				  Caret caret,
1165
         */
1163
				  String str, 
1166
        protected void replaceSelection(
1164
				  boolean overwrite) 
1167
                JTextComponent target,
1165
	throws BadLocationException 
1168
                int dotPos,
1166
      {
1169
                Caret caret,
1167
          target.replaceSelection(str);
1170
                String str,
1168
      }
1171
                boolean overwrite) throws BadLocationException
1172
        {
1173
            target.replaceSelection(str);
1174
        }
1169
1175
1170
1176
        /**
1171
        /** Check whether there was any important character typed
1177
         * Check whether there was any important character typed
1172
        * so that the line should be possibly reformatted.
1178
         * so that the line should be possibly reformatted.
1173
        */
1179
         *
1180
         * @deprecated Please use <a href="@org-netbeans-modules-editor-indent@/org/netbeans/modules/editor/indent/spi/AutomatedIndenting.html">AutomatedIndentig</a>
1181
         *   or Typing Hooks instead, for details see
1182
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1183
         */
1174
        protected void checkIndent(JTextComponent target, String typedText) {
1184
        protected void checkIndent(JTextComponent target, String typedText) {
1175
        }
1185
        }
1176
1186
1177
    }
1187
        // --------------------------------------------------------------------
1188
        // Private implementation
1189
        // --------------------------------------------------------------------
1178
1190
1191
        private void performTextInsertion(JTextComponent target, int insertionOffset, String insertionText, int caretPosition) throws BadLocationException {
1192
            final BaseDocument doc = (BaseDocument)target.getDocument();
1193
            
1194
            try {
1195
                NavigationHistory.getEdits().markWaypoint(target, insertionOffset, false, true);
1196
            } catch (BadLocationException e) {
1197
                LOG.log(Level.WARNING, "Can't add position to the history of edits.", e); //NOI18N
1198
            }
1199
1200
            DocumentUtilities.setTypingModification(doc, true);
1201
            try {
1202
                EditorUI editorUI = Utilities.getEditorUI(target);
1203
                Caret caret = target.getCaret();
1204
1205
                editorUI.getWordMatch().clear(); // reset word matching
1206
                Boolean overwriteMode = (Boolean)editorUI.getProperty(EditorUI.OVERWRITE_MODE_PROPERTY);
1207
                boolean ovr = (overwriteMode != null && overwriteMode.booleanValue());
1208
                if (Utilities.isSelectionShowing(caret)) { // valid selection
1209
                    try {
1210
                        doc.putProperty(DOC_REPLACE_SELECTION_PROPERTY, true);
1211
                        replaceSelection(target, insertionOffset, caret, insertionText, ovr);
1212
                    } finally {
1213
                        doc.putProperty(DOC_REPLACE_SELECTION_PROPERTY, null);
1214
                    }
1215
                } else { // no selection
1216
                    if (ovr && insertionOffset < doc.getLength() && doc.getChars(insertionOffset, 1)[0] != '\n') { //NOI18N
1217
                        // overwrite current char
1218
                        insertString(doc, insertionOffset, caret, insertionText, true);
1219
                    } else { // insert mode
1220
                        insertString(doc, insertionOffset, caret, insertionText, false);
1221
                    }
1222
                }
1223
1224
                if (caretPosition != -1) {
1225
                    assert caretPosition >= 0 && caretPosition < insertionText.length();
1226
                    caret.setDot(insertionOffset + caretPosition);
1227
                }
1228
            } finally {
1229
                DocumentUtilities.setTypingModification(doc, false);
1230
            }
1231
        }
1232
1233
        private int computeInsertionOffset(Caret caret) {
1234
            if (Utilities.isSelectionShowing(caret)) {
1235
                return Math.min(caret.getMark(), caret.getDot());
1236
            } else {
1237
                return caret.getDot();
1238
            }
1239
        }
1240
    } // End of DefaultKeyTypedAction class
1241
1242
    /** 
1243
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
1244
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1245
     */
1179
    public static class InsertBreakAction extends LocalBaseAction {
1246
    public static class InsertBreakAction extends LocalBaseAction {
1180
1247
1181
        static final long serialVersionUID =7966576342334158659L;
1248
        static final long serialVersionUID =7966576342334158659L;
 Lines 1192-1242    Link Here 
1192
                }
1259
                }
1193
1260
1194
                final BaseDocument doc = (BaseDocument)target.getDocument();
1261
                final BaseDocument doc = (BaseDocument)target.getDocument();
1195
                final Formatter formatter = doc.getFormatter();
1262
                final int insertionOffset = computeInsertionOffset(target.getCaret());
1196
                formatter.indentLock();
1263
                final TypedBreakInterceptorsManager.Transaction transaction = TypedBreakInterceptorsManager.getInstance().openTransaction(
1264
                        target, insertionOffset, insertionOffset);
1265
                
1197
                try {
1266
                try {
1198
                    doc.runAtomicAsUser (new Runnable () {
1267
                    if (!transaction.beforeInsertion()) {
1199
                        public void run () {
1268
                        final Boolean [] result = new Boolean [] { Boolean.FALSE }; //NOI18N
1200
                            DocumentUtilities.setTypingModification(doc, true);
1269
                        final Indent indenter = Indent.get(doc);
1201
                            try {
1270
                        indenter.lock();
1202
                                target.replaceSelection("");
1271
                        try {
1203
                                Caret caret = target.getCaret();
1272
                            doc.runAtomicAsUser (new Runnable () {
1204
                                Object cookie = beforeBreak(target, doc, caret);
1273
                                public void run () {
1274
                                    Object [] r = transaction.textTyped();
1275
                                    String insertionText = r == null ? "\n" : (String) r[0]; //NOI18N
1276
                                    int breakInsertPosition = r == null ? -1 : (Integer) r[1];
1277
                                    int caretPosition = r == null ? -1 : (Integer) r[2];
1278
                                    int [] reindentBlocks = r == null ? null : (int []) r[3];
1205
1279
1206
                                int dotPos = caret.getDot();
1280
                                    try {
1207
                                int newDotPos = formatter.indentNewLine(doc, dotPos);
1281
                                        performLineBreakInsertion(target, insertionOffset, insertionText, breakInsertPosition, caretPosition, reindentBlocks, indenter);
1208
                                caret.setDot(newDotPos);
1282
                                        result[0] = Boolean.TRUE;
1209
1283
                                    } catch (BadLocationException ble) {
1210
                                afterBreak(target, doc, caret, cookie);
1284
                                        LOG.log(Level.FINE, null, ble);
1211
                            } finally {
1285
                                        target.getToolkit().beep();
1212
                                DocumentUtilities.setTypingModification(doc, false);
1286
                                    }
1213
                            }
1287
                                }
1288
                            });
1289
                        } finally {
1290
                            indenter.unlock();
1214
                        }
1291
                        }
1215
                    });
1292
                        
1293
                        if (result[0].booleanValue()) {
1294
                            transaction.afterInsertion();
1295
                        } // else line-break insertion failed
1296
                        
1297
                    }
1216
                } finally {
1298
                } finally {
1217
                    formatter.indentUnlock();
1299
                    transaction.close();
1218
                }
1300
                }
1301
                
1219
            }
1302
            }
1220
        }
1303
        }
1221
1304
1222
      /**
1305
        // --------------------------------------------------------------------
1223
       * Hook called before any changes to the document. The value
1306
        // SPI
1224
       * returned is passed intact to the other hook.
1307
        // --------------------------------------------------------------------
1225
       */
1226
      protected Object beforeBreak(JTextComponent target, BaseDocument doc, Caret caret) { 
1227
	return null;
1228
      }
1229
1308
1230
      /**
1309
        /**
1231
       * Hook called after the enter was inserted and cursor
1310
         * Hook called before any changes to the document. The value
1232
       * repositioned. *data* is the object returned previously by
1311
         * returned is passed intact to the other hook.
1233
       * *beforeBreak* hook. By default null.
1312
         * 
1234
       */
1313
         * @deprecated Please use Typing Hooks instead, for details see
1235
      protected void afterBreak(JTextComponent target, BaseDocument doc, Caret caret, Object data) {
1314
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1236
      }
1315
         */
1237
    }
1316
        protected Object beforeBreak(JTextComponent target, BaseDocument doc, Caret caret) {
1317
            return null;
1318
        }
1238
1319
1239
    @EditorActionRegistration(name = splitLineAction)
1320
        /**
1321
         * Hook called after the enter was inserted and cursor
1322
         * repositioned.
1323
         *
1324
         * @param data the object returned from previously called 
1325
         * {@link #beforeBreak(javax.swing.text.JTextComponent, org.netbeans.editor.BaseDocument, javax.swing.text.Caret)} hook.
1326
         * By default <code>null</code>.
1327
         * 
1328
         * @deprecated Please use Typing Hooks instead, for details see
1329
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1330
         */
1331
        protected void afterBreak(JTextComponent target, BaseDocument doc, Caret caret, Object data) {
1332
        }
1333
        
1334
        // --------------------------------------------------------------------
1335
        // Private implementation
1336
        // --------------------------------------------------------------------
1337
1338
        private void performLineBreakInsertion(
1339
                JTextComponent target, 
1340
                int insertionOffset, 
1341
                String insertionText, 
1342
                int breakInsertPosition, 
1343
                int caretPosition, 
1344
                int [] reindentBlocks,
1345
                Indent indenter) throws BadLocationException
1346
        {
1347
            BaseDocument doc = (BaseDocument) target.getDocument();
1348
            DocumentUtilities.setTypingModification(doc, true);
1349
            try {
1350
                target.replaceSelection(""); // NOI18N
1351
                Caret caret = target.getCaret();
1352
                Object cookie = beforeBreak(target, doc, caret);
1353
1354
                // insert new line, caret moves to the new line
1355
                int dotPos = caret.getDot();
1356
                assert dotPos == insertionOffset : "dotPos=" + dotPos + " != " + "insertionOffset=" + insertionOffset; //NOI18N
1357
//                doc.insertString(dotPos, "\n", null); //NOI18N
1358
//                dotPos++;
1359
                doc.insertString(dotPos, insertionText, null);
1360
                dotPos += caretPosition != -1 ? caretPosition :
1361
                          breakInsertPosition != -1 ? breakInsertPosition + 1 :
1362
                          insertionText.indexOf('\n') + 1; //NOI18N
1363
1364
                // reindent the new line
1365
                Position newDotPos = doc.createPosition(dotPos);
1366
                if (reindentBlocks != null && reindentBlocks.length > 0) {
1367
                    for(int i = 0; i < reindentBlocks.length / 2; i++) {
1368
                        int startOffset = insertionOffset + reindentBlocks[2 * i];
1369
                        int endOffset = insertionOffset + reindentBlocks[2 * i + 1];
1370
                        indenter.reindent(startOffset, endOffset);
1371
                    }
1372
                } else {
1373
                    indenter.reindent(dotPos);
1374
                }
1375
1376
                // adjust the caret
1377
                caret.setDot(newDotPos.getOffset());
1378
1379
                afterBreak(target, doc, caret, cookie);
1380
            } finally {
1381
                DocumentUtilities.setTypingModification(doc, false);
1382
            }
1383
        }
1384
        
1385
        private int computeInsertionOffset(Caret caret) {
1386
            if (Utilities.isSelectionShowing(caret)) {
1387
                return Math.min(caret.getMark(), caret.getDot());
1388
            } else {
1389
                return caret.getDot();
1390
            }
1391
        }
1392
        
1393
    } // End of InsertBreakAction class
1394
1395
    @EditorActionRegistration(name = splitLineAction)    
1240
    public static class SplitLineAction extends LocalBaseAction {
1396
    public static class SplitLineAction extends LocalBaseAction {
1241
1397
1242
        static final long serialVersionUID =7966576342334158659L;
1398
        static final long serialVersionUID =7966576342334158659L;
 Lines 1255-1278    Link Here 
1255
                final BaseDocument doc = (BaseDocument)target.getDocument();
1411
                final BaseDocument doc = (BaseDocument)target.getDocument();
1256
                final Caret caret = target.getCaret();
1412
                final Caret caret = target.getCaret();
1257
1413
1258
                final Formatter formatter = doc.getFormatter();
1414
                final Indent formatter = Indent.get(doc);
1259
                formatter.indentLock();
1415
                formatter.lock();
1260
                try {
1416
                try {
1261
                    doc.runAtomicAsUser (new Runnable () {
1417
                    doc.runAtomicAsUser (new Runnable () {
1262
                        public void run () {
1418
                        public void run () {
1263
                            DocumentUtilities.setTypingModification(doc, true);
1419
                            DocumentUtilities.setTypingModification(doc, true);
1264
                            try{
1420
                            try{
1265
                                target.replaceSelection("");
1421
                                target.replaceSelection(""); //NOI18N
1266
                                final int dotPos = caret.getDot();      // dot stays where it was
1422
1267
                                formatter.indentNewLine(doc, dotPos);   // newline
1423
                                // insert new line, caret stays where it is
1424
                                int dotPos = caret.getDot();
1425
                                doc.insertString(dotPos, "\n", null); //NOI18N
1426
1427
                                // reindent the new line
1428
                                formatter.reindent(dotPos + 1);   // newline
1429
1430
                                // make sure the caret stays on its original position
1268
                                caret.setDot(dotPos);
1431
                                caret.setDot(dotPos);
1432
                            } catch (BadLocationException ble) {
1433
                                LOG.log(Level.WARNING, null, ble);
1269
                            } finally {
1434
                            } finally {
1270
                                DocumentUtilities.setTypingModification(doc, false);
1435
                                DocumentUtilities.setTypingModification(doc, false);
1271
                            }
1436
                            }
1272
                        }
1437
                        }
1273
                    });
1438
                    });
1274
                } finally {
1439
                } finally {
1275
                    formatter.indentUnlock();
1440
                    formatter.unlock();
1276
                }
1441
                }
1277
            }
1442
            }
1278
        }
1443
        }
 Lines 1300-1311    Link Here 
1300
                doc.runAtomicAsUser (new Runnable () {
1465
                doc.runAtomicAsUser (new Runnable () {
1301
                    public void run () {
1466
                    public void run () {
1302
                        DocumentUtilities.setTypingModification(doc, true);
1467
                        DocumentUtilities.setTypingModification(doc, true);
1303
                        Formatter.pushFormattingContextDocument(doc);
1304
                        try {
1468
                        try {
1305
                        if (Utilities.isSelectionShowing(caret)) { // block selected
1469
                        if (Utilities.isSelectionShowing(caret)) { // block selected
1306
                            try {
1470
                            try {
1307
                                doc.getFormatter().changeBlockIndent(doc,
1471
                                changeBlockIndent(doc, target.getSelectionStart(), target.getSelectionEnd(), +1);
1308
                                        target.getSelectionStart(), target.getSelectionEnd(), +1);
1309
                            } catch (GuardedException e) {
1472
                            } catch (GuardedException e) {
1310
                                target.getToolkit().beep();
1473
                                target.getToolkit().beep();
1311
                            } catch (BadLocationException e) {
1474
                            } catch (BadLocationException e) {
 Lines 1341-1347    Link Here 
1341
                                    // Fix of #32240 - #1 of 2
1504
                                    // Fix of #32240 - #1 of 2
1342
                                    int rowStart = Utilities.getRowStart(doc, dotPos);
1505
                                    int rowStart = Utilities.getRowStart(doc, dotPos);
1343
1506
1344
                                    doc.getFormatter().changeRowIndent(doc, dotPos, indent);
1507
                                    changeRowIndent(doc, dotPos, indent);
1345
1508
1346
                                    // Fix of #32240 - #2 of 2
1509
                                    // Fix of #32240 - #2 of 2
1347
                                    int newDotPos = doc.getOffsetFromVisCol(indent, rowStart);
1510
                                    int newDotPos = doc.getOffsetFromVisCol(indent, rowStart);
 Lines 1350-1356    Link Here 
1350
                                    }
1513
                                    }
1351
1514
1352
                                } else { // already chars on the line
1515
                                } else { // already chars on the line
1353
                                    doc.getFormatter().insertTabString(doc, dotPos);
1516
                                    insertTabString(doc, dotPos);
1354
1517
1355
                                }
1518
                                }
1356
                            } catch (BadLocationException e) {
1519
                            } catch (BadLocationException e) {
 Lines 1358-1364    Link Here 
1358
                            }
1521
                            }
1359
                        }
1522
                        }
1360
                        } finally {
1523
                        } finally {
1361
                            Formatter.popFormattingContextDocument(doc);
1362
                            DocumentUtilities.setTypingModification(doc, false);
1524
                            DocumentUtilities.setTypingModification(doc, false);
1363
                        }
1525
                        }
1364
                    }
1526
                    }
 Lines 1507-1513    Link Here 
1507
        }
1669
        }
1508
    }
1670
    }
1509
1671
1510
    /** Remove previous or next character */
1672
    /** 
1673
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
1674
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1675
     */
1511
    public static class DeleteCharAction extends LocalBaseAction {
1676
    public static class DeleteCharAction extends LocalBaseAction {
1512
1677
1513
        protected boolean nextChar;
1678
        protected boolean nextChar;
 Lines 1531-1574    Link Here 
1531
		final int dot = caret.getDot();
1696
		final int dot = caret.getDot();
1532
		final int mark = caret.getMark();
1697
		final int mark = caret.getMark();
1533
1698
1534
                doc.runAtomicAsUser (new Runnable () {
1699
                if (dot != mark) {
1535
                    public void run () {
1700
                    // remove selection
1536
                    DocumentUtilities.setTypingModification(doc, true);
1701
                    doc.runAtomicAsUser (new Runnable () {
1537
1702
                        public void run () {
1538
                    try {
1703
                            DocumentUtilities.setTypingModification(doc, true);
1539
                        if (dot != mark) { // remove selection
1704
                            try {
1540
                            doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
1705
                                doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
1541
                        } else {
1706
                            } catch (BadLocationException e) {
1542
                            if (nextChar) { // remove next char
1707
                                target.getToolkit().beep();
1543
                                char ch = doc.getChars(dot, 1)[0];
1708
                            } finally {
1544
                                doc.remove(dot, 1);
1709
                                DocumentUtilities.setTypingModification(doc, false);
1545
                                charDeleted(doc, dot, caret, ch);
1546
                            } else { // remove previous char
1547
                                char ch = doc.getChars(dot-1, 1)[0];
1548
                                doc.remove(dot - 1, 1);
1549
                                charBackspaced(doc, dot-1, caret, ch);
1550
                            }
1710
                            }
1551
                        }
1711
                        }
1552
                    } catch (BadLocationException e) {
1712
                    });
1713
                } else {
1714
                    char [] removedChar = null;
1715
                    
1716
                    try {
1717
                        removedChar = nextChar ? 
1718
                        dot < doc.getLength() - 1 ? doc.getChars(dot, 1) : null : 
1719
                        dot > 0 ? doc.getChars(dot - 1, 1) : null;
1720
                    } catch (BadLocationException ble) {
1553
                        target.getToolkit().beep();
1721
                        target.getToolkit().beep();
1554
                    } finally {
1555
                        DocumentUtilities.setTypingModification(doc, false);
1556
                    }
1722
                    }
1723
                    
1724
                    if (removedChar != null) {
1725
                        final String removedText = String.valueOf(removedChar);
1726
                        final DeletedTextInterceptorsManager.Transaction t = DeletedTextInterceptorsManager.getInstance().openTransaction(target, dot, removedText, !nextChar);
1727
                        try {
1728
                            if (!t.beforeRemove()) {
1729
                                final boolean [] result = new boolean [] { false };
1730
                                doc.runAtomicAsUser (new Runnable () {
1731
                                    public void run () {
1732
                                        DocumentUtilities.setTypingModification(doc, true);
1733
                                        try {
1734
                                            if (nextChar) { // remove next char
1735
                                                doc.remove(dot, 1);
1736
                                            } else { // remove previous char
1737
                                                doc.remove(dot - 1, 1);
1738
                                            }
1739
1740
                                            t.textDeleted();
1741
1742
                                            if (nextChar) {
1743
                                                charDeleted(doc, dot, caret, removedText.charAt(0));
1744
                                            } else {
1745
                                                charBackspaced(doc, dot - 1, caret, removedText.charAt(0));
1746
                                            }
1747
1748
                                            result[0] = true;
1749
                                        } catch (BadLocationException e) {
1750
                                            target.getToolkit().beep();
1751
                                        } finally {
1752
                                            DocumentUtilities.setTypingModification(doc, false);
1753
                                        }
1754
                                    }
1755
                                });
1756
1757
                                if (result[0]) {
1758
                                    t.afterRemove();
1759
                                }
1760
                            }
1761
                        } finally {
1762
                            t.close();
1763
                        }
1557
                    }
1764
                    }
1558
                });
1765
                }
1559
            }
1766
            }
1560
        }
1767
        }
1561
1768
1562
      protected void charBackspaced(BaseDocument doc, int dotPos, Caret caret, char ch) 
1769
        /**
1563
	throws BadLocationException
1770
         * @deprecated Please use Typing Hooks instead, for details see
1564
      {
1771
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1565
      }
1772
         */
1566
      
1773
        protected void charBackspaced(BaseDocument doc, int dotPos, Caret caret, char ch) throws BadLocationException {
1567
      protected void charDeleted(BaseDocument doc, int dotPos, Caret caret, char ch) 
1774
        }
1568
	throws BadLocationException
1775
1569
      {
1776
        /**
1570
      }
1777
         * @deprecated Please use Typing Hooks instead, for details see
1571
    }
1778
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1779
         */
1780
        protected void charDeleted(BaseDocument doc, int dotPos, Caret caret, char ch) throws BadLocationException {
1781
        }
1782
    } // End of DeleteCharAction class
1572
1783
1573
    /**
1784
    /**
1574
     * @deprecated this action is no longer used. It is reimplemented in editor.actions module.
1785
     * @deprecated this action is no longer used. It is reimplemented in editor.actions module.
 Lines 1734-1743    Link Here 
1734
                    LOG.log(Level.WARNING, "Can't add position to the history of edits.", e); //NOI18N
1945
                    LOG.log(Level.WARNING, "Can't add position to the history of edits.", e); //NOI18N
1735
                }
1946
                }
1736
1947
1737
                final Formatter formatter = doc.getFormatter();
1948
                final Reformat formatter = Reformat.get(doc);
1738
                final boolean formatted = pasteFormatedAction.equals(getValue(Action.NAME));
1949
                final boolean formatted = pasteFormatedAction.equals(getValue(Action.NAME));
1739
                if (formatted) {
1950
                if (formatted) {
1740
                    formatter.reformatLock();
1951
                    formatter.lock();
1741
                }
1952
                }
1742
                try {
1953
                try {
1743
                    doc.runAtomicAsUser (new Runnable () {
1954
                    doc.runAtomicAsUser (new Runnable () {
 Lines 1758-1764    Link Here 
1758
                            }
1969
                            }
1759
                            int endOffset = caret.getDot();
1970
                            int endOffset = caret.getDot();
1760
                            if (formatted) {
1971
                            if (formatted) {
1761
                                formatter.reformat(doc, startOffset, endOffset);
1972
                                formatter.reformat(startOffset, endOffset);
1762
                            }
1973
                            }
1763
                        } catch (Exception e) {
1974
                        } catch (Exception e) {
1764
                            target.getToolkit().beep();
1975
                            target.getToolkit().beep();
 Lines 1769-1840    Link Here 
1769
                    });
1980
                    });
1770
                } finally {
1981
                } finally {
1771
                    if (formatted) {
1982
                    if (formatted) {
1772
                        formatter.reformatUnlock();
1983
                        formatter.unlock();
1773
                    }
1984
                    }
1774
                }
1985
                }
1775
            }
1986
            }
1776
        }
1987
        }
1777
1988
1778
      public static void indentBlock(BaseDocument doc, int startOffset, int endOffset)
1989
//      public static void indentBlock(BaseDocument doc, int startOffset, int endOffset)
1779
	throws BadLocationException
1990
//	throws BadLocationException
1780
      {
1991
//      {
1781
	char [] text = doc.getChars(startOffset, endOffset-startOffset);
1992
//	char [] text = doc.getChars(startOffset, endOffset-startOffset);
1782
	String [] lines = toLines(new String(text));
1993
//	String [] lines = toLines(new String(text));
1783
1994
//
1784
	doc.remove(startOffset, endOffset - startOffset);
1995
//	doc.remove(startOffset, endOffset - startOffset);
1785
	//	System.out.println("Lines:\n"); // NOI18N
1996
//	//	System.out.println("Lines:\n"); // NOI18N
1786
	//	for (int j = 0 ; j < lines.length; j++) System.out.println(lines[j] + "<"); // NOI18N
1997
//	//	for (int j = 0 ; j < lines.length; j++) System.out.println(lines[j] + "<"); // NOI18N
1787
1998
//
1788
	int offset = startOffset;
1999
//	int offset = startOffset;
1789
	// handle the full lines
2000
//	// handle the full lines
1790
	for (int i = 0; i < lines.length - 1; i++) {
2001
//	for (int i = 0; i < lines.length - 1; i++) {
1791
	  String indent = getIndentString(doc, offset, lines[i]);
2002
//	  String indent = getIndentString(doc, offset, lines[i]);
1792
	  String fragment = indent + lines[i].trim() + '\n';
2003
//	  String fragment = indent + lines[i].trim() + '\n';
1793
	  //	  System.out.println(fragment + "|"); // NOI18N
2004
//	  //	  System.out.println(fragment + "|"); // NOI18N
1794
	  doc.insertString(offset, fragment, null);
2005
//	  doc.insertString(offset, fragment, null);
1795
	  offset += fragment.length();
2006
//	  offset += fragment.length();
1796
	}
2007
//	}
1797
2008
//
1798
	// the rest just paste without indenting
2009
//	// the rest just paste without indenting
1799
	doc.insertString(offset, lines[lines.length-1], null);
2010
//	doc.insertString(offset, lines[lines.length-1], null);
1800
2011
//
1801
      }
2012
//      }
1802
2013
//
1803
      /** Break string to lines */
2014
//      /** Break string to lines */
1804
      private static String [] toLines(String str) {
2015
//      private static String [] toLines(String str) {
1805
	Vector v = new Vector();
2016
//	Vector v = new Vector();
1806
	int p=0 , p0=0;
2017
//	int p=0 , p0=0;
1807
	for (; p < str.length() ; p++) {
2018
//	for (; p < str.length() ; p++) {
1808
	  if (str.charAt(p) == '\n') {
2019
//	  if (str.charAt(p) == '\n') {
1809
	    v.add(str.substring(p0, p+1));
2020
//	    v.add(str.substring(p0, p+1));
1810
	    p0 = p+1;
2021
//	    p0 = p+1;
1811
	  }
2022
//	  }
1812
	}
2023
//	}
1813
	if (p0 < str.length()) v.add(str.substring(p0, str.length())); else v.add("");
2024
//	if (p0 < str.length()) v.add(str.substring(p0, str.length())); else v.add("");
1814
2025
//
1815
	return (String [])v.toArray(new String [0]);
2026
//	return (String [])v.toArray(new String [0]);
1816
      }
2027
//      }
1817
2028
//
1818
      private static String getIndentString(BaseDocument doc, int startOffset, String str) {
2029
//      private static String getIndentString(BaseDocument doc, int startOffset, String str) {
1819
	try {
2030
//	try {
1820
	  Formatter f = doc.getFormatter();
2031
//	  Formatter f = doc.getFormatter();
1821
	  CharArrayWriter cw = new CharArrayWriter();
2032
//	  CharArrayWriter cw = new CharArrayWriter();
1822
	  Writer w = f.createWriter(doc, startOffset, cw);
2033
//	  Writer w = f.createWriter(doc, startOffset, cw);
1823
	  w.write(str, 0, str.length());
2034
//	  w.write(str, 0, str.length());
1824
	  w.close();
2035
//	  w.close();
1825
	  String out = new String(cw.toCharArray());
2036
//	  String out = new String(cw.toCharArray());
1826
	  int i = 0;
2037
//	  int i = 0;
1827
	  for (; i < out.length(); i++) {
2038
//	  for (; i < out.length(); i++) {
1828
	    if (out.charAt(i) != ' ' && out.charAt(i) != '\t') break;
2039
//	    if (out.charAt(i) != ' ' && out.charAt(i) != '\t') break;
1829
	  }
2040
//	  }
1830
	  //	  System.out.println(out+"|"); // NOI18N
2041
//	  //	  System.out.println(out+"|"); // NOI18N
1831
	  //	  System.out.println(out.substring(0,i)+"^"); // NOI18N
2042
//	  //	  System.out.println(out.substring(0,i)+"^"); // NOI18N
1832
2043
//
1833
	  return out.substring(0, i);
2044
//	  return out.substring(0, i);
1834
	} catch (java.io.IOException e) {
2045
//	} catch (java.io.IOException e) {
1835
	  return "";
2046
//	  return "";
1836
	}
2047
//	}
1837
      }
2048
//      }
1838
    }
2049
    }
1839
2050
1840
2051
 Lines 2875-2878    Link Here 
2875
3086
2876
    }
3087
    }
2877
3088
3089
3090
    /** Modify the line to move the text starting at dotPos one tab
3091
     * column to the right.  Whitespace preceeding dotPos may be
3092
     * replaced by a TAB character if tabs expanding is on.
3093
     * @param doc document to operate on
3094
     * @param dotPos insertion point
3095
     */
3096
    static void insertTabString (final BaseDocument doc, final int dotPos) throws BadLocationException {
3097
        final BadLocationException[] badLocationExceptions = new BadLocationException [1];
3098
        doc.runAtomic (new Runnable () {
3099
            public void run () {
3100
                try {
3101
                    // Determine first white char before dotPos
3102
                    int rsPos = Utilities.getRowStart(doc, dotPos);
3103
                    int startPos = Utilities.getFirstNonWhiteBwd(doc, dotPos, rsPos);
3104
                    startPos = (startPos >= 0) ? (startPos + 1) : rsPos;
3105
3106
                    int startCol = Utilities.getVisualColumn(doc, startPos);
3107
                    int endCol = Utilities.getNextTabColumn(doc, dotPos);
3108
                    Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
3109
                    String tabStr = Analyzer.getWhitespaceString(
3110
                            startCol, endCol,
3111
                            prefs.getBoolean(SimpleValueNames.EXPAND_TABS, EditorPreferencesDefaults.defaultExpandTabs),
3112
                            prefs.getInt(SimpleValueNames.TAB_SIZE, EditorPreferencesDefaults.defaultTabSize));
3113
3114
                    // Search for the first non-common char
3115
                    char[] removeChars = doc.getChars(startPos, dotPos - startPos);
3116
                    int ind = 0;
3117
                    while (ind < removeChars.length && removeChars[ind] == tabStr.charAt(ind)) {
3118
                        ind++;
3119
                    }
3120
3121
                    startPos += ind;
3122
                    doc.remove(startPos, dotPos - startPos);
3123
                    doc.insertString(startPos, tabStr.substring(ind), null);
3124
                } catch (BadLocationException ex) {
3125
                    badLocationExceptions [0] = ex;
3126
                }
3127
            }
3128
        });
3129
        if (badLocationExceptions[0] != null)
3130
            throw badLocationExceptions [0];
3131
    }
3132
3133
    /** Change the indent of the given row. Document is atomically locked
3134
     * during this operation.
3135
     */
3136
    static void changeRowIndent (final BaseDocument doc, final int pos, final int newIndent) throws BadLocationException {
3137
        final BadLocationException[] badLocationExceptions = new BadLocationException [1];
3138
        doc.runAtomic (new Runnable () {
3139
            public void run () {
3140
                try {
3141
                    int indent = newIndent < 0 ? 0 : newIndent;
3142
                    int firstNW = Utilities.getRowFirstNonWhite(doc, pos);
3143
                    if (firstNW == -1) { // valid first non-blank
3144
                        firstNW = Utilities.getRowEnd(doc, pos);
3145
                    }
3146
                    int replacePos = Utilities.getRowStart(doc, pos);
3147
                    int removeLen = firstNW - replacePos;
3148
                    CharSequence removeText = DocumentUtilities.getText(doc, replacePos, removeLen);
3149
                    String newIndentText = IndentUtils.createIndentString(doc, indent);
3150
                    if (CharSequenceUtilities.startsWith(newIndentText, removeText)) {
3151
                        // Skip removeLen chars at start
3152
                        newIndentText = newIndentText.substring(removeLen);
3153
                        replacePos += removeLen;
3154
                        removeLen = 0;
3155
                    } else if (CharSequenceUtilities.endsWith(newIndentText, removeText)) {
3156
                        // Skip removeLen chars at the end
3157
                        newIndentText = newIndentText.substring(0, newIndentText.length() - removeLen);
3158
                        removeLen = 0;
3159
                    }
3160
3161
                    if (removeLen != 0) {
3162
                        doc.remove(replacePos, removeLen);
3163
                    }
3164
3165
                    doc.insertString(replacePos, newIndentText, null);
3166
                } catch (BadLocationException ex) {
3167
                    badLocationExceptions [0] = ex;
3168
                }
3169
            }
3170
        });
3171
        if (badLocationExceptions[0] != null)
3172
            throw badLocationExceptions [0];
3173
    }
3174
3175
    /** Increase/decrease indentation of the block of the code. Document
3176
    * is atomically locked during the operation.
3177
    * @param doc document to operate on
3178
    * @param startPos starting line position
3179
    * @param endPos ending line position
3180
    * @param shiftCnt positive/negative count of shiftwidths by which indentation
3181
    *   should be shifted right/left
3182
    */
3183
    static void changeBlockIndent (final BaseDocument doc, final int startPos, final int endPos,
3184
                                  final int shiftCnt) throws BadLocationException {
3185
        GuardedDocument gdoc = (doc instanceof GuardedDocument)
3186
                               ? (GuardedDocument)doc : null;
3187
        if (gdoc != null){
3188
            for (int i = startPos; i<endPos; i++){
3189
                if (gdoc.isPosGuarded(i)){
3190
                    java.awt.Toolkit.getDefaultToolkit().beep();
3191
                    return;
3192
                }
3193
            }
3194
        }
3195
3196
        final BadLocationException[] badLocationExceptions = new BadLocationException [1];
3197
        doc.runAtomic (new Runnable () {
3198
            public void run () {
3199
                try {
3200
                    int indentDelta = shiftCnt * doc.getShiftWidth();
3201
                    int end = (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) ?
3202
                        endPos - 1 : endPos;
3203
3204
                    int pos = Utilities.getRowStart(doc, startPos );
3205
                    for (int lineCnt = Utilities.getRowCount(doc, startPos, end);
3206
                            lineCnt > 0; lineCnt--
3207
                        ) {
3208
                        int indent = Utilities.getRowIndent(doc, pos);
3209
                        if (Utilities.isRowWhite(doc, pos)) {
3210
                            indent = -indentDelta; // zero indentation for white line
3211
                        }
3212
                        changeRowIndent(doc, pos, Math.max(indent + indentDelta, 0));
3213
                        pos = Utilities.getRowStart(doc, pos, +1);
3214
                    }
3215
                } catch (BadLocationException ex) {
3216
                    badLocationExceptions [0] = ex;
3217
                }
3218
            }
3219
        });
3220
        if (badLocationExceptions[0] != null)
3221
            throw badLocationExceptions [0];
3222
    }
3223
3224
    /** Shift line either left or right */
3225
    static void shiftLine(BaseDocument doc, int dotPos, boolean right) throws BadLocationException {
3226
        int ind = doc.getShiftWidth();
3227
        if (!right) {
3228
            ind = -ind;
3229
        }
3230
3231
        if (Utilities.isRowWhite(doc, dotPos)) {
3232
            ind += Utilities.getVisualColumn(doc, dotPos);
3233
        } else {
3234
            ind += Utilities.getRowIndent(doc, dotPos);
3235
        }
3236
        ind = Math.max(ind, 0);
3237
        changeRowIndent(doc, dotPos, ind);
3238
    }
2878
}
3239
}
(-)a/editor.lib/src/org/netbeans/editor/Utilities.java (-17 / +27 lines)
 Lines 58-63    Link Here 
58
import java.util.Set;
58
import java.util.Set;
59
import java.util.logging.Level;
59
import java.util.logging.Level;
60
import java.util.logging.Logger;
60
import java.util.logging.Logger;
61
import java.util.prefs.Preferences;
61
import javax.swing.SwingUtilities;
62
import javax.swing.SwingUtilities;
62
import javax.swing.Action;
63
import javax.swing.Action;
63
import javax.swing.InputMap;
64
import javax.swing.InputMap;
 Lines 79-90    Link Here 
79
import javax.swing.plaf.TextUI;
80
import javax.swing.plaf.TextUI;
80
import javax.swing.text.AbstractDocument;
81
import javax.swing.text.AbstractDocument;
81
import javax.swing.text.Element;
82
import javax.swing.text.Element;
83
import javax.swing.text.Position;
82
import javax.swing.text.View;
84
import javax.swing.text.View;
83
import org.netbeans.api.editor.EditorRegistry;
85
import org.netbeans.api.editor.EditorRegistry;
84
import org.netbeans.api.editor.mimelookup.MimeLookup;
86
import org.netbeans.api.editor.mimelookup.MimeLookup;
87
import org.netbeans.api.editor.settings.SimpleValueNames;
85
import org.netbeans.lib.editor.util.CharSequenceUtilities;
88
import org.netbeans.lib.editor.util.CharSequenceUtilities;
86
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
89
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
90
import org.netbeans.modules.editor.indent.api.Reformat;
91
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
87
import org.netbeans.modules.editor.lib.drawing.DrawEngineDocView;
92
import org.netbeans.modules.editor.lib.drawing.DrawEngineDocView;
93
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
88
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
94
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
89
import org.netbeans.modules.editor.lib2.highlighting.HighlightingManager;
95
import org.netbeans.modules.editor.lib2.highlighting.HighlightingManager;
90
import org.netbeans.modules.editor.lib2.view.DocumentView;
96
import org.netbeans.modules.editor.lib2.view.DocumentView;
 Lines 984-1009    Link Here 
984
     * @param endOffset offset at which the formatting ends
990
     * @param endOffset offset at which the formatting ends
985
     * @return length of the reformatted code
991
     * @return length of the reformatted code
986
     */
992
     */
987
    public static int reformat (final BaseDocument doc, final int startOffset, final int endOffset)
993
    public static int reformat (final BaseDocument doc, final int startOffset, final int endOffset) throws BadLocationException {
988
    throws BadLocationException {
994
        final Reformat formatter = Reformat.get(doc);
989
        final Formatter formatter = doc.getFormatter();
995
        formatter.lock();
990
        formatter.reformatLock();
991
        try {
996
        try {
992
            final Object[] result = new Object [1];
997
            final Object[] result = new Object[1];
993
            doc.runAtomicAsUser (new Runnable () {
998
            doc.runAtomicAsUser(new Runnable() {
994
                public @Override void run () {
999
                public @Override void run() {
995
                    try {
1000
                    try {
996
                        result [0] = formatter.reformat (doc, startOffset, endOffset);
1001
                        Position endPos = doc.createPosition(endOffset);
1002
                        formatter.reformat(startOffset, endOffset);
1003
                        result[0] = Math.max(endPos.getOffset() - startOffset, 0);
997
                    } catch (BadLocationException ex) {
1004
                    } catch (BadLocationException ex) {
998
                        result [0] = ex;
1005
                        result[0] = ex;
999
                    }
1006
                    }
1000
                }
1007
                }
1001
            });
1008
            });
1002
            if (result [0] instanceof BadLocationException)
1009
            if (result[0] instanceof BadLocationException) {
1003
                throw (BadLocationException) result [0];
1010
                throw (BadLocationException) result[0];
1004
            return (Integer) result [0];
1011
            } else {
1012
                return (Integer) result[0];
1013
            }
1005
        } finally {
1014
        } finally {
1006
            formatter.reformatUnlock();
1015
            formatter.unlock();
1007
        }
1016
        }
1008
    }
1017
    }
1009
1018
 Lines 1043-1052    Link Here 
1043
    public static String getTabInsertString(BaseDocument doc, int offset)
1052
    public static String getTabInsertString(BaseDocument doc, int offset)
1044
    throws BadLocationException {
1053
    throws BadLocationException {
1045
        int col = getVisualColumn(doc, offset);
1054
        int col = getVisualColumn(doc, offset);
1046
        Formatter f = doc.getFormatter();
1055
        Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
1047
        boolean expandTabs = f.expandTabs();
1056
        boolean expandTabs = prefs.getBoolean(SimpleValueNames.EXPAND_TABS, EditorPreferencesDefaults.defaultExpandTabs);
1048
        if (expandTabs) {
1057
        if (expandTabs) {
1049
            int spacesPerTab = f.getSpacesPerTab();
1058
            int spacesPerTab = prefs.getInt(SimpleValueNames.SPACES_PER_TAB, EditorPreferencesDefaults.defaultSpacesPerTab);
1050
            int len = (col + spacesPerTab) / spacesPerTab * spacesPerTab - col;
1059
            int len = (col + spacesPerTab) / spacesPerTab * spacesPerTab - col;
1051
            return new String(Analyzer.getSpacesBuffer(len), 0, len);
1060
            return new String(Analyzer.getSpacesBuffer(len), 0, len);
1052
        } else { // insert pure tab
1061
        } else { // insert pure tab
 Lines 1062-1068    Link Here 
1062
    public static int getNextTabColumn(BaseDocument doc, int offset)
1071
    public static int getNextTabColumn(BaseDocument doc, int offset)
1063
    throws BadLocationException {
1072
    throws BadLocationException {
1064
        int col = getVisualColumn(doc, offset);
1073
        int col = getVisualColumn(doc, offset);
1065
        int tabSize = doc.getFormatter().getSpacesPerTab();
1074
        Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
1075
        int tabSize = prefs.getInt(SimpleValueNames.SPACES_PER_TAB, EditorPreferencesDefaults.defaultSpacesPerTab);
1066
        return (col + tabSize) / tabSize * tabSize;
1076
        return (col + tabSize) / tabSize * tabSize;
1067
    }
1077
    }
1068
1078
(-)a/editor.lib/src/org/netbeans/editor/ext/ExtKit.java (-61 / +20 lines)
 Lines 46-52    Link Here 
46
46
47
import java.awt.Rectangle;
47
import java.awt.Rectangle;
48
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionEvent;
49
import java.io.IOException;
50
import java.util.ArrayList;
49
import java.util.ArrayList;
51
import java.util.StringTokenizer;
50
import java.util.StringTokenizer;
52
import java.util.prefs.Preferences;
51
import java.util.prefs.Preferences;
 Lines 67-73    Link Here 
67
import org.netbeans.editor.Utilities;
66
import org.netbeans.editor.Utilities;
68
import org.netbeans.editor.BaseDocument;
67
import org.netbeans.editor.BaseDocument;
69
import org.netbeans.editor.SyntaxSupport;
68
import org.netbeans.editor.SyntaxSupport;
70
import org.netbeans.editor.Formatter;
71
import org.netbeans.lib.editor.util.CharSequenceUtilities;
69
import org.netbeans.lib.editor.util.CharSequenceUtilities;
72
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
70
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
73
import org.netbeans.modules.editor.lib.NavigationHistory;
71
import org.netbeans.modules.editor.lib.NavigationHistory;
 Lines 370-376    Link Here 
370
        
368
        
371
        protected final void debugPopupMenuItem(JMenuItem item, Action action) {
369
        protected final void debugPopupMenuItem(JMenuItem item, Action action) {
372
            if (debugPopupMenu) {
370
            if (debugPopupMenu) {
373
                StringBuffer sb = new StringBuffer("POPUP: "); // NOI18N
371
                StringBuilder sb = new StringBuilder("POPUP: "); // NOI18N
374
                if (item != null) {
372
                if (item != null) {
375
                    sb.append('"'); //NOI18N
373
                    sb.append('"'); //NOI18N
376
                    sb.append(item.getText());
374
                    sb.append(item.getText());
 Lines 1043-1049    Link Here 
1043
    }
1041
    }
1044
1042
1045
1043
1046
    // Completion customized actions
1044
    /** 
1045
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
1046
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1047
     */
1047
//    @EditorActionRegistration(
1048
//    @EditorActionRegistration(
1048
//            name = defaultKeyTypedAction,
1049
//            name = defaultKeyTypedAction,
1049
//            shortDescription = editorBundleHash + defaultKeyTypedAction
1050
//            shortDescription = editorBundleHash + defaultKeyTypedAction
 Lines 1081-1113    Link Here 
1081
            }
1082
            }
1082
        }
1083
        }
1083
1084
1084
        /** Check the characters that should cause reindenting the line. */
1085
        // --------------------------------------------------------------------
1086
        // SPI
1087
        // --------------------------------------------------------------------
1088
1089
        /** 
1090
         * Check the characters that should cause reindenting the line. 
1091
         * 
1092
         * @