X

Geertjan's Blog

  • March 11, 2014

EditorConfig and NetBeans IDE (Part 2)

Geertjan Wielenga
Product Manager

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);
}

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.