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

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

(-)a/gsf/src/org/netbeans/modules/gsf/GsfDocument.java (-1 / +5 lines)
Lines 86-91 Link Here
86
    }
86
    }
87
87
88
    /** Get the formatter for this document. */
88
    /** Get the formatter for this document. */
89
    @Override
89
    public Formatter getFormatter() {
90
    public Formatter getFormatter() {
90
        if (formatter == null) {
91
        if (formatter == null) {
91
            // NbDocument will go looking in the settings map for a formatter - let's make
92
            // NbDocument will go looking in the settings map for a formatter - let's make
Lines 103-109 Link Here
103
    public int getShiftWidth() {
104
    public int getShiftWidth() {
104
        org.netbeans.modules.gsf.api.Formatter f = language.getFormatter();
105
        org.netbeans.modules.gsf.api.Formatter f = language.getFormatter();
105
        if (f != null) {
106
        if (f != null) {
106
            return f.indentSize();
107
            int shiftWidth = f.indentSize();
108
            if (shiftWidth > 0) {
109
                return shiftWidth;
110
            }
107
        }
111
        }
108
        return super.getShiftWidth();
112
        return super.getShiftWidth();
109
    }
113
    }
(-)a/javascript.editing/src/org/netbeans/modules/javascript/editing/CodeStyle.java (-2 / +2 lines)
Lines 54-60 Link Here
54
 * 
54
 * 
55
 * @author Dusan Balek
55
 * @author Dusan Balek
56
 */
56
 */
57
public final class CodeStyle {
57
public /*final*/ class CodeStyle {
58
    
58
    
59
    private static CodeStyle INSTANCE;
59
    private static CodeStyle INSTANCE;
60
60
Lines 64-70 Link Here
64
    
64
    
65
    private Preferences preferences;
65
    private Preferences preferences;
66
    
66
    
67
    private CodeStyle(Preferences preferences) {
67
    protected CodeStyle(Preferences preferences) {
68
        this.preferences = preferences;
68
        this.preferences = preferences;
69
    }
69
    }
70
70
(-)a/javascript.editing/src/org/netbeans/modules/javascript/editing/JsFormatter.java (-6 / +72 lines)
Lines 47-58 Link Here
47
import java.util.Stack;
47
import java.util.Stack;
48
import javax.swing.text.BadLocationException;
48
import javax.swing.text.BadLocationException;
49
import javax.swing.text.Document;
49
import javax.swing.text.Document;
50
import javax.swing.text.EditorKit;
51
import org.netbeans.api.editor.mimelookup.MimeLookup;
52
import org.netbeans.api.editor.mimelookup.MimePath;
50
import org.netbeans.api.lexer.Token;
53
import org.netbeans.api.lexer.Token;
51
import org.netbeans.api.lexer.TokenHierarchy;
54
import org.netbeans.api.lexer.TokenHierarchy;
52
import org.netbeans.api.lexer.TokenId;
55
import org.netbeans.api.lexer.TokenId;
53
import org.netbeans.api.lexer.TokenSequence;
56
import org.netbeans.api.lexer.TokenSequence;
54
import org.netbeans.editor.BaseDocument;
57
import org.netbeans.editor.BaseDocument;
58
import org.netbeans.editor.Settings;
59
import org.netbeans.editor.SettingsNames;
55
import org.netbeans.editor.Utilities;
60
import org.netbeans.editor.Utilities;
61
import org.netbeans.modules.editor.options.BaseOptions;
56
import org.netbeans.modules.gsf.api.CompilationInfo;
62
import org.netbeans.modules.gsf.api.CompilationInfo;
57
import org.netbeans.modules.gsf.api.OffsetRange;
63
import org.netbeans.modules.gsf.api.OffsetRange;
58
import org.netbeans.modules.javascript.editing.lexer.LexUtilities;
64
import org.netbeans.modules.javascript.editing.lexer.LexUtilities;
Lines 98-104 Link Here
98
    private Stack<StackItem> stack = new Stack<StackItem>();
104
    private Stack<StackItem> stack = new Stack<StackItem>();
99
105
100
    public JsFormatter() {
106
    public JsFormatter() {
101
        this.codeStyle = CodeStyle.getDefault(null);
107
        this.codeStyle = new DocSyncedCodeStyle();
102
    }
108
    }
103
    
109
    
104
    public JsFormatter(CodeStyle codeStyle, int rightMarginOverride) {
110
    public JsFormatter(CodeStyle codeStyle, int rightMarginOverride) {
Lines 119-129 Link Here
119
    }
125
    }
120
    
126
    
121
    public int indentSize() {
127
    public int indentSize() {
122
        return codeStyle.getIndentSize();
128
        return -1; // Use IDE defaults
123
    }
129
    }
124
    
130
    
125
    public int hangingIndentSize() {
131
    public int hangingIndentSize() {
126
        return codeStyle.getContinuationIndentSize();
132
        return -1; // Use IDE defaults
127
    }
133
    }
128
134
129
    /** Compute the initial balance of brackets at the given offset. */
135
    /** Compute the initial balance of brackets at the given offset. */
Lines 849-857 Link Here
849
     * those settings
855
     * those settings
850
     */
856
     */
851
    private static void syncOptions(BaseDocument doc, CodeStyle style) {
857
    private static void syncOptions(BaseDocument doc, CodeStyle style) {
852
        org.netbeans.editor.Formatter formatter = doc.getFormatter();
858
        if (style instanceof DocSyncedCodeStyle) {
853
        if (formatter.getSpacesPerTab() != style.getIndentSize()) {
859
            ((DocSyncedCodeStyle)style).syncToDocument(doc);
854
            formatter.setSpacesPerTab(style.getIndentSize());
860
        }
861
    }
862
    
863
    private static final class DocSyncedCodeStyle extends CodeStyle {
864
        private DocSyncedCodeStyle() {
865
            super(null);
866
        }
867
        
868
        private int indentSize = 4;
869
        private int continuationIndentSize = 4;
870
        private int rightMargin = 80;
871
        private EditorKit kit;
872
        
873
        // Copied from option.editor's org.netbeans.modules.options.indentation.IndentationModel
874
        private EditorKit getEditorKit() {
875
            if(kit == null)
876
                kit = MimeLookup.getLookup(MimePath.parse("text/xml")).lookup(EditorKit.class); // NOI18N
877
            return kit;
878
        }
879
880
        // Copied from option.editor's org.netbeans.modules.options.indentation.IndentationModel
881
        private Integer getSpacesPerTab() {
882
            Integer sp =
883
                    (Integer) Settings.getValue(getEditorKit().getClass(), SettingsNames.SPACES_PER_TAB);
884
            return sp;
885
        }
886
        
887
        public void syncToDocument(BaseDocument doc) {
888
            Integer sp = getSpacesPerTab();
889
            int indent = sp.intValue();
890
            if (indent <= 0) {
891
                indent = 4;
892
            }
893
            indentSize = continuationIndentSize = indent;
894
        }
895
        
896
        @Override
897
        public int getIndentSize() {
898
            return indentSize;
899
        }
900
901
        @Override
902
        public int getContinuationIndentSize() {
903
            return continuationIndentSize;
904
        }
905
906
        @Override
907
        public boolean reformatComments() {
908
            // This isn't used in JavaScript yet
909
            return false;
910
        }
911
912
        @Override
913
        public boolean indentHtml() {
914
            // This isn't used in JavaScript yet
915
            return false;
916
        }
917
918
        @Override
919
        public int getRightMargin() {
920
            return rightMargin;
855
        }
921
        }
856
    }
922
    }
857
923

Return to bug 132363