EditorConfig and NetBeans IDE (Part 2)

Indentation size (and, as a result, tab width) is now working. Turned out to be much easier than I thought. The APIs for this are great.

@Override
public void actionPerformed(ActionEvent e) {
    InputOutput io = IOProvider.getDefault().getIO("EditorConfig", true);
    io.select();
    OutputWriter writer = io.getOut();
    StatusDisplayer.getDefault().setStatusText(dobj.getPrimaryFile().getPath());
    EditorConfig ec;
    try {
        ec = new EditorConfig();
        List<EditorConfig.OutPair> l = null;
        l = ec.getProperties(dobj.getPrimaryFile().getPath());
        for (int i = 0; i < l.size(); ++i) {
            writer.println(l.get(i).getKey() + "=" + l.get(i).getVal());
            if (l.get(i).getKey().equals("indent_size")) {
                doIndentSize(
                        dobj.getPrimaryFile(),
                        Integer.valueOf(l.get(i).getVal()));
            }
        }
        writer.close();
    } catch (PythonException ex) {
        Exceptions.printStackTrace(ex);
    } catch (EditorConfigException ex) {
        Exceptions.printStackTrace(ex);
    }
}
public static final String indentSize = SimpleValueNames.INDENT_SHIFT_WIDTH;
private void doIndentSize(FileObject file, int value) {
    Preferences prefs = CodeStylePreferences.get(file, file.getMIMEType()).getPreferences();
    prefs.putInt(indentSize, value);
}

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« March 2015
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    
       
Today