Search in sources :

Example 31 with HtmlBuilder

use of com.android.utils.HtmlBuilder in project android by JetBrains.

the class RenderProblem method createPlain.

@NotNull
public static RenderProblem createPlain(@NotNull HighlightSeverity severity, @NotNull String message, @NotNull Project project, @NotNull HtmlLinkManager linkManager, @Nullable Throwable throwable) {
    Html problem = new Html(severity, ourNextOrdinal++);
    HtmlBuilder builder = problem.getHtmlBuilder();
    builder.add(message);
    if (throwable != null) {
        String url = linkManager.createRunnableLink(new ShowExceptionFix(project, throwable));
        builder.add(" (").addLink("Details", url).add(")");
        problem.throwable(throwable);
        if (message.equals(throwable.getMessage())) {
            problem.myIsDefaultHtml = true;
        }
    }
    return problem;
}
Also used : HtmlBuilder(com.android.utils.HtmlBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with HtmlBuilder

use of com.android.utils.HtmlBuilder in project android by JetBrains.

the class ViewLoader method checkModified.

/** Checks that the given class has not been edited since the last compilation (and if it has, logs a warning to the user) */
private void checkModified(@NotNull String fqcn) {
    if (DumbService.getInstance(myModule.getProject()).isDumb()) {
        // If the index is not ready, we can not check the modified time since it requires accessing the PSI
        return;
    }
    if (myModuleClassLoader != null && myModuleClassLoader.isSourceModified(fqcn, myCredential) && !myRecentlyModifiedClasses.contains(fqcn)) {
        assert myLogger != null;
        myRecentlyModifiedClasses.add(fqcn);
        RenderProblem.Html problem = RenderProblem.create(WARNING);
        HtmlBuilder builder = problem.getHtmlBuilder();
        String className = fqcn.substring(fqcn.lastIndexOf('.') + 1);
        builder.addLink("The " + className + " custom view has been edited more recently than the last build: ", "Build", " the project.", myLogger.getLinkManager().createBuildProjectUrl());
        myLogger.addMessage(problem);
    }
}
Also used : RenderProblem(com.android.tools.idea.rendering.RenderProblem) HtmlBuilder(com.android.utils.HtmlBuilder)

Example 33 with HtmlBuilder

use of com.android.utils.HtmlBuilder in project android by JetBrains.

the class AndroidJavaDocRenderer method renderAttributeDoc.

@NotNull
private static String renderAttributeDoc(@NotNull Module module, @Nullable Configuration configuration, @NotNull String name) {
    AttributeDefinition def = ResolutionUtils.getAttributeDefinition(module, configuration, name);
    String doc = (def == null) ? null : def.getDocValue(null);
    HtmlBuilder builder = new HtmlBuilder();
    builder.openHtmlBody();
    builder.beginBold();
    builder.add(name);
    builder.endBold();
    int api = ResolutionUtils.getOriginalApiLevel(name, module.getProject());
    if (api >= 0) {
        builder.add(" (Added in API level ");
        builder.add(String.valueOf(api));
        builder.add(")");
    }
    builder.addHtml("<br/>");
    if (!StringUtil.isEmpty(doc)) {
        builder.addHtml(doc);
        builder.addHtml("<br/>");
    }
    builder.addHtml("<hr/>");
    builder.closeHtmlBody();
    return builder.getHtml();
}
Also used : HtmlBuilder(com.android.utils.HtmlBuilder) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with HtmlBuilder

use of com.android.utils.HtmlBuilder in project android by JetBrains.

the class CreateResourceDirectoryDialogBase method setupDeviceConfigurationPanel.

protected DeviceConfiguratorPanel setupDeviceConfigurationPanel(final JComboBox resourceTypeComboBox, final JTextField directoryNameTextField, final JBLabel errorLabel) {
    return new DeviceConfiguratorPanel() {

        @Override
        public void applyEditors() {
            try {
                doApplyEditors();
                final FolderConfiguration config = this.getConfiguration();
                final ResourceFolderType selectedResourceType = (ResourceFolderType) resourceTypeComboBox.getSelectedItem();
                directoryNameTextField.setText(selectedResourceType != null ? config.getFolderName(selectedResourceType) : "");
                errorLabel.setText("");
            } catch (InvalidOptionValueException e) {
                errorLabel.setText(new HtmlBuilder().openHtmlBody().coloredText(JBColor.RED, e.getMessage()).closeHtmlBody().getHtml());
                directoryNameTextField.setText("");
            }
            setOKActionEnabled(directoryNameTextField.getText().length() > 0);
        }
    };
}
Also used : ResourceFolderType(com.android.resources.ResourceFolderType) HtmlBuilder(com.android.utils.HtmlBuilder) InvalidOptionValueException(org.jetbrains.android.uipreview.InvalidOptionValueException) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) DeviceConfiguratorPanel(org.jetbrains.android.uipreview.DeviceConfiguratorPanel)

Example 35 with HtmlBuilder

use of com.android.utils.HtmlBuilder in project android by JetBrains.

the class LintNotificationPanel method updateExplanation.

