Search in sources :

Example 1 with SmartIndentOptionsEditor

use of com.intellij.application.options.SmartIndentOptionsEditor in project intellij-community by JetBrains.

the class GroovyLanguageCodeStyleSettingsProvider method getIndentOptionsEditor.

@Override
public IndentOptionsEditor getIndentOptionsEditor() {
    return new SmartIndentOptionsEditor() {

        private JTextField myLabelIndent;

        private JLabel myLabelIndentLabel;

        private JComboBox myLabelIndentStyle;

        private JBLabel myStyleLabel;

        @Override
        protected void addComponents() {
            super.addComponents();
            myLabelIndent = new JTextField(4);
            add(myLabelIndentLabel = new JLabel(ApplicationBundle.message("editbox.indent.label.indent")), myLabelIndent);
            myStyleLabel = new JBLabel("Label indent style:");
            myLabelIndentStyle = new JComboBox(new Object[] { ABSOLUTE, RELATIVE, RELATIVE_REVERSED });
            add(myStyleLabel, myLabelIndentStyle);
        }

        @Override
        public boolean isModified(final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions options) {
            boolean isModified = super.isModified(settings, options);
            isModified |= isFieldModified(myLabelIndent, options.LABEL_INDENT_SIZE);
            isModified |= isLabelStyleModified(options.LABEL_INDENT_ABSOLUTE, settings.getCustomSettings(GroovyCodeStyleSettings.class).INDENT_LABEL_BLOCKS);
            return isModified;
        }

        private boolean isLabelStyleModified(boolean absolute, boolean relative) {
            if (absolute) {
                return !ABSOLUTE.equals(myLabelIndentStyle.getSelectedItem());
            } else if (relative) {
                return !RELATIVE.equals(myLabelIndentStyle.getSelectedItem());
            } else {
                return !RELATIVE_REVERSED.equals(myLabelIndentStyle.getSelectedItem());
            }
        }

        @Override
        public void apply(final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions options) {
            super.apply(settings, options);
            options.LABEL_INDENT_SIZE = getFieldValue(myLabelIndent, Integer.MIN_VALUE, options.LABEL_INDENT_SIZE);
            options.LABEL_INDENT_ABSOLUTE = ABSOLUTE.equals(myLabelIndentStyle.getSelectedItem());
            settings.getCustomSettings(GroovyCodeStyleSettings.class).INDENT_LABEL_BLOCKS = RELATIVE.equals(myLabelIndentStyle.getSelectedItem());
        }

        @Override
        public void reset(@NotNull final CodeStyleSettings settings, @NotNull final CommonCodeStyleSettings.IndentOptions options) {
            super.reset(settings, options);
            myLabelIndent.setText(Integer.toString(options.LABEL_INDENT_SIZE));
            if (options.LABEL_INDENT_ABSOLUTE) {
                myLabelIndentStyle.setSelectedItem(ABSOLUTE);
            } else if (settings.getCustomSettings(GroovyCodeStyleSettings.class).INDENT_LABEL_BLOCKS) {
                myLabelIndentStyle.setSelectedItem(RELATIVE);
            } else {
                myLabelIndentStyle.setSelectedItem(RELATIVE_REVERSED);
            }
        }

        @Override
        public void setEnabled(final boolean enabled) {
            super.setEnabled(enabled);
            myLabelIndent.setEnabled(enabled);
            myLabelIndentLabel.setEnabled(enabled);
            myStyleLabel.setEnabled(enabled);
            myLabelIndentStyle.setEnabled(enabled);
        }
    };
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) SmartIndentOptionsEditor(com.intellij.application.options.SmartIndentOptionsEditor) JBLabel(com.intellij.ui.components.JBLabel) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SmartIndentOptionsEditor (com.intellij.application.options.SmartIndentOptionsEditor)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)1 JBLabel (com.intellij.ui.components.JBLabel)1 NotNull (org.jetbrains.annotations.NotNull)1