private String buildLabelText( @NotNull final String text, @NotNull final Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap) { final StringBuilder labelText = new StringBuilder(text); final String disabledTag = FLAG_TO_TAG.get(ParameterInfoUIContextEx.Flag.DISABLE); final Map<Integer, Integer> faultMap = new HashMap<>(); if (isDisabledBeforeHighlight) { final String tag = getTag(disabledTag); labelText.insert(0, tag); faultMap.put(0, tag.length()); } for (Map.Entry<TextRange, ParameterInfoUIContextEx.Flag> entry : flagsMap.entrySet()) { final TextRange highlightRange = entry.getKey(); final ParameterInfoUIContextEx.Flag flag = entry.getValue(); final String tagValue = FLAG_TO_TAG.get(flag); final String tag = getTag(tagValue); int startOffset = highlightRange.getStartOffset(); int endOffset = highlightRange.getEndOffset() + tag.length(); for (Map.Entry<Integer, Integer> entry1 : faultMap.entrySet()) { if (entry1.getKey() < highlightRange.getStartOffset()) { startOffset += entry1.getValue(); } if (entry1.getKey() < highlightRange.getEndOffset()) { endOffset += entry1.getValue(); } } if (flag == ParameterInfoUIContextEx.Flag.HIGHLIGHT && isDisabledBeforeHighlight) { final String disableCloseTag = getClosingTag(disabledTag); labelText.insert(startOffset, disableCloseTag); faultMap.put(highlightRange.getStartOffset(), disableCloseTag.length()); } labelText.insert(startOffset, tag); faultMap.put(highlightRange.getStartOffset(), tag.length()); final String endTag = getClosingTag(tagValue); labelText.insert(endOffset, endTag); faultMap.put(highlightRange.getEndOffset(), endTag.length()); } return XmlStringUtil.wrapInHtml(labelText); }
@Nullable @NonNls private static String htmlEscapeToolTip(@Nullable String unescapedTooltip) { return unescapedTooltip == null ? null : XmlStringUtil.wrapInHtml(XmlStringUtil.escapeString(unescapedTooltip)); }
public String getToolTip() { String toolTip = this.toolTip; String description = this.description; if (toolTip == null || description == null || !toolTip.contains(DESCRIPTION_PLACEHOLDER)) return toolTip; String decoded = StringUtil.replace( toolTip, DESCRIPTION_PLACEHOLDER, XmlStringUtil.escapeString(description)); return XmlStringUtil.wrapInHtml(decoded); }
public void showDescription(InspectionTool tool) { if (tool.getShortName().length() == 0) { showEmpty(); return; } @NonNls StringBuffer page = new StringBuffer(); page.append("<table border='0' cellspacing='0' cellpadding='0' width='100%'>"); page.append("<tr><td colspan='2'>"); HTMLComposer.appendHeading( page, InspectionsBundle.message("inspection.tool.in.browser.id.title")); page.append("</td></tr>"); page.append("<tr><td width='37'></td>" + "<td>"); page.append(tool.getShortName()); page.append("</td></tr>"); page.append("<tr height='10'></tr>"); page.append("<tr><td colspan='2'>"); HTMLComposer.appendHeading( page, InspectionsBundle.message("inspection.tool.in.browser.description.title")); page.append("</td></tr>"); page.append("<tr><td width='37'></td>" + "<td>"); @NonNls final String underConstruction = "<b>" + UNDER_CONSTRUCTION + "</b></html>"; try { @NonNls String description = tool.loadDescription(); if (description == null) { description = underConstruction; } page.append(UIUtil.getHtmlBody(description)); page.append("</td></tr></table>"); myHTMLViewer.setText(XmlStringUtil.wrapInHtml(page)); setupStyle(); } finally { myCurrentEntity = null; } }
protected void setValue(@Nullable final String value) { final XmlTag tag = ensureTagExists(); final String attributeName = getXmlElementName(); final String namespace = getXmlApiCompatibleNamespace(getParentHandler()); final String oldValue = StringUtil.unescapeXml(tag.getAttributeValue(attributeName, namespace)); final String newValue = XmlStringUtil.escapeString(value); if (Comparing.equal(oldValue, newValue, true)) return; getManager() .runChange( new Runnable() { public void run() { try { XmlAttribute attribute = tag.setAttribute(attributeName, namespace, newValue); setXmlElement(attribute); getManager() .cacheHandler( DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, AttributeChildInvocationHandler.this); } catch (IncorrectOperationException e) { LOG.error(e); } } }); final DomElement proxy = getProxy(); final DomElement element = proxy; getManager() .fireEvent(oldValue != null ? new DomEvent(proxy, false) : new DomEvent(element, true)); }
@Override public String getToolTip(int line, Editor editor) { LastRevision revision = myRevisions.get(line); if (revision != null) { return XmlStringUtil.escapeString( revision.getAuthor() + " " + DateFormatUtil.formatDateTime(revision.getDate()) + "\n" + revision.getMessage()); } return null; }
protected void setup( final AnAction action, JPanel root, final JLabel name, final JLabel description, JLabel icon) { name.setText(action.getTemplatePresentation().getText()); name.setUI(DarculaWelcomeScreenLabelUI.createUI(name)); name.setForeground(UIUtil.getPanelBackground()); description.setUI(DarculaWelcomeScreenLabelUI.createUI(description)); // icon.setIcon(action.getTemplatePresentation().getIcon()); final String text = action.getTemplatePresentation().getDescription(); final String html = XmlStringUtil.wrapInHtml( MessageFormat.format(text, ApplicationNamesInfo.getInstance().getFullProductName())); root.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); description.setText(html); description.setForeground(Gray._200); description.setEnabled(false); root.addMouseListener( new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { description.setEnabled(true); name.setForeground(new Color(0xE09600)); } @Override public void mouseExited(MouseEvent e) { description.setEnabled(false); name.setForeground(UIUtil.getPanelBackground()); } @Override public void mouseClicked(MouseEvent e) { final ActionManager actionManager = ActionManager.getInstance(); AnActionEvent evt = new AnActionEvent( null, DataManager.getInstance().getDataContext(e.getComponent()), ActionPlaces.WELCOME_SCREEN, action.getTemplatePresentation(), actionManager, 0); action.beforeActionPerformedUpdate(evt); if (evt.getPresentation().isEnabled()) { action.actionPerformed(evt); } } }); }
protected Annotation createAnnotation( TextRange range, HighlightSeverity severity, @Nullable String message) { //noinspection HardCodedStringLiteral // TODO: FIXME @NonNls String tooltip = message == null ? null : "<html><body>" + XmlStringUtil.escapeString(message) + "</body></html>"; Annotation annotation = new Annotation(range.getStartOffset(), range.getEndOffset(), severity, message, tooltip); add(annotation); return annotation; }
@Nullable public String getQualifiedName(final RefEntity refEntity) { if (refEntity instanceof RefJavaElement && ((RefJavaElement) refEntity).isSyntheticJSP()) { return XmlStringUtil.escapeString(refEntity.getName()); } else if (refEntity instanceof RefMethod) { PsiMethod psiMethod = (PsiMethod) ((RefMethod) refEntity).getElement(); if (psiMethod != null) { return psiMethod.getName(); } else { return refEntity.getName(); } } return null; }
private static String encodeTooltip(String toolTip, String description) { if (toolTip == null || description == null) return toolTip; String unescaped = StringUtil.unescapeXml(XmlStringUtil.stripHtml(toolTip)); String encoded = description.isEmpty() ? unescaped : StringUtil.replace(unescaped, description, DESCRIPTION_PLACEHOLDER); //noinspection StringEquality if (encoded == unescaped) { return toolTip; } if (encoded.equals(DESCRIPTION_PLACEHOLDER)) encoded = DESCRIPTION_PLACEHOLDER; return encoded; }
private ReturnResult warnAboutDetachedHeadIfNeeded() { // Warning: commit on a detached HEAD DetachedRoot detachedRoot = getDetachedRoot(); if (detachedRoot == null) { return ReturnResult.COMMIT; } final String title; final String message; final CharSequence rootPath = StringUtil.last(detachedRoot.myRoot.getPresentableUrl(), 50, true); final String messageCommonStart = "The Git repository <code>" + rootPath + "</code>"; if (detachedRoot.myRebase) { title = "Unfinished rebase process"; message = messageCommonStart + " <br/> has an <b>unfinished rebase</b> process. <br/>" + "You probably want to <b>continue rebase</b> instead of committing. <br/>" + "Committing during rebase may lead to the commit loss. <br/>" + readMore( "http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html", "Read more about Git rebase"); } else { title = "Commit in detached HEAD may be dangerous"; message = messageCommonStart + " is in the <b>detached HEAD</b> state. <br/>" + "You can look around, make experimental changes and commit them, but be sure to checkout a branch not to lose your work. <br/>" + "Otherwise you risk losing your changes. <br/>" + readMore( "http://sitaramc.github.com/concepts/detached-head.html", "Read more about detached HEAD"); } final int choice = Messages.showOkCancelDialog( myPanel.getComponent(), XmlStringUtil.wrapInHtml(message), title, "Cancel", "Commit", Messages.getWarningIcon()); if (choice != Messages.OK) { return ReturnResult.COMMIT; } else { return ReturnResult.CLOSE_WINDOW; } }
private String setup( @NotNull String text, @NotNull Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap, @NotNull Color background) { myLabel.setBackground(background); setBackground(background); myLabel.setForeground(JBColor.foreground()); if (flagsMap.isEmpty()) { myLabel.setText(XmlStringUtil.wrapInHtml(text)); } else { String labelText = buildLabelText(text, flagsMap); myLabel.setText(labelText); } // IDEA-95904 Darcula parameter info pop-up colors hard to read if (UIUtil.isUnderDarcula()) { myLabel.setText(myLabel.getText().replace("<b>", "<b color=ffC800>")); } return myLabel.getText(); }
private void explainTrailingSpaces( @NotNull @EditorSettingsExternalizable.StripTrailingSpaces String stripTrailingSpaces) { if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE.equals(stripTrailingSpaces)) { myStripTrailingSpacesExplanationLabel.setVisible(false); return; } myStripTrailingSpacesExplanationLabel.setVisible(true); boolean isVirtualSpace = myCbVirtualSpace.isSelected(); String text; String virtSpaceText = myCbVirtualSpace.getText(); if (isVirtualSpace) { text = "Trailing spaces will be trimmed even in the line under caret.<br>To disable trimming in that line uncheck the '<b>" + virtSpaceText + "</b>' above."; } else { text = "Trailing spaces will <b><font color=red>NOT</font></b> be trimmed in the line under caret.<br>To enable trimming in that line too check the '<b>" + virtSpaceText + "</b>' above."; } myStripTrailingSpacesExplanationLabel.setText(XmlStringUtil.wrapInHtml(text)); }
public void appendReferencePresentation( RefEntity refElement, final StringBuffer buf, final boolean isPackageIncluded) { if (refElement instanceof RefImplicitConstructor) { buf.append(InspectionsBundle.message("inspection.export.results.implicit.constructor")); refElement = ((RefImplicitConstructor) refElement).getOwnerClass(); } buf.append(HTMLComposerImpl.CODE_OPENING); if (refElement instanceof RefField) { RefField field = (RefField) refElement; PsiField psiField = field.getElement(); buf.append(psiField.getType().getPresentableText()); buf.append(HTMLComposerImpl.NBSP); } else if (refElement instanceof RefMethod) { RefMethod method = (RefMethod) refElement; PsiMethod psiMethod = (PsiMethod) method.getElement(); PsiType returnType = psiMethod.getReturnType(); if (returnType != null) { buf.append(returnType.getPresentableText()); buf.append(HTMLComposerImpl.NBSP); } } buf.append(HTMLComposerImpl.A_HREF_OPENING); if (myComposer.myExporter == null) { buf.append(((RefElementImpl) refElement).getURL()); } else { buf.append(myComposer.myExporter.getURL(refElement)); } buf.append("\">"); if (refElement instanceof RefClass && ((RefClass) refElement).isAnonymous()) { buf.append(InspectionsBundle.message("inspection.reference.anonymous")); } else if (refElement instanceof RefJavaElement && ((RefJavaElement) refElement).isSyntheticJSP()) { buf.append(XmlStringUtil.escapeString(refElement.getName())); } else if (refElement instanceof RefMethod) { PsiMethod psiMethod = (PsiMethod) ((RefMethod) refElement).getElement(); buf.append(psiMethod.getName()); } else { buf.append(refElement.getName()); } buf.append(HTMLComposerImpl.A_CLOSING); if (refElement instanceof RefMethod) { PsiMethod psiMethod = (PsiMethod) ((RefMethod) refElement).getElement(); appendMethodParameters(buf, psiMethod, false); } buf.append(HTMLComposerImpl.CODE_CLOSING); if (refElement instanceof RefClass && ((RefClass) refElement).isAnonymous()) { buf.append(" "); buf.append(InspectionsBundle.message("inspection.export.results.anonymous.ref.in.owner")); buf.append(" "); myComposer.appendElementReference( buf, ((RefElement) refElement.getOwner()), isPackageIncluded); } else if (isPackageIncluded) { buf.append(" ").append(HTMLComposerImpl.CODE_OPENING).append("("); myComposer.appendQualifiedName(buf, refElement.getOwner()); // buf.append(RefUtil.getPackageName(refElement)); buf.append(")").append(HTMLComposerImpl.CODE_CLOSING); } }
private String escapeString(String line, Function<String, String> escapeFunction) { line = XmlStringUtil.escapeString(line); return escapeFunction == null ? line : escapeFunction.fun(line); }
// return true if panel needs to be rebuilt boolean updatePanel(@NotNull DaemonCodeAnalyzerStatus status, Project project) { progressBarsEnabled = false; progressBarsCompleted = null; statistics = ""; passStatusesVisible = false; statusLabel = null; statusExtraLine = null; boolean result = false; if (!status.passStati.equals(new ArrayList<>(passes.keySet()))) { // passes set has changed rebuildPassesMap(status); result = true; } if (PowerSaveMode.isEnabled()) { statusLabel = "Code analysis is disabled in power save mode"; status.errorAnalyzingFinished = true; icon = AllIcons.General.SafeMode; return result; } if (status.reasonWhyDisabled != null) { statusLabel = "No analysis has been performed"; statusExtraLine = "(" + status.reasonWhyDisabled + ")"; passStatusesVisible = true; progressBarsCompleted = Boolean.FALSE; icon = AllIcons.General.InspectionsTrafficOff; return result; } if (status.reasonWhySuspended != null) { statusLabel = "Code analysis has been suspended"; statusExtraLine = "(" + status.reasonWhySuspended + ")"; passStatusesVisible = true; progressBarsCompleted = Boolean.FALSE; icon = AllIcons.General.InspectionsPause; return result; } Icon icon = AllIcons.General.InspectionsOK; for (int i = status.errorCount.length - 1; i >= 0; i--) { if (status.errorCount[i] != 0) { icon = SeverityRegistrar.getSeverityRegistrar(project).getRendererIconByIndex(i); break; } } if (status.errorAnalyzingFinished) { boolean isDumb = project != null && DumbService.isDumb(project); if (isDumb) { statusLabel = "Shallow analysis completed"; statusExtraLine = "Complete results will be available after indexing"; } else { statusLabel = DaemonBundle.message("analysis.completed"); } progressBarsCompleted = Boolean.TRUE; } else { statusLabel = DaemonBundle.message("performing.code.analysis"); passStatusesVisible = true; progressBarsEnabled = true; progressBarsCompleted = null; } int currentSeverityErrors = 0; @org.intellij.lang.annotations.Language("HTML") String text = ""; for (int i = status.errorCount.length - 1; i >= 0; i--) { if (status.errorCount[i] > 0) { final HighlightSeverity severity = SeverityRegistrar.getSeverityRegistrar(project).getSeverityByIndex(i); String name = status.errorCount[i] > 1 ? StringUtil.pluralize(severity.getName().toLowerCase()) : severity.getName().toLowerCase(); text += status.errorAnalyzingFinished ? DaemonBundle.message("errors.found", status.errorCount[i], name) : DaemonBundle.message("errors.found.so.far", status.errorCount[i], name); text += "<br>"; currentSeverityErrors += status.errorCount[i]; } } if (currentSeverityErrors == 0) { text += status.errorAnalyzingFinished ? DaemonBundle.message("no.errors.or.warnings.found") : DaemonBundle.message("no.errors.or.warnings.found.so.far") + "<br>"; } statistics = XmlStringUtil.wrapInHtml(text); this.icon = icon; return result; }
@SuppressWarnings("HardCodedStringLiteral") @NotNull public String getDescription() { final StringBuilder buf = StringBuilderSpinAllocator.alloc(); try { buf.append("<html><body>"); buf.append(getDisplayName()); if (myInvalidMessage != null && !myInvalidMessage.isEmpty()) { buf.append("<br><font color='red'>"); buf.append(DebuggerBundle.message("breakpoint.warning", myInvalidMessage)); buf.append("</font>"); } buf.append(" <br> "); buf.append(DebuggerBundle.message("breakpoint.property.name.suspend.policy")).append(" : "); if (DebuggerSettings.SUSPEND_NONE.equals(getSuspendPolicy()) || !isSuspend()) { buf.append(DebuggerBundle.message("breakpoint.properties.panel.option.suspend.none")); } else if (DebuggerSettings.SUSPEND_ALL.equals(getSuspendPolicy())) { buf.append(DebuggerBundle.message("breakpoint.properties.panel.option.suspend.all")); } else if (DebuggerSettings.SUSPEND_THREAD.equals(getSuspendPolicy())) { buf.append(DebuggerBundle.message("breakpoint.properties.panel.option.suspend.thread")); } buf.append(" <br> "); buf.append(DebuggerBundle.message("breakpoint.property.name.log.message")).append(": "); buf.append(isLogEnabled() ? CommonBundle.getYesButtonText() : CommonBundle.getNoButtonText()); if (isLogExpressionEnabled()) { buf.append(" <br> "); buf.append(DebuggerBundle.message("breakpoint.property.name.log.expression")).append(": "); buf.append(XmlStringUtil.escapeString(getLogMessage().getText())); } if (isConditionEnabled() && getCondition() != null && getCondition().getText() != null && !getCondition().getText().isEmpty()) { buf.append(" <br> "); buf.append(DebuggerBundle.message("breakpoint.property.name.condition")).append(": "); buf.append(XmlStringUtil.escapeString(getCondition().getText())); } if (isCountFilterEnabled()) { buf.append(" <br> "); buf.append(DebuggerBundle.message("breakpoint.property.name.pass.count")).append(": "); buf.append(getCountFilter()); } if (isClassFiltersEnabled()) { buf.append(" <br> "); buf.append(DebuggerBundle.message("breakpoint.property.name.class.filters")).append(": "); ClassFilter[] classFilters = getClassFilters(); for (ClassFilter classFilter : classFilters) { buf.append(classFilter.getPattern()).append(" "); } } if (isInstanceFiltersEnabled()) { buf.append(" <br> "); buf.append(DebuggerBundle.message("breakpoint.property.name.instance.filters")); InstanceFilter[] instanceFilters = getInstanceFilters(); for (InstanceFilter instanceFilter : instanceFilters) { buf.append(Long.toString(instanceFilter.getId())).append(" "); } } buf.append("</body></html>"); return buf.toString(); } finally { StringBuilderSpinAllocator.dispose(buf); } }
private static boolean suggestToEnableInstalledPlugins( InstalledPluginsTableModel pluginsModel, Set<IdeaPluginDescriptor> disabled, Set<IdeaPluginDescriptor> disabledDependants, List<PluginNode> list) { if (!disabled.isEmpty() || !disabledDependants.isEmpty()) { String message = ""; if (disabled.size() == 1) { message += "Updated plugin '" + disabled.iterator().next().getName() + "' is disabled."; } else if (!disabled.isEmpty()) { message += "Updated plugins " + StringUtil.join( disabled, new Function<IdeaPluginDescriptor, String>() { @Override public String fun(IdeaPluginDescriptor pluginDescriptor) { return pluginDescriptor.getName(); } }, ", ") + " are disabled."; } if (!disabledDependants.isEmpty()) { message += "<br>"; message += "Updated plugin" + (list.size() > 1 ? "s depend " : " depends ") + "on disabled"; if (disabledDependants.size() == 1) { message += " plugin '" + disabledDependants.iterator().next().getName() + "'."; } else { message += " plugins " + StringUtil.join( disabledDependants, new Function<IdeaPluginDescriptor, String>() { @Override public String fun(IdeaPluginDescriptor pluginDescriptor) { return pluginDescriptor.getName(); } }, ", ") + "."; } } message += " Disabled plugins " + (disabled.isEmpty() ? "and plugins which depend on disabled " : "") + "won't be activated after restart."; int result; if (!disabled.isEmpty() && !disabledDependants.isEmpty()) { result = Messages.showYesNoCancelDialog( XmlStringUtil.wrapInHtml(message), CommonBundle.getWarningTitle(), "Enable all", "Enable updated plugin" + (disabled.size() > 1 ? "s" : ""), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon()); if (result == Messages.CANCEL) return false; } else { message += "<br>Would you like to enable "; if (!disabled.isEmpty()) { message += "updated plugin" + (disabled.size() > 1 ? "s" : ""); } else { //noinspection SpellCheckingInspection message += "plugin dependenc" + (disabledDependants.size() > 1 ? "ies" : "y"); } message += "?"; result = Messages.showYesNoDialog( XmlStringUtil.wrapInHtml(message), CommonBundle.getWarningTitle(), Messages.getQuestionIcon()); if (result == Messages.NO) return false; } if (result == Messages.YES) { disabled.addAll(disabledDependants); pluginsModel.enableRows(disabled.toArray(new IdeaPluginDescriptor[disabled.size()]), true); } else if (result == Messages.NO && !disabled.isEmpty()) { pluginsModel.enableRows(disabled.toArray(new IdeaPluginDescriptor[disabled.size()]), true); } return true; } return false; }
private String escapeString(String line) { return XmlStringUtil.escapeString(line); }