private void updateExplanation(@Nullable IssueData selected) {
    // We have the capability to show markup text here, e.g.
    // myExplanationPane.setContentType(UIUtil.HTML_MIME)
    // and then use an HtmlBuilder to populate it with for
    // example issue.getExplanation(HTML). However, the builtin
    // HTML formatter ends up using a bunch of weird fonts etc
    // so the dialog just ends up looking tacky.
    String headerFontColor = HtmlBuilderHelper.getHeaderFontColor();
    HtmlBuilder builder = new HtmlBuilder();
    builder.openHtmlBody();
    if (selected != null) {
        builder.addHeading("Message: ", headerFontColor);
        builder.add(selected.message).newline();
        // Look for quick fixes
        AndroidLintInspectionBase inspection = selected.inspection;
        AndroidLintQuickFix[] quickFixes = inspection.getQuickFixes(selected.startElement, selected.endElement, selected.message);
        IntentionAction[] intentions = inspection.getIntentions(selected.startElement, selected.endElement);
        builder.addHeading("Suggested Fixes:", headerFontColor).newline();
        builder.beginList();
        for (final AndroidLintQuickFix fix : quickFixes) {
            builder.listItem();
            builder.addLink(fix.getName(), myLinkManager.createRunnableLink(() -> {
                myPopup.cancel();
                // TODO: Pull in editor context?
                WriteCommandAction.runWriteCommandAction(selected.startElement.getProject(), () -> {
                    fix.apply(selected.startElement, selected.endElement, AndroidQuickfixContexts.BatchContext.getInstance());
                });
            }));
        }
        for (final IntentionAction fix : intentions) {
            builder.listItem();
            builder.addLink(fix.getText(), myLinkManager.createRunnableLink(() -> {
                NlModel model = myScreenView.getModel();
                Editor editor = PsiEditorUtil.Service.getInstance().findEditorByPsiElement(selected.startElement);
                if (editor != null) {
                    editor.getCaretModel().getCurrentCaret().moveToOffset(selected.startElement.getTextOffset());
                    myPopup.cancel();
                    WriteCommandAction.runWriteCommandAction(model.getProject(), () -> {
                        fix.invoke(model.getProject(), editor, model.getFile());
                    });
                }
            }));
        }
        final SuppressLintIntentionAction suppress = new SuppressLintIntentionAction(selected.issue, selected.startElement);
        builder.listItem();
        builder.addLink(suppress.getText(), myLinkManager.createRunnableLink(() -> {
            myPopup.cancel();
            WriteCommandAction.runWriteCommandAction(selected.startElement.getProject(), () -> {
                suppress.invoke(selected.startElement.getProject(), null, myScreenView.getModel().getFile());
            });
        }));
        builder.endList();
        Issue issue = selected.issue;
        builder.addHeading("Priority: ", headerFontColor);
        builder.addHtml(String.format("%1$d / 10", issue.getPriority()));
        builder.newline();
        builder.addHeading("Category: ", headerFontColor);
        builder.add(issue.getCategory().getFullName());
        builder.newline();
        builder.addHeading("Severity: ", headerFontColor);
        builder.beginSpan();
        // Use converted level instead of *default* severity such that we match any user configured overrides
        HighlightDisplayLevel level = selected.level;
        builder.add(StringUtil.capitalize(level.getName().toLowerCase(Locale.US)));
        builder.endSpan();
        builder.newline();
        builder.addHeading("Explanation: ", headerFontColor);
        String description = issue.getBriefDescription(HTML);
        builder.addHtml(description);
        if (!description.isEmpty() && Character.isLetter(description.charAt(description.length() - 1))) {
            builder.addHtml(".");
        }
        builder.newline();
        String explanationHtml = issue.getExplanation(HTML);
        builder.addHtml(explanationHtml);
        List<String> moreInfo = issue.getMoreInfo();
        builder.newline();
        int count = moreInfo.size();
        if (count > 1) {
            builder.addHeading("More Info: ", headerFontColor);
            builder.beginList();
        }
        for (String uri : moreInfo) {
            if (count > 1) {
                builder.listItem();
            }
            builder.addLink(uri, uri);
        }
        if (count > 1) {
            builder.endList();
        }
        builder.newline();
    }
    builder.closeHtmlBody();
    try {
        myExplanationPane.read(new StringReader(builder.getHtml()), null);
        HtmlBuilderHelper.fixFontStyles(myExplanationPane);
        myExplanationPane.setCaretPosition(0);
    } catch (IOException ignore) {
    // can't happen for internal string reading
    }
}
Also used : AndroidLintInspectionBase(org.jetbrains.android.inspections.lint.AndroidLintInspectionBase) Issue(com.android.tools.lint.detector.api.Issue) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) HtmlBuilder(com.android.utils.HtmlBuilder) NlModel(com.android.tools.idea.uibuilder.model.NlModel) SuppressLintIntentionAction(com.android.tools.idea.lint.SuppressLintIntentionAction) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) IOException(java.io.IOException) RelativePoint(com.intellij.ui.awt.RelativePoint) SuppressLintIntentionAction(com.android.tools.idea.lint.SuppressLintIntentionAction) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) StringReader(java.io.StringReader) Editor(com.intellij.openapi.editor.Editor)

Aggregations

HtmlBuilder (com.android.utils.HtmlBuilder)36 NotNull (org.jetbrains.annotations.NotNull)9 XmlFile (com.intellij.psi.xml.XmlFile)8 Module (com.intellij.openapi.module.Module)7 Project (com.intellij.openapi.project.Project)7 File (java.io.File)6 IOException (java.io.IOException)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 SourceFile (com.android.ide.common.blame.SourceFile)2 ResourceResolver (com.android.ide.common.resources.ResourceResolver)2 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)2 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)2 ResourceFolderType (com.android.resources.ResourceFolderType)2 AndroidVersion (com.android.sdklib.AndroidVersion)2 IAndroidTarget (com.android.sdklib.IAndroidTarget)2 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)2 EditorDesignSurface (com.android.tools.idea.ui.designer.EditorDesignSurface)2