com.intellij.codeInsight.hint.HintManagerImpl Java Examples

The following examples show how to use com.intellij.codeInsight.hint.HintManagerImpl. 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: FlutterReloadManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private LightweightHint showEditorHint(@NotNull Editor editor, String message, boolean isError) {
  final AtomicReference<LightweightHint> ref = new AtomicReference<>();

  ApplicationManager.getApplication().invokeAndWait(() -> {
    final JComponent component = isError
                                 ? HintUtil.createErrorLabel(message)
                                 : HintUtil.createInformationLabel(message);
    final LightweightHint hint = new LightweightHint(component);
    ref.set(hint);
    HintManagerImpl.getInstanceImpl().showEditorHint(
      hint, editor, HintManager.UNDER,
      HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING | HintManager.HIDE_BY_OTHER_HINT,
      isError ? 0 : 3000, false);
  });

  return ref.get();
}
 
Example #2
Source File: LookupImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean performGuardedChange(Runnable change) {
  checkValid();

  myEditor.getDocument().startGuardedBlockChecking();
  myGuardedChanges++;
  boolean result;
  try {
    result = myOffsets.performGuardedChange(change);
  }
  finally {
    myEditor.getDocument().stopGuardedBlockChecking();
    myGuardedChanges--;
  }
  if (!result || myDisposed) {
    hideLookup(false);
    return false;
  }
  if (isVisible()) {
    HintManagerImpl.updateLocation(this, myEditor, myUi.calculatePosition().getLocation());
  }
  checkValid();
  return true;
}
 
Example #3
Source File: LookupUi.java    From consulo with Apache License 2.0 6 votes vote down vote up
void refreshUi(boolean selectionVisible, boolean itemsChanged, boolean reused, boolean onExplicitAction) {
  Editor editor = myLookup.getTopLevelEditor();
  if (editor.getComponent().getRootPane() == null || editor instanceof EditorWindow && !((EditorWindow)editor).isValid()) {
    return;
  }

  if (myLookup.myResizePending || itemsChanged) {
    myMaximumHeight = Integer.MAX_VALUE;
  }
  Rectangle rectangle = calculatePosition();
  myMaximumHeight = rectangle.height;

  if (myLookup.myResizePending || itemsChanged) {
    myLookup.myResizePending = false;
    myLookup.pack();
  }
  HintManagerImpl.updateLocation(myLookup, editor, rectangle.getLocation());

  if (reused || selectionVisible || onExplicitAction) {
    myLookup.ensureSelectionVisible(false);
  }
}
 
Example #4
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 #5
Source File: CommentByBlockCommentHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showMessageIfNeeded() {
  if (myWarning != null) {
    myEditor.getScrollingModel().disableAnimation();
    myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    myEditor.getScrollingModel().enableAnimation();

    LogicalPosition hintPosition = myCaret.getLogicalPosition();
    if (myWarningLocation != null) {
      LogicalPosition targetPosition = myEditor.offsetToLogicalPosition(myWarningLocation.getStartOffset());
      Point targetPoint = myEditor.logicalPositionToXY(targetPosition);
      if (myEditor.getScrollingModel().getVisibleArea().contains(targetPoint)) {
        hintPosition = targetPosition;
      }
    }
    LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(myWarning));
    Point p = HintManagerImpl.getHintPosition(hint, myEditor, hintPosition, HintManager.ABOVE);
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, myEditor, p, 0, 0, false);
  }
}
 
Example #6
Source File: FlutterReloadManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private LightweightHint showEditorHint(@NotNull Editor editor, String message, boolean isError) {
  final AtomicReference<LightweightHint> ref = new AtomicReference<>();

  ApplicationManager.getApplication().invokeAndWait(() -> {
    final JComponent component = isError
                                 ? HintUtil.createErrorLabel(message)
                                 : HintUtil.createInformationLabel(message);
    final LightweightHint hint = new LightweightHint(component);
    ref.set(hint);
    HintManagerImpl.getInstanceImpl().showEditorHint(
      hint, editor, HintManager.UNDER,
      HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING | HintManager.HIDE_BY_OTHER_HINT,
      isError ? 0 : 3000, false);
  });

  return ref.get();
}
 
