com.intellij.openapi.editor.ex.EditorMarkupModel Java Examples

The following examples show how to use com.intellij.openapi.editor.ex.EditorMarkupModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThreesideTextDiffViewer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected List<TextEditorHolder> createEditorHolders(@Nonnull EditorHolderFactory<TextEditorHolder> factory) {
  List<TextEditorHolder> holders = super.createEditorHolders(factory);

  boolean[] forceReadOnly = TextDiffViewerUtil.checkForceReadOnly(myContext, myRequest);
  for (int i = 0; i < 3; i++) {
    if (forceReadOnly[i]) holders.get(i).getEditor().setViewer(true);
  }

  ThreeSide.LEFT.select(holders).getEditor().setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT);
  ((EditorMarkupModel)ThreeSide.BASE.select(holders).getEditor().getMarkupModel()).setErrorStripeVisible(false);

  for (TextEditorHolder holder : holders) {
    DiffUtil.disableBlitting(holder.getEditor());
  }

  return holders;
}
 
Example #2
Source File: ErrorStripeUpdateManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("WeakerAccess") // Used in Rider
protected void setOrRefreshErrorStripeRenderer(@Nonnull EditorMarkupModel editorMarkupModel, @Nullable PsiFile file) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (!editorMarkupModel.isErrorStripeVisible() || !DaemonCodeAnalyzer.getInstance(myProject).isHighlightingAvailable(file)) {
    return;
  }
  ErrorStripeRenderer renderer = editorMarkupModel.getErrorStripeRenderer();
  if (renderer instanceof TrafficLightRenderer) {
    TrafficLightRenderer tlr = (TrafficLightRenderer)renderer;
    DesktopEditorMarkupModelImpl markupModelImpl = (DesktopEditorMarkupModelImpl)editorMarkupModel;
    tlr.refresh(markupModelImpl);
    markupModelImpl.repaintTrafficLightIcon();
    if (tlr.isValid()) return;
  }
  Editor editor = editorMarkupModel.getEditor();
  if (editor.isDisposed()) return;

  editorMarkupModel.setErrorStripeRenderer(createRenderer(editor, file));
}
 
Example #3
Source File: TrafficTooltipRendererImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public LightweightHint show(@Nonnull Editor editor, @Nonnull Point p, boolean alignToRight, @Nonnull TooltipGroup group, @Nonnull HintHint hintHint) {
  myTrafficLightRenderer = (TrafficLightRenderer)((EditorMarkupModel)editor.getMarkupModel()).getErrorStripeRenderer();
  myPanel = new TrafficProgressPanel(myTrafficLightRenderer, editor, hintHint);
  repaintTooltipWindow();
  LineTooltipRenderer.correctLocation(editor, myPanel, p, alignToRight, true, myPanel.getMinWidth());
  LightweightHint hint = new LightweightHint(myPanel);

  HintManagerImpl hintManager = (HintManagerImpl)HintManager.getInstance();
  hintManager.showEditorHint(hint, editor, p,
                             HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT |
                             HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
  hint.addHintListener(new HintListener() {
    @Override
    public void hintHidden(EventObject event) {
      if (myPanel == null) return; //double hide?
      myPanel = null;
      onHide.run();
    }
  });
  return hint;
}
 
Example #4
Source File: MergePanel2.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public EditorEx createEditor() {
  Document document = getDocument();
  if (document == null) return null;
  Project project = myData.getProject();
  EditorEx editor = DiffUtil.createEditor(document, project, myIndex != 1);

  if (editor == null) return editor;
  //FileType type = getFileType();
  //editor.setHighlighter(HighlighterFactory.createHighlighter(project, type));
  if (myIndex == 0) editor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT);
  if (myIndex != 1) ((EditorMarkupModel)editor.getMarkupModel()).setErrorStripeVisible(true);
  editor.getSettings().setFoldingOutlineShown(false);
  editor.getFoldingModel().setFoldingEnabled(false);
  editor.getSettings().setLineMarkerAreaShown(false);
  editor.getSettings().setFoldingOutlineShown(false);
  editor.getGutterComponentEx().setShowDefaultGutterPopup(false);
  initEditorSettings(editor);

  return editor;
}
 
Example #5
Source File: DiffUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static EditorEx createEditor(@Nonnull Document document, @Nullable Project project, boolean isViewer, boolean enableFolding) {
  EditorFactory factory = EditorFactory.getInstance();
  EditorEx editor = (EditorEx)(isViewer ? factory.createViewer(document, project) : factory.createEditor(document, project));

  editor.putUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY, Boolean.TRUE);

  editor.getSettings().setShowIntentionBulb(false);
  ((EditorMarkupModel)editor.getMarkupModel()).setErrorStripeVisible(true);
  editor.getGutterComponentEx().setShowDefaultGutterPopup(false);

  if (enableFolding) {
    setFoldingModelSupport(editor);
  } else {
    editor.getSettings().setFoldingOutlineShown(false);
    editor.getFoldingModel().setFoldingEnabled(false);
  }

  UIUtil.removeScrollBorder(editor.getComponent());

  return editor;
}
 
