Search in sources :

Example 1 with SequentialTask

use of com.intellij.util.SequentialTask in project intellij-community by JetBrains.

the class FormatterImpl method formatWithoutModifications.

public void formatWithoutModifications(final FormattingDocumentModel model, final Block rootBlock, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final TextRange affectedRange) throws IncorrectOperationException {
    SequentialTask task = new MyFormattingTask() {

        @NotNull
        @Override
        protected FormatProcessor buildProcessor() {
            FormatProcessor result = new FormatProcessor(model, rootBlock, settings, indentOptions, new FormatTextRanges(affectedRange, true), FormattingProgressCallback.EMPTY);
            result.formatWithoutRealModifications();
            return result;
        }
    };
    execute(task);
}
Also used : SequentialTask(com.intellij.util.SequentialTask)

Example 2 with SequentialTask

use of com.intellij.util.SequentialTask in project intellij-community by JetBrains.

the class FormatterImpl method format.

@Override
public void format(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final CommonCodeStyleSettings.IndentOptions javaIndentOptions, final FormatTextRanges affectedRanges) throws IncorrectOperationException {
    try {
        validateModel(model);
        SequentialTask task = new MyFormattingTask() {

            @NotNull
            @Override
            protected FormatProcessor buildProcessor() {
                FormatProcessor processor = new FormatProcessor(model.getDocumentModel(), model.getRootBlock(), settings, indentOptions, affectedRanges, FormattingProgressCallback.EMPTY);
                processor.format(model);
                return processor;
            }
        };
        execute(task);
    } catch (FormattingModelInconsistencyException e) {
        LOG.error(e);
    }
}
Also used : SequentialTask(com.intellij.util.SequentialTask)

Example 3 with SequentialTask

use of com.intellij.util.SequentialTask in project intellij-community by JetBrains.

the class FormatterImpl method format.

public void format(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final FormatTextRanges affectedRanges, final boolean formatContextAroundRanges) throws IncorrectOperationException {
    try {
        validateModel(model);
        SequentialTask task = new MyFormattingTask() {

            @NotNull
            @Override
            protected FormatProcessor buildProcessor() {
                FormatOptions options = new FormatOptions(settings, indentOptions, affectedRanges, formatContextAroundRanges);
                FormatProcessor processor = new FormatProcessor(model.getDocumentModel(), model.getRootBlock(), options, getProgressCallback());
                processor.format(model, true);
                return processor;
            }
        };
        execute(task);
    } catch (FormattingModelInconsistencyException e) {
        LOG.error(e);
    }
}
Also used : SequentialTask(com.intellij.util.SequentialTask) FormatOptions(com.intellij.formatting.FormatProcessor.FormatOptions)

Example 4 with SequentialTask

use of com.intellij.util.SequentialTask in project intellij-community by JetBrains.

the class ConvertSchemaPrefixToDefaultIntention method convertTagsAndAttributes.

private static void convertTagsAndAttributes(String ns, final List<XmlTag> tags, final List<XmlAttribute> attrs, Project project) {
    final int localNameIndex = ns.length() + 1;
    final int totalCount = tags.size() + attrs.size();
    final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, "Changing to default namespace", true);
    progressTask.setTask(new SequentialTask() {

        int tagIndex = 0;

        int attrIndex = 0;

        @Override
        public void prepare() {
        }

        @Override
        public boolean isDone() {
            return tagIndex + attrIndex >= totalCount;
        }

        @Override
        public boolean iteration() {
            progressTask.getIndicator().setFraction(((double) (tagIndex + attrIndex)) / totalCount);
            ApplicationManager.getApplication().runWriteAction(() -> {
                if (tagIndex < tags.size()) {
                    XmlTag tag = tags.get(tagIndex++);
                    final String s = tag.getName().substring(localNameIndex);
                    if (!s.isEmpty()) {
                        tag.setName(s);
                    }
                } else if (attrIndex < attrs.size()) {
                    XmlAttribute attr = attrs.get(attrIndex++);
                    //noinspection ConstantConditions
                    attr.setValue(attr.getValue().substring(localNameIndex));
                }
            });
            return isDone();
        }

        @Override
        public void stop() {
        }
    });
    ProgressManager.getInstance().run(progressTask);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) SequentialTask(com.intellij.util.SequentialTask) SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

SequentialTask (com.intellij.util.SequentialTask)4 FormatOptions (com.intellij.formatting.FormatProcessor.FormatOptions)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 SequentialModalProgressTask (com.intellij.util.SequentialModalProgressTask)1