Example #7
Source File: InputPanel.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void showDecisionEventToolTip(Editor editor, int offset, HintManagerImpl hintMgr, String msg) {
	int flags =
		HintManager.HIDE_BY_ANY_KEY|
			HintManager.HIDE_BY_TEXT_CHANGE|
			HintManager.HIDE_BY_SCROLLING;
	int timeout = 0; // default?
	JComponent infoLabel = HintUtil.createInformationLabel(msg);
	LightweightHint hint = new LightweightHint(infoLabel);
	final LogicalPosition pos = editor.offsetToLogicalPosition(offset);
	final Point p = HintManagerImpl.getHintPosition(hint, editor, pos, HintManager.ABOVE);
	hintMgr.showEditorHint(hint, editor, p, flags, timeout, false);
}
 
Example #8
Source File: FindUsagesManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showEditorHint(String message, final Editor editor) {
  JComponent component = HintUtil.createInformationLabel(message);
  final LightweightHint hint = new LightweightHint(component);
  HintManagerImpl.getInstanceImpl()
          .showEditorHint(hint, editor, HintManager.UNDER, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0,
                          false);
}
 
Example #9
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeActionPerformed(@Nonnull AnAction action, @Nonnull DataContext dataContext, @Nonnull AnActionEvent event) {
  if (!Registry.is("editor.new.mouse.hover.popups")) {
    return;
  }
  if (action instanceof HintManagerImpl.ActionToIgnore) return;
  getInstance().cancelProcessingAndCloseHint();
}
 
Example #10
Source File: SelectOccurrencesActionHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static void showHint(final Editor editor) {
  String message = FindBundle.message("select.next.occurence.not.found.message");
  final LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(message));
  HintManagerImpl.getInstanceImpl().showEditorHint(hint,
                                                   editor,
                                                   HintManager.UNDER,
                                                   HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING,
                                                   0,
                                                   false);
}
 
Example #11
Source File: ShowIntentionActionsHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void invoke(@Nonnull final Project project, @Nonnull Editor editor, @Nonnull PsiFile file, boolean showFeedbackOnEmptyMenu) {
  PsiDocumentManager.getInstance(project).commitAllDocuments();
  if (editor instanceof EditorWindow) {
    editor = ((EditorWindow)editor).getDelegate();
    file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
  }

  final LookupEx lookup = LookupManager.getActiveLookup(editor);
  if (lookup != null) {
    lookup.showElementActions(null);
    return;
  }

  final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project);
  letAutoImportComplete(editor, file, codeAnalyzer);

  ShowIntentionsPass.IntentionsInfo intentions = ShowIntentionsPass.getActionsToShow(editor, file, true);
  IntentionsUI.getInstance(project).hide();

  if (HintManagerImpl.getInstanceImpl().performCurrentQuestionAction()) return;

  //intentions check isWritable before modification: if (!file.isWritable()) return;

  TemplateState state = TemplateManagerImpl.getTemplateState(editor);
  if (state != null && !state.isFinished()) {
    return;
  }

  editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
  Editor finalEditor = editor;
  PsiFile finalFile = file;
  showIntentionHint(project, finalEditor, finalFile, intentions, showFeedbackOnEmptyMenu);
}
 
Example #12
Source File: ElementPreviewHintProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void show(@Nonnull PsiElement element, @Nonnull Editor editor, @Nonnull Point point, boolean keyTriggered) {
  LightweightHint newHint = getHint(element);
  hideCurrentHintIfAny();
  if (newHint == null) {
    return;
  }

  hint = newHint;
  HintManagerImpl.getInstanceImpl().showEditorHint(newHint, editor,
                                                   getHintPosition(newHint, editor, editor.xyToLogicalPosition(point), HintManager.RIGHT_UNDER),
                                                   HINT_HIDE_FLAGS, 0, false);
}
 
