use of com.intellij.execution.filters.HyperlinkInfo in project intellij-community by JetBrains.
the class EventLog method formatForLog.
public static LogEntry formatForLog(@NotNull final Notification notification, final String indent) {
DocumentImpl logDoc = new DocumentImpl("", true);
AtomicBoolean showMore = new AtomicBoolean(false);
Map<RangeMarker, HyperlinkInfo> links = new LinkedHashMap<>();
List<RangeMarker> lineSeparators = new ArrayList<>();
String title = notification.getTitle();
String subtitle = notification.getSubtitle();
if (StringUtil.isNotEmpty(title) && StringUtil.isNotEmpty(subtitle)) {
title += " (" + subtitle + ")";
}
title = truncateLongString(showMore, title);
String content = truncateLongString(showMore, notification.getContent());
RangeMarker afterTitle = null;
boolean hasHtml = parseHtmlContent(addIndents(title, indent), notification, logDoc, showMore, links, lineSeparators);
if (StringUtil.isNotEmpty(title)) {
if (StringUtil.isNotEmpty(content)) {
appendText(logDoc, ": ");
afterTitle = logDoc.createRangeMarker(logDoc.getTextLength() - 2, logDoc.getTextLength());
}
}
int titleLength = logDoc.getTextLength();
hasHtml |= parseHtmlContent(addIndents(content, indent), notification, logDoc, showMore, links, lineSeparators);
List<AnAction> actions = notification.getActions();
if (!actions.isEmpty()) {
String text = "<p>" + StringUtil.join(actions, new Function<AnAction, String>() {
private int index;
@Override
public String fun(AnAction action) {
return "<a href=\"" + index++ + "\">" + action.getTemplatePresentation().getText() + "</a>";
}
}, isLongLine(actions) ? "<br>" : " ") + "</p>";
Notification n = new Notification("", "", ".", NotificationType.INFORMATION, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification n, @NotNull HyperlinkEvent event) {
Notification.fire(notification, notification.getActions().get(Integer.parseInt(event.getDescription())));
}
});
if (title.length() > 0 || content.length() > 0) {
lineSeparators.add(logDoc.createRangeMarker(TextRange.from(logDoc.getTextLength(), 0)));
}
hasHtml |= parseHtmlContent(text, n, logDoc, showMore, links, lineSeparators);
}
String status = getStatusText(logDoc, showMore, lineSeparators, indent, hasHtml);
indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml, indent);
ArrayList<Pair<TextRange, HyperlinkInfo>> list = new ArrayList<>();
for (RangeMarker marker : links.keySet()) {
if (!marker.isValid()) {
showMore.set(true);
continue;
}
list.add(Pair.create(new TextRange(marker.getStartOffset(), marker.getEndOffset()), links.get(marker)));
}
if (showMore.get()) {
String sb = "show balloon";
if (!logDoc.getText().endsWith(" ")) {
appendText(logDoc, " ");
}
appendText(logDoc, "(" + sb + ")");
list.add(new Pair<>(TextRange.from(logDoc.getTextLength() - 1 - sb.length(), sb.length()), new ShowBalloon(notification)));
}
return new LogEntry(logDoc.getText(), status, list, titleLength);
}
use of com.intellij.execution.filters.HyperlinkInfo in project intellij-community by JetBrains.
the class EventLogConsole method doPrintNotification.
void doPrintNotification(final Notification notification) {
Editor editor = getConsoleEditor();
if (editor.isDisposed()) {
return;
}
Document document = editor.getDocument();
boolean scroll = document.getTextLength() == editor.getCaretModel().getOffset() || !editor.getContentComponent().hasFocus();
if (document.getTextLength() > 0) {
append(document, "\n");
}
String lastDate = DateFormatUtil.formatDate(notification.getTimestamp());
if (document.getTextLength() == 0 || !lastDate.equals(myLastDate)) {
myLastDate = lastDate;
append(document, lastDate + "\n");
}
int startDateOffset = document.getTextLength();
String date = DateFormatUtil.formatTime(notification.getTimestamp()) + "\t";
append(document, date);
int tabs = calculateTabs(editor, startDateOffset);
int titleStartOffset = document.getTextLength();
int startLine = document.getLineCount() - 1;
EventLog.LogEntry pair = EventLog.formatForLog(notification, StringUtil.repeatSymbol('\t', tabs));
final NotificationType type = notification.getType();
TextAttributesKey key = type == NotificationType.ERROR ? ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY : type == NotificationType.INFORMATION ? ConsoleViewContentType.NORMAL_OUTPUT_KEY : ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY;
int msgStart = document.getTextLength();
append(document, pair.message);
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
int layer = HighlighterLayer.CARET_ROW + 1;
RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(msgStart, document.getTextLength(), layer, attributes, HighlighterTargetArea.EXACT_RANGE);
GROUP_ID.set(highlighter, notification.getGroupId());
NOTIFICATION_ID.set(highlighter, notification.id);
for (Pair<TextRange, HyperlinkInfo> link : pair.links) {
final RangeHighlighter rangeHighlighter = myHyperlinkSupport.getValue().createHyperlink(link.first.getStartOffset() + msgStart, link.first.getEndOffset() + msgStart, null, link.second);
if (link.second instanceof EventLog.ShowBalloon) {
((EventLog.ShowBalloon) link.second).setRangeHighlighter(rangeHighlighter);
}
}
append(document, "\n");
if (scroll) {
editor.getCaretModel().moveToOffset(document.getTextLength());
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
}
if (notification.isImportant()) {
highlightNotification(notification, pair.status, startLine, document.getLineCount() - 1, titleStartOffset, pair.titleLength);
}
}
use of com.intellij.execution.filters.HyperlinkInfo in project intellij-community by JetBrains.
the class MavenConsoleImpl method createConsoleBuilder.
public static TextConsoleBuilder createConsoleBuilder(final Project project) {
TextConsoleBuilder builder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
builder.addFilter(new RegexpFilter(project, CONSOLE_FILTER_REGEXP) {
@Nullable
@Override
protected HyperlinkInfo createOpenFileHyperlink(String fileName, int line, int column) {
HyperlinkInfo res = super.createOpenFileHyperlink(fileName, line, column);
if (res == null && fileName.startsWith("\\") && SystemInfo.isWindows) {
// Maven cut prefix 'C:\' from paths on Windows
VirtualFile[] roots = ProjectRootManager.getInstance(project).getContentRoots();
if (roots.length > 0) {
String projectPath = roots[0].getPath();
if (projectPath.matches("[A-Z]:[\\\\/].+")) {
res = super.createOpenFileHyperlink(projectPath.charAt(0) + ":" + fileName, line, column);
}
}
}
return res;
}
});
builder.addFilter(new MavenGroovyConsoleFilter(project));
builder.addFilter(new MavenScalaConsoleFilter(project));
builder.addFilter(new MavenTestConsoleFilter());
return builder;
}
use of com.intellij.execution.filters.HyperlinkInfo in project intellij-community by JetBrains.
the class CustomRegexpFilter method createResult.
private Result createResult(final Matcher matcher, final int entireLen) {
final String filePath = matcher.group(myFileRegister);
String lineNumber = "0";
String columnNumber = "0";
if (myLineRegister != -1) {
lineNumber = matcher.group(myLineRegister);
}
if (myColumnRegister != -1) {
columnNumber = matcher.group(myColumnRegister);
}
int line = 0;
int column = 0;
try {
line = Integer.parseInt(lineNumber);
column = Integer.parseInt(columnNumber);
} catch (NumberFormatException e) {
// Do nothing, so that line and column will remain at their initial
// zero values.
}
if (line > 0)
line -= 1;
if (column > 0)
column -= 1;
// Calculate the offsets relative to the entire text.
final int highlightStartOffset;
final int highlightEndOffset;
if ((filePath == null || filePath.length() == 0) && myLineRegister != -1) {
highlightStartOffset = entireLen + matcher.start(myLineRegister);
highlightEndOffset = highlightStartOffset + lineNumber.length();
} else {
highlightStartOffset = entireLen + matcher.start(myFileRegister);
highlightEndOffset = highlightStartOffset + filePath.length();
}
final HyperlinkInfo info = createOpenFileHyperlink(filePath, line, column);
// don't return a result if the filename cannot be resolved to a file
return info != null ? new Result(highlightStartOffset, highlightEndOffset, info) : null;
}
Aggregations