Search in sources :

Example 1 with SeverityBasedTextAttributes

use of com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes in project intellij-community by JetBrains.

the class SeverityEditorDialog method doOKAction.

@Override
protected void doOKAction() {
    apply((SeverityBasedTextAttributes) myOptionsList.getSelectedValue());
    final Collection<SeverityBasedTextAttributes> infoTypes = new HashSet<>(SeverityUtil.getRegisteredHighlightingInfoTypes(mySeverityRegistrar));
    final ListModel listModel = myOptionsList.getModel();
    final List<HighlightSeverity> order = new ArrayList<>();
    for (int i = listModel.getSize() - 1; i >= 0; i--) {
        SeverityBasedTextAttributes info = (SeverityBasedTextAttributes) listModel.getElementAt(i);
        order.add(info.getSeverity());
        if (!mySeverityRegistrar.isDefaultSeverity(info.getSeverity())) {
            infoTypes.remove(info);
            final Color stripeColor = info.getAttributes().getErrorStripeColor();
            final boolean exists = mySeverityRegistrar.getSeverity(info.getSeverity().getName()) != null;
            if (exists) {
                info.getType().getAttributesKey().getDefaultAttributes().setErrorStripeColor(stripeColor);
            } else {
                HighlightInfoType.HighlightInfoTypeImpl type = info.getType();
                TextAttributesKey key = type.getAttributesKey();
                final TextAttributes defaultAttributes = key.getDefaultAttributes().clone();
                defaultAttributes.setErrorStripeColor(stripeColor);
                key = TextAttributesKey.createTextAttributesKey(key.getExternalName(), defaultAttributes);
                type = new HighlightInfoType.HighlightInfoTypeImpl(type.getSeverity(null), key);
                info = new SeverityBasedTextAttributes(info.getAttributes(), type);
            }
            mySeverityRegistrar.registerSeverity(info, stripeColor != null ? stripeColor : LightColors.YELLOW);
        }
    }
    for (SeverityBasedTextAttributes info : infoTypes) {
        mySeverityRegistrar.unregisterSeverity(info.getSeverity());
    }
    mySeverityRegistrar.setOrder(order);
    super.doOKAction();
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) SeverityBasedTextAttributes(com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SeverityBasedTextAttributes(com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes)

Example 2 with SeverityBasedTextAttributes

use of com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes in project intellij-community by JetBrains.

the class SeverityEditorDialog method fillList.

private void fillList(@Nullable final HighlightSeverity severity) {
    DefaultListModel model = new DefaultListModel();
    model.removeAllElements();
    final List<SeverityBasedTextAttributes> infoTypes = new ArrayList<>();
    infoTypes.addAll(SeverityUtil.getRegisteredHighlightingInfoTypes(mySeverityRegistrar));
    Collections.sort(infoTypes, (attributes1, attributes2) -> -mySeverityRegistrar.compare(attributes1.getSeverity(), attributes2.getSeverity()));
    SeverityBasedTextAttributes preselection = null;
    for (SeverityBasedTextAttributes type : infoTypes) {
        if (HighlightSeverity.INFO.equals(type.getSeverity()))
            continue;
        model.addElement(type);
        if (type.getSeverity().equals(severity)) {
            preselection = type;
        }
    }
    if (preselection == null && !infoTypes.isEmpty()) {
        preselection = infoTypes.get(0);
    }
    myOptionsList.setModel(model);
    myOptionsList.setSelectedValue(preselection, true);
}
Also used : SeverityBasedTextAttributes(com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes)

Example 3 with SeverityBasedTextAttributes

use of com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes in project intellij-community by JetBrains.

the class SeverityEditorDialog method apply.

private void apply(SeverityBasedTextAttributes info) {
    if (info == null) {
        return;
    }
    MyTextAttributesDescription description = new MyTextAttributesDescription(info.getType().toString(), null, new TextAttributes(), info.getType().getAttributesKey());
    myOptionsPanel.apply(description, null);
    Element textAttributes = new Element("temp");
    try {
        description.getTextAttributes().writeExternal(textAttributes);
        info.getAttributes().readExternal(textAttributes);
    } catch (Exception e) {
        LOG.error(e);
    }
}
Also used : Element(org.jdom.Element) SeverityBasedTextAttributes(com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Aggregations

SeverityBasedTextAttributes (com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes)3 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)1 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)1 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)1 Element (org.jdom.Element)1