Example #13
Source File: LSPReferencesAction.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
private void showReferences(Editor editor, List<PsiElement2UsageTargetAdapter> targets, LogicalPosition position) {
    if (targets.isEmpty()) {
        short constraint = HintManager.ABOVE;
        int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING;
        JLabel label = new JLabel("No references found");
        label.setBackground(new JBColor(new Color(150, 0, 0), new Color(150, 0, 0)));
        LightweightHint hint = new LightweightHint(label);
        Point p = HintManagerImpl.getHintPosition(hint, editor, position, constraint);
        HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, p, flags, 0, false,
                HintManagerImpl.createHintHint(editor, p, hint, constraint).setContentActive(false));
    } else {
        List<Usage> usages = new ArrayList<>();
        targets.forEach(ut -> {
            PsiElement elem = ut.getElement();
            usages.add(new UsageInfo2UsageAdapter(new UsageInfo(elem, -1, -1, false)));
        });

        if (editor == null) {
            return;
        }
        Project project = editor.getProject();
        if (project == null) {
            return;
        }
        UsageViewPresentation presentation = createPresentation(targets.get(0).getElement(),
                new FindUsagesOptions(editor.getProject()), false);
        UsageViewManager.getInstance(project)
                .showUsages(new UsageTarget[] { targets.get(0) }, usages.toArray(new Usage[usages.size()]),
                        presentation);
    }
}
 
Example #14
Source File: CodeInsightUtilBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void showReadOnlyViewWarning(Editor editor) {
  if (ApplicationManager.getApplication().isHeadlessEnvironment()) return;

  JComponent component = HintUtil.createInformationLabel("This view is read-only");
  final LightweightHint hint = new LightweightHint(component);
  HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, HintManager.UNDER,
                                                   HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false);
}
 
Example #15
Source File: FileInEditorProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void showHint(@Nonnull Editor editor, @Nonnull String info, @Nullable HyperlinkListener hyperlinkListener) {
  JComponent component = HintUtil.createInformationLabel(info, hyperlinkListener, null, null);
  LightweightHint hint = new LightweightHint(component);
  HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, HintManager.UNDER,
                                                   HintManager.HIDE_BY_ANY_KEY |
                                                   HintManager.HIDE_BY_TEXT_CHANGE |
                                                   HintManager.HIDE_BY_SCROLLING,
                                                   0, false);
}
 
Example #16
Source File: JSGraphQLQueryContextHighlightVisitor.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Shows a query context hint under the current caret position.
 * The hint hides after a few seconds or when the user interacts with the editor
 */
private static void showQueryContextHint(Editor editor, String hintText) {
    final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
    final JComponent label = HintUtil.createInformationLabel(hintText);
    final LightweightHint lightweightHint = new LightweightHint(label);
    final Point hintPosition = hintManager.getHintPosition(lightweightHint, editor, HintManager.UNDER);
    hintManager.showEditorHint(lightweightHint, editor, hintPosition, 0, 2000, false, HintManager.UNDER);
}
 
Example #17
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void showHint(@Nonnull LightweightHint hint, @Nonnull Editor editor) {
  if (ApplicationManager.getApplication().isUnitTestMode() || editor.isDisposed()) return;
  final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  short constraint = HintManager.ABOVE;
  LogicalPosition position = editor.offsetToLogicalPosition(getOffset(editor));
  Point p = HintManagerImpl.getHintPosition(hint, editor, position, constraint);
  if (p.y - hint.getComponent().getPreferredSize().height < 0) {
    constraint = HintManager.UNDER;
    p = HintManagerImpl.getHintPosition(hint, editor, position, constraint);
  }
  hintManager.showEditorHint(hint, editor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false,
                             HintManagerImpl.createHintHint(editor, p, hint, constraint).setContentActive(false));
}
 
Example #18
Source File: CoverageLineMarkerRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showHint(final Editor editor, final Point point, final int lineNumber) {
  final JPanel panel = new JPanel(new BorderLayout());
  panel.add(createActionsToolbar(editor, lineNumber), BorderLayout.NORTH);

  final LineData lineData = getLineData(lineNumber);
  final Editor uEditor;
  if (lineData != null && lineData.getStatus() != LineCoverage.NONE && !mySubCoverageActive) {
    final EditorFactory factory = EditorFactory.getInstance();
    final Document doc = factory.createDocument(getReport(editor, lineNumber));
    doc.setReadOnly(true);
    uEditor = factory.createEditor(doc, editor.getProject());
    panel.add(EditorFragmentComponent.createEditorFragmentComponent(uEditor, 0, doc.getLineCount(), false, false), BorderLayout.CENTER);
  } else {
    uEditor = null;
  }


  final LightweightHint hint = new LightweightHint(panel){
    @Override
    public void hide() {
      if (uEditor != null) EditorFactory.getInstance().releaseEditor(uEditor);
      super.hide();

    }
  };
  HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point,
                                                   HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE | HintManagerImpl.HIDE_BY_OTHER_HINT | HintManagerImpl.HIDE_BY_SCROLLING, -1, false, new HintHint(editor, point));
}
 