Example #6
Source File: TextEditorComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private Editor createEditor() {
  Editor editor = EditorFactory.getInstance().createEditor(myDocument, myProject);
  ((EditorMarkupModel)editor.getMarkupModel()).setErrorStripeVisible(true);
  ((EditorEx)editor).getGutterComponentEx().setForceShowRightFreePaintersArea(true);

  ((EditorEx)editor).setFile(myFile);

  ((EditorEx)editor).setContextMenuGroupId(IdeActions.GROUP_EDITOR_POPUP);

  ((DesktopEditorImpl)editor).setDropHandler(new FileDropHandler(editor));

  TextEditorProvider.putTextEditor(editor, myTextEditor);
  return editor;
}
 
Example #7
Source File: DaemonTooltipUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void showInfoTooltip(@Nonnull final HighlightInfo info, @Nonnull Editor editor, final int defaultOffset, final int currentWidth, final boolean requestFocus, final boolean showImmediately) {
  if (Registry.is("editor.new.mouse.hover.popups")) {
    EditorMouseHoverPopupManager.getInstance().showInfoTooltip(editor, info, defaultOffset, requestFocus, showImmediately);
    return;
  }
  String text = info.getToolTip();
  if (text == null) return;
  Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();

  Point point = editor.logicalPositionToXY(editor.offsetToLogicalPosition(defaultOffset));
  Point highlightEndPoint = editor.logicalPositionToXY(editor.offsetToLogicalPosition(info.endOffset));
  if (highlightEndPoint.y > point.y) {
    if (highlightEndPoint.x > point.x) {
      point = new Point(point.x, highlightEndPoint.y);
    }
    else if (highlightEndPoint.y > point.y + editor.getLineHeight()) {
      point = new Point(point.x, highlightEndPoint.y - editor.getLineHeight());
    }
  }

  Point bestPoint = new Point(point);
  bestPoint.y += editor.getLineHeight() / 2;
  if (!visibleArea.contains(bestPoint)) bestPoint = point;

  Point p = SwingUtilities.convertPoint(editor.getContentComponent(), bestPoint, editor.getComponent().getRootPane().getLayeredPane());

  HintHint hintHint = new HintHint(editor, bestPoint).setAwtTooltip(true).setHighlighterType(true).setRequestFocus(requestFocus).setCalloutShift(editor.getLineHeight() / 2 - 1)
          .setShowImmediately(showImmediately);

  TooltipAction action = TooltipActionProvider.calcTooltipAction(info, editor);
  ErrorStripTooltipRendererProvider provider = ((EditorMarkupModel)editor.getMarkupModel()).getErrorStripTooltipRendererProvider();
  TooltipRenderer tooltipRenderer = provider.calcTooltipRenderer(text, action, currentWidth);

  TooltipController.getInstance().showTooltip(editor, p, tooltipRenderer, false, DAEMON_INFO_GROUP, hintHint);
}
 
Example #8
Source File: ErrorStripeUpdateManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("WeakerAccess") // Used in Rider
public void repaintErrorStripePanel(@Nonnull Editor editor) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (!myProject.isInitialized()) return;

  PsiFile file = myPsiDocumentManager.getPsiFile(editor.getDocument());
  final EditorMarkupModel markup = (EditorMarkupModel)editor.getMarkupModel();
  markup.setErrorPanelPopupHandler(new DaemonEditorPopup(myProject, editor));
  markup.setErrorStripTooltipRendererProvider(createTooltipRenderer(editor));
  markup.setMinMarkHeight(DaemonCodeAnalyzerSettings.getInstance().getErrorStripeMarkMinHeight());
  setOrRefreshErrorStripeRenderer(markup, file);
}
 
