コード例 #1
0
 public void actionPerformed(final AnActionEvent e) {
   LogModel model = myConsole.myProjectModel;
   for (Notification notification : model.getNotifications()) {
     notification.expire();
     model.removeNotification(notification);
   }
   model.setStatusMessage(null, 0);
   final Editor editor = e.getData(CommonDataKeys.EDITOR);
   if (editor != null) {
     editor.getDocument().deleteString(0, editor.getDocument().getTextLength());
   }
 }
コード例 #2
0
  private Editor createLogEditor() {
    Project project = myProjectModel.getProject();
    final Editor editor = ConsoleViewUtil.setupConsoleEditor(project, false, false);
    myProjectModel
        .getProject()
        .getMessageBus()
        .connect()
        .subscribe(
            ProjectManager.TOPIC,
            new ProjectManagerAdapter() {
              @Override
              public void projectClosed(Project project) {
                if (project == myProjectModel.getProject()) {
                  EditorFactory.getInstance().releaseEditor(editor);
                }
              }
            });

    ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);

    final ClearLogAction clearLog = new ClearLogAction(this);
    clearLog.registerCustomShortcutSet(
        ActionManager.getInstance().getAction(IdeActions.CONSOLE_CLEAR_ALL).getShortcutSet(),
        editor.getContentComponent());

    editor.addEditorMouseListener(
        new EditorPopupHandler() {
          public void invokePopup(final EditorMouseEvent event) {
            final ActionManager actionManager = ActionManager.getInstance();
            final ActionPopupMenu menu =
                actionManager.createActionPopupMenu(
                    ActionPlaces.EDITOR_POPUP, createPopupActions(actionManager, clearLog));
            final MouseEvent mouseEvent = event.getMouseEvent();
            menu.getComponent()
                .show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
          }
        });
    return editor;
  }
コード例 #3
0
  void doPrintNotification(final Notification notification) {
    Editor editor = myLogEditor.getValue();
    if (editor.isDisposed()) {
      return;
    }

    Document document = editor.getDocument();
    boolean scroll =
        document.getTextLength() == editor.getCaretModel().getOffset()
            || !editor.getContentComponent().hasFocus();

    Long notificationTime = myProjectModel.getNotificationTime(notification);
    if (notificationTime == null) {
      return;
    }

    String date = DateFormatUtil.formatTimeWithSeconds(notificationTime) + " ";
    append(document, date);

    int startLine = document.getLineCount() - 1;

    EventLog.LogEntry pair =
        EventLog.formatForLog(notification, StringUtil.repeatSymbol(' ', date.length()));

    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();
    String message = pair.message;
    append(document, message);

    TextAttributes attributes =
        EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
    int layer = HighlighterLayer.CARET_ROW + 1;
    editor
        .getMarkupModel()
        .addRangeHighlighter(
            msgStart,
            document.getTextLength(),
            layer,
            attributes,
            HighlighterTargetArea.EXACT_RANGE);

    for (Pair<TextRange, HyperlinkInfo> link : pair.links) {
      myHyperlinkSupport
          .getValue()
          .addHyperlink(
              link.first.getStartOffset() + msgStart,
              link.first.getEndOffset() + msgStart,
              null,
              link.second);
    }

    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);
    }
  }