Example #19
Source File: InputPanel.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void showPreviewEditorErrorToolTip(Editor editor, int offset, HintManagerImpl hintMgr, String msg) {
	int flags =
		HintManager.HIDE_BY_ANY_KEY|
			HintManager.HIDE_BY_TEXT_CHANGE|
			HintManager.HIDE_BY_SCROLLING;
	int timeout = 0; // default?
	hintMgr.showErrorHint(editor, msg,
	                      offset, offset+1,
	                      HintManager.ABOVE, flags, timeout);
}
 
Example #20
Source File: InputPanel.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Display syntax errors, hints in tooltips if under the cursor
 */
public static void showTooltips(EditorMouseEvent event, Editor editor,
                                @NotNull PreviewState previewState, int offset) {
	if ( previewState.parsingResult==null ) return; // no results?

	// Turn off any tooltips if none under the cursor
	// find the highlighter associated with this offset
	List<RangeHighlighter> highlightersAtOffset = MyActionUtils.getRangeHighlightersAtOffset(editor, offset);
	if ( highlightersAtOffset.size()==0 ) {
		return;
	}

	List<String> msgList = new ArrayList<>();
	boolean foundDecisionEvent = false;
	for ( RangeHighlighter r : highlightersAtOffset ) {
		DecisionEventInfo eventInfo = r.getUserData(ProfilerPanel.DECISION_EVENT_INFO_KEY);
		String msg;
		if ( eventInfo!=null ) {
			// TODO: move decision event stuff to profiler?
			if ( eventInfo instanceof AmbiguityInfo ) {
				msg = "Ambiguous upon alts " + eventInfo.configs.getAlts().toString();
			} else if ( eventInfo instanceof ContextSensitivityInfo ) {
				msg = "Context-sensitive";
			} else if ( eventInfo instanceof LookaheadEventInfo ) {
				int k = eventInfo.stopIndex - eventInfo.startIndex + 1;
				msg = "Deepest lookahead k=" + k;
			} else if ( eventInfo instanceof PredicateEvalInfo ) {
				PredicateEvalInfo evalInfo = (PredicateEvalInfo) eventInfo;
				msg = ProfilerPanel.getSemanticContextDisplayString(evalInfo,
						previewState,
						evalInfo.semctx, evalInfo.predictedAlt,
						evalInfo.evalResult);
				msg = msg + (!evalInfo.fullCtx ? " (DFA)" : "");
			} else {
				msg = "Unknown decision event: " + eventInfo;
			}
			foundDecisionEvent = true;
		} else {
			// error tool tips
			SyntaxError errorUnderCursor = r.getUserData(SYNTAX_ERROR);
			msg = getErrorDisplayString(errorUnderCursor);
			if ( msg.length()>MAX_HINT_WIDTH ) {
				msg = msg.substring(0, MAX_HINT_WIDTH) + "...";
			}
			if ( msg.indexOf('<') >= 0 ) {
				msg = msg.replaceAll("<", "&lt;");
			}
		}
		msgList.add(msg);
	}
	String combinedMsg = Utils.join(msgList.iterator(), "\n");
	HintManagerImpl hintMgr = (HintManagerImpl) HintManager.getInstance();
	if ( foundDecisionEvent ) {
		showDecisionEventToolTip(editor, offset, hintMgr, combinedMsg);
	}
	else {
		showPreviewEditorErrorToolTip(editor, offset, hintMgr, combinedMsg);
	}
}
 