Example #9
Source File: InputPanel.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Editor createPreviewEditor(final VirtualFile grammarFile, Document doc, boolean readOnly) {
	LOG.info("createEditor: create new editor for "+grammarFile.getPath()+" "+previewPanel.project.getName());
	final EditorFactory factory = EditorFactory.getInstance();
	doc.addDocumentListener(
		new DocumentAdapter() {
			VirtualFile grammarFileForThisPreviewEditor;

			{
				{ // faux ctor
					this.grammarFileForThisPreviewEditor = grammarFile;
				}
			}

			@Override
			public void documentChanged(DocumentEvent event) {
				previewPanel.updateParseTreeFromDoc(grammarFileForThisPreviewEditor);
			}
		}
	);
	final Editor editor = readOnly
			? factory.createViewer(doc, previewPanel.project)
			: factory.createEditor(doc, previewPanel.project);
	// force right margin
	((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
	EditorSettings settings = editor.getSettings();
	settings.setWhitespacesShown(true);
	settings.setLineNumbersShown(true);
	settings.setLineMarkerAreaShown(true);
	installListeners(editor);

	return editor;
}
 
Example #10
Source File: ConsoleGutterComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseMoved(MouseEvent e) {
  int line = EditorUtil.yPositionToLogicalLine(editor, e.getPoint());
  if (line == lastGutterToolTipLine) {
    return;
  }

  TooltipController controller = TooltipController.getInstance();
  if (lastGutterToolTipLine != -1) {
    controller.cancelTooltip(TOOLTIP_GROUP, e, true);
  }

  String toolTip = gutterContentProvider.getToolTip(line, editor);
  setCursor(toolTip == null ? Cursor.getDefaultCursor() : Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  if (toolTip == null) {
    lastGutterToolTipLine = -1;
    controller.cancelTooltip(TOOLTIP_GROUP, e, false);
  }
  else {
    lastGutterToolTipLine = line;
    RelativePoint showPoint = new RelativePoint(this, e.getPoint());
    controller.showTooltipByMouseMove(editor,
                                      showPoint,
                                      ((EditorMarkupModel)editor.getMarkupModel()).getErrorStripTooltipRendererProvider().calcTooltipRenderer(toolTip),
                                      false,
                                      TOOLTIP_GROUP,
                                      new HintHint(this, e.getPoint()).setAwtTooltip(true));
  }
}
 
Example #11
Source File: TooltipController.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void showTooltip(@Nonnull Editor editor, @Nonnull Point p, @Nonnull String text, int currentWidth, boolean alignToRight, @Nonnull TooltipGroup group) {
  TooltipRenderer tooltipRenderer = ((EditorMarkupModel)editor.getMarkupModel()).getErrorStripTooltipRendererProvider().calcTooltipRenderer(text, currentWidth);
  showTooltip(editor, p, tooltipRenderer, alignToRight, group);
}
 
Example #12
Source File: TooltipController.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void showTooltip(@Nonnull Editor editor, @Nonnull Point p, @Nonnull String text, int currentWidth, boolean alignToRight, @Nonnull TooltipGroup group, @Nonnull HintHint hintHint) {
  TooltipRenderer tooltipRenderer = ((EditorMarkupModel)editor.getMarkupModel()).getErrorStripTooltipRendererProvider().calcTooltipRenderer(text, currentWidth);
  showTooltip(editor, p, tooltipRenderer, alignToRight, group, hintHint);
}
 
Example #13
Source File: DiffPanelImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void onContentChangedIn(EditorSource source) {
  myDiffUpdater.contentRemoved(source);
  final EditorEx editor = source.getEditor();
  if (myIsHorizontal && source.getSide() == FragmentSide.SIDE1 && editor != null) {
    editor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT);
  }
  DiffSideView viewSide = getSideView(source.getSide());
  viewSide.setEditorSource(getProject(), source);
  Disposer.dispose(myScrollSupport);
  if (editor == null) {
    if (!myDisposed) {
      rediff();
    }
    return;
  }

  final MouseListener mouseListener = PopupHandler.installUnknownPopupHandler(editor.getContentComponent(), new MergeActionGroup(this, source.getSide()), ActionManager.getInstance());
  myDiffUpdater.contentAdded(source);
  editor.getSettings().setLineNumbersShown(true);
  editor.getSettings().setFoldingOutlineShown(false);
  editor.getFoldingModel().setFoldingEnabled(false);
  ((EditorMarkupModel)editor.getMarkupModel()).setErrorStripeVisible(true);

  Editor editor1 = getEditor(FragmentSide.SIDE1);
  Editor editor2 = getEditor(FragmentSide.SIDE2);
  if (editor1 != null && editor2 != null && myIsSyncScroll) {
    myScrollSupport.install(new EditingSides[]{this});
  }

  final VisibleAreaListener visibleAreaListener = mySplitter.getVisibleAreaListener();
  final ScrollingModel scrollingModel = editor.getScrollingModel();
  if (visibleAreaListener != null) {
    scrollingModel.addVisibleAreaListener(visibleAreaListener);
    scrollingModel.addVisibleAreaListener(myVisibleAreaListener);
  }
  myFontSizeSynchronizer.synchronize(editor);
  source.addDisposable(new Disposable() {
    public void dispose() {
      myFontSizeSynchronizer.stopSynchronize(editor);
    }
  });
  source.addDisposable(new Disposable() {
    public void dispose() {
      if (visibleAreaListener != null) {
        scrollingModel.removeVisibleAreaListener(visibleAreaListener);
        scrollingModel.removeVisibleAreaListener(myVisibleAreaListener);
      }
      editor.getContentComponent().removeMouseListener(mouseListener);
    }
  });
}
 
Example #14
Source File: TooltipController.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void showTooltip(@Nonnull Editor editor, @Nonnull Point p, @Nonnull String text, boolean alignToRight, @Nonnull TooltipGroup group) {
  TooltipRenderer tooltipRenderer = ((EditorMarkupModel)editor.getMarkupModel()).getErrorStripTooltipRendererProvider().calcTooltipRenderer(text);
  showTooltip(editor, p, tooltipRenderer, alignToRight, group);
}
 
Example #15
Source File: ApplyPatchViewer.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ApplyPatchViewer(@Nonnull DiffContext context, @Nonnull ApplyPatchRequest request) {
  myProject = context.getProject();
  myContext = context;
  myPatchRequest = request;


  DocumentContent resultContent = request.getResultContent();
  DocumentContent patchContent = DiffContentFactory.getInstance().create(new DocumentImpl("", true), resultContent);

  myResultHolder = TextEditorHolder.create(myProject, resultContent);
  myPatchHolder = TextEditorHolder.create(myProject, patchContent);

  myResultEditor = myResultHolder.getEditor();
  myPatchEditor = myPatchHolder.getEditor();

  if (isReadOnly()) myResultEditor.setViewer(true);
  myPatchEditor.setViewer(true);

  DiffUtil.disableBlitting(myResultEditor);
  DiffUtil.disableBlitting(myPatchEditor);

  ((EditorMarkupModel)myResultEditor.getMarkupModel()).setErrorStripeVisible(false);
  myResultEditor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT);

  myPatchEditor.getGutterComponentEx().setForceShowRightFreePaintersArea(true);
  ((EditorMarkupModel)myPatchEditor.getMarkupModel()).setErrorStripeVisible(false);


  List<TextEditorHolder> holders = ContainerUtil.list(myResultHolder, myPatchHolder);
  List<EditorEx> editors = ContainerUtil.list(myResultEditor, myPatchEditor);
  JComponent resultTitle = DiffUtil.createTitle(myPatchRequest.getResultTitle());
  JComponent patchTitle = DiffUtil.createTitle(myPatchRequest.getPatchTitle());
  List<JComponent> titleComponents = DiffUtil.createSyncHeightComponents(ContainerUtil.list(resultTitle, patchTitle));

  myContentPanel = new TwosideContentPanel(holders, titleComponents);
  myPanel = new SimpleDiffPanel(myContentPanel, this, myContext);

  myModel = new MyModel(myProject, myResultEditor.getDocument());

  myFocusTrackerSupport = new FocusTrackerSupport.Twoside(holders);
  myFocusTrackerSupport.setCurrentSide(Side.LEFT);
  myPrevNextDifferenceIterable = new MyPrevNextDifferenceIterable();
  myStatusPanel = new MyStatusPanel();
  myFoldingModel = new MyFoldingModel(myResultEditor, this);


  new MyFocusOppositePaneAction().install(myPanel);
  new TextDiffViewerUtil.EditorActionsPopup(createEditorPopupActions()).install(editors, myPanel);

  new TextDiffViewerUtil.EditorFontSizeSynchronizer(editors).install(this);

  myEditorSettingsAction = new SetEditorSettingsAction(getTextSettings(), editors);
  myEditorSettingsAction.applyDefaults();

  if (!isReadOnly()) {
    DiffUtil.registerAction(new ApplySelectedChangesAction(true), myPanel);
    DiffUtil.registerAction(new IgnoreSelectedChangesAction(true), myPanel);
  }

  ProxyUndoRedoAction.register(myProject, myResultEditor, myContentPanel);
}
 
Example #16
Source File: DefaultHighlightInfoProcessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
static void repaintErrorStripeAndIcon(@Nonnull Editor editor, @Nonnull Project project) {
  EditorMarkupModel markup = (EditorMarkupModel)editor.getMarkupModel();
  markup.repaintTrafficLightIcon();
  ErrorStripeUpdateManager.getInstance(project).repaintErrorStripePanel(editor);
}
 
Example #17
Source File: FontEditorPreview.java    From consulo with Apache License 2.0 4 votes vote down vote up
static void installTrafficLights(@Nonnull EditorEx editor) {
  ((EditorMarkupModel)editor.getMarkupModel()).setErrorStripeRenderer(new DumbTrafficLightRenderer());
  ((EditorMarkupModel)editor.getMarkupModel()).setErrorStripeVisible(true);
}