Example #21
Source File: LookupImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean showLookup() {
  ApplicationManager.getApplication().assertIsDispatchThread();
  checkValid();
  LOG.assertTrue(!myShown);
  myShown = true;
  myStampShown = System.currentTimeMillis();

  fireLookupShown();

  if (ApplicationManager.getApplication().isHeadlessEnvironment()) return true;

  if (!myEditor.getContentComponent().isShowing()) {
    hideLookup(false);
    return false;
  }

  myAdComponent.showRandomText();
  if (Boolean.TRUE.equals(myEditor.getUserData(AutoPopupController.NO_ADS))) {
    myAdComponent.clearAdvertisements();
  }

  myUi = new LookupUi(this, myAdComponent, myList);//, myProject);
  myUi.setCalculating(myCalculating);
  Point p = myUi.calculatePosition().getLocation();
  if (ScreenReader.isActive()) {
    myList.setFocusable(true);
    setFocusRequestor(myList);

    AnActionEvent actionEvent = AnActionEvent.createFromDataContext(ActionPlaces.EDITOR_POPUP, null, ((DesktopEditorImpl)myEditor).getDataContext());
    delegateActionToEditor(IdeActions.ACTION_EDITOR_BACKSPACE, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_ESCAPE, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_TAB, () -> new ChooseItemAction.Replacing(), actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_ENTER,
            /* e.g. rename popup comes initially unfocused */
                           () -> getFocusDegree() == FocusDegree.UNFOCUSED ? new NextVariableAction() : new ChooseItemAction.FocusedOnly(), actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_MOVE_CARET_UP, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_RENAME, null, actionEvent);
  }
  try {
    HintManagerImpl.getInstanceImpl()
            .showEditorHint(this, myEditor, p, HintManager.HIDE_BY_ESCAPE | HintManager.UPDATE_BY_SCROLLING, 0, false, HintManagerImpl.createHintHint(myEditor, p, this, HintManager.UNDER).
                    setRequestFocus(ScreenReader.isActive()).
                    setAwtTooltip(false));
  }
  catch (Exception e) {
    LOG.error(e);
  }

  if (!isVisible() || !myList.isShowing()) {
    hideLookup(false);
    return false;
  }

  return true;
}
 
Example #22
Source File: LineStatusMarkerPopup.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void showHintAt(@javax.annotation.Nullable Point mousePosition) {
  if (!myTracker.isValid()) return;
  final Disposable disposable = Disposable.newDisposable();

  FileType fileType = getFileType();
  List<DiffFragment> wordDiff = computeWordDiff();

  installMasterEditorHighlighters(wordDiff, disposable);
  JComponent editorComponent = createEditorComponent(fileType, wordDiff);

  ActionToolbar toolbar = buildToolbar(mousePosition, disposable);
  toolbar.updateActionsImmediately(); // we need valid ActionToolbar.getPreferredSize() to calc size of popup
  toolbar.setReservePlaceAutoPopupIcon(false);

  PopupPanel popupPanel = new PopupPanel(myEditor, toolbar, editorComponent);

  LightweightHint hint = new LightweightHint(popupPanel);
  HintListener closeListener = new HintListener() {
    public void hintHidden(final EventObject event) {
      Disposer.dispose(disposable);
    }
  };
  hint.addHintListener(closeListener);

  int line = myEditor.getCaretModel().getLogicalPosition().line;
  Point point = HintManagerImpl.getHintPosition(hint, myEditor, new LogicalPosition(line, 0), HintManager.UNDER);
  if (mousePosition != null) { // show right after the nearest line
    int lineHeight = myEditor.getLineHeight();
    int delta = (point.y - mousePosition.y) % lineHeight;
    if (delta < 0) delta += lineHeight;
    point.y = mousePosition.y + delta;
  }
  point.x -= popupPanel.getEditorTextOffset(); // align main editor with the one in popup

  int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING;
  HintManagerImpl.getInstanceImpl().showEditorHint(hint, myEditor, point, flags, -1, false, new HintHint(myEditor, point));

  if (!hint.isVisible()) {
    closeListener.hintHidden(null);
  }
}
 
Example #23
Source File: LightPlatformTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void doTearDown(@Nonnull final Project project, ApplicationStarter application, boolean checkForEditors) throws Exception {
  DocumentCommitThread.getInstance().clearQueue();
  CodeStyleSettingsManager.getInstance(project).dropTemporarySettings();
  checkAllTimersAreDisposed();
  UsefulTestCase.doPostponedFormatting(project);

  LookupManager lookupManager = LookupManager.getInstance(project);
  if (lookupManager != null) {
    lookupManager.hideActiveLookup();
  }
  ((StartupManagerImpl)StartupManager.getInstance(project)).prepareForNextTest();
  InspectionProfileManager.getInstance().deleteProfile(PROFILE);
  assertNotNull("Application components damaged", ProjectManager.getInstance());

  new WriteCommandAction.Simple(project) {
    @Override
    @RequiredWriteAction
    protected void run() throws Throwable {
      if (ourSourceRoot != null) {
        try {
          final VirtualFile[] children = ourSourceRoot.getChildren();
          for (VirtualFile child : children) {
            child.delete(this);
          }
        }
        catch (IOException e) {
          //noinspection CallToPrintStackTrace
          e.printStackTrace();
        }
      }
      EncodingManager encodingManager = EncodingManager.getInstance();
      if (encodingManager instanceof EncodingManagerImpl) ((EncodingManagerImpl)encodingManager).clearDocumentQueue();

      FileDocumentManager manager = FileDocumentManager.getInstance();

      ApplicationManager.getApplication().runWriteAction(EmptyRunnable.getInstance()); // Flush postponed formatting if any.
      manager.saveAllDocuments();
      if (manager instanceof FileDocumentManagerImpl) {
        ((FileDocumentManagerImpl)manager).dropAllUnsavedDocuments();
      }
    }
  }.execute().throwException();

  assertFalse(PsiManager.getInstance(project).isDisposed());

  PsiDocumentManagerImpl documentManager = clearUncommittedDocuments(project);
  ((HintManagerImpl)HintManager.getInstance()).cleanup();
  DocumentCommitThread.getInstance().clearQueue();

  UIUtil.invokeAndWaitIfNeeded(new Runnable() {
    @Override
    public void run() {
      ((UndoManagerImpl)UndoManager.getGlobalInstance()).dropHistoryInTests();
      ((UndoManagerImpl)UndoManager.getInstance(project)).dropHistoryInTests();

      UIUtil.dispatchAllInvocationEvents();
    }
  });

  TemplateDataLanguageMappings.getInstance(project).cleanupForNextTest();

  ProjectManagerEx.getInstanceEx().closeTestProject(project);
  //application.setDataProvider(null);
  ourTestCase = null;
  ((PsiManagerImpl)PsiManager.getInstance(project)).cleanupForNextTest();

  CompletionProgressIndicator.cleanupForNextTest();

  if (checkForEditors) {
    checkEditorsReleased();
  }
  if (isLight(project)) {
    // mark temporarily as disposed so that rogue component trying to access it will fail
    ((ProjectImpl)project).setTemporarilyDisposed(true);
    documentManager.clearUncommittedDocuments();
  }
}
 
Example #24
Source File: NavBarPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void showHint(@Nullable final Editor editor, final DataContext dataContext) {
  myModel.updateModel(dataContext);
  if (myModel.isEmpty()) return;
  final JPanel panel = new JPanel(new BorderLayout());
  panel.add(this);
  panel.setOpaque(true);
  panel.setBackground(UIUtil.getListBackground());

  myHint = new LightweightHint(panel) {
    @Override
    public void hide() {
      super.hide();
      cancelPopup();
      Disposer.dispose(NavBarPanel.this);
    }
  };
  myHint.setForceShowAsPopup(true);
  myHint.setFocusRequestor(this);
  final KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
  myUpdateQueue.rebuildUi();
  if (editor == null) {
    myContextComponent = dataContext.getData(PlatformDataKeys.CONTEXT_COMPONENT);
    getHintContainerShowPoint().doWhenDone((Consumer<RelativePoint>)relativePoint -> {
      final Component owner = focusManager.getFocusOwner();
      final Component cmp = relativePoint.getComponent();
      if (cmp instanceof JComponent && cmp.isShowing()) {
        myHint.show((JComponent)cmp, relativePoint.getPoint().x, relativePoint.getPoint().y, owner instanceof JComponent ? (JComponent)owner : null,
                    new HintHint(relativePoint.getComponent(), relativePoint.getPoint()));
      }
    });
  }
  else {
    myHintContainer = editor.getContentComponent();
    getHintContainerShowPoint().doWhenDone((Consumer<RelativePoint>)rp -> {
      Point p = rp.getPointOn(myHintContainer).getPoint();
      final HintHint hintInfo = new HintHint(editor, p);
      HintManagerImpl.getInstanceImpl().showEditorHint(myHint, editor, p, HintManager.HIDE_BY_ESCAPE, 0, true, hintInfo);
    });
  }

  rebuildAndSelectTail(true);
}