private void recalculateMaxValues() { myIdxLeft = widestEditor(myLeftEditors); final Editor leftEditor = myLeftEditors.get(myIdxLeft); final int wholeWidth = leftEditor.getContentComponent().getWidth(); final Rectangle va = leftEditor.getScrollingModel().getVisibleArea(); final int visibleLeft = leftEditor.xyToVisualPosition(new Point(va.width, 0)).column; myMaxColumnsLeft = (int) (visibleLeft * ((double) wholeWidth / va.getWidth())); myIdxRight = widestEditor(myRightEditors); final Editor rightEditor = myRightEditors.get(myIdxRight); final int wholeWidthRight = rightEditor.getContentComponent().getWidth(); final Rectangle vaRight = rightEditor.getScrollingModel().getVisibleArea(); final int visibleRight = rightEditor.xyToVisualPosition(new Point(va.width, 0)).column; myMaxColumnsRight = (int) (visibleRight * ((double) wholeWidthRight / vaRight.getWidth())); myByLeft = !(myMaxColumnsLeft <= visibleLeft); if (!myByLeft) { // check right editor if (myLeftScroll.getVisibleAmount() != visibleRight) { myLeftScroll.setVisibleAmount(visibleRight); } myLeftScroll.setMaximum(myMaxColumnsRight); } else { if (myLeftScroll.getVisibleAmount() != visibleLeft) { myLeftScroll.setVisibleAmount(visibleLeft); } myLeftScroll.setMaximum(myMaxColumnsLeft); } }
@NotNull private static DataContext createEditorContext(@NotNull Editor editor) { Object e = editor; Object hostEditor = editor instanceof EditorWindow ? ((EditorWindow) editor).getDelegate() : editor; Map<String, Object> map = ContainerUtil.newHashMap( Pair.create(CommonDataKeys.HOST_EDITOR.getName(), hostEditor), Pair.createNonNull(CommonDataKeys.EDITOR.getName(), e)); DataContext parent = DataManager.getInstance().getDataContext(editor.getContentComponent()); return SimpleDataContext.getSimpleContext(map, parent); }
private int widestEditor(final List<Editor> editors) { int maxWidth = 0; int idxMax = 0; for (int i = 0; i < editors.size(); i++) { Editor editor = editors.get(i); final int wholeWidth = editor.getContentComponent().getWidth(); if (wholeWidth > maxWidth) { maxWidth = wholeWidth; idxMax = i; } } return idxMax; }
public static void performTypingAction(Editor editor, char c) { EditorActionManager actionManager = EditorActionManager.getInstance(); if (c == BACKSPACE_FAKE_CHAR) { executeAction(editor, IdeActions.ACTION_EDITOR_BACKSPACE); } else if (c == SMART_ENTER_FAKE_CHAR) { executeAction(editor, IdeActions.ACTION_EDITOR_COMPLETE_STATEMENT); } else if (c == SMART_LINE_SPLIT_CHAR) { executeAction(editor, IdeActions.ACTION_EDITOR_SPLIT); } else if (c == '\n') { executeAction(editor, IdeActions.ACTION_EDITOR_ENTER); } else { TypedAction action = actionManager.getTypedAction(); action.actionPerformed( editor, c, DataManager.getInstance().getDataContext(editor.getContentComponent())); } }
@Override protected void processKeyEvent(@NotNull final KeyEvent e) { final char keyChar = e.getKeyChar(); if (keyChar == KeyEvent.VK_ENTER || keyChar == KeyEvent.VK_TAB) { IdeFocusManager.getInstance(myProject) .requestFocus(myEditor.getContentComponent(), true) .doWhenDone( new Runnable() { @Override public void run() { IdeEventQueue.getInstance().getKeyEventDispatcher().dispatchKeyEvent(e); } }); return; } super.processKeyEvent(e); }
public boolean showLookup() { ApplicationManager.getApplication().assertIsDispatchThread(); checkValid(); LOG.assertTrue(!myShown); myShown = true; myStampShown = System.currentTimeMillis(); if (ApplicationManager.getApplication().isUnitTestMode()) return true; if (!myEditor.getContentComponent().isShowing()) { hide(); return false; } myAdComponent.showRandomText(); myUi = new LookupUi(this, myAdComponent, myList, myProject); myUi.setCalculating(myCalculating); Point p = myUi.calculatePosition().getLocation(); try { HintManagerImpl.getInstanceImpl() .showEditorHint( this, myEditor, p, HintManager.HIDE_BY_ESCAPE | HintManager.UPDATE_BY_SCROLLING, 0, false, HintManagerImpl.createHintHint(myEditor, p, this, HintManager.UNDER) .setAwtTooltip(false)); } catch (Exception e) { LOG.error(e); } if (!isVisible() || !myList.isShowing()) { hide(); return false; } DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(this); return true; }
@Override public RelativePoint recalculateLocation(final Balloon object) { FindResult cursor = mySearchResults.getCursor(); if (cursor == null) return null; final TextRange cur = cursor; int startOffset = cur.getStartOffset(); int endOffset = cur.getEndOffset(); if (startOffset >= myEditor.getDocument().getTextLength()) { if (!object.isDisposed()) { requestBalloonHiding(object); } return null; } if (!SearchResults.insideVisibleArea(myEditor, cur)) { requestBalloonHiding(object); VisibleAreaListener visibleAreaListener = new VisibleAreaListener() { @Override public void visibleAreaChanged(VisibleAreaEvent e) { if (SearchResults.insideVisibleArea(myEditor, cur)) { showReplacementPreview(); final VisibleAreaListener visibleAreaListener = this; final boolean remove = myVisibleAreaListenersToRemove.remove(visibleAreaListener); if (remove) { myEditor.getScrollingModel().removeVisibleAreaListener(visibleAreaListener); } } } }; myEditor.getScrollingModel().addVisibleAreaListener(visibleAreaListener); myVisibleAreaListenersToRemove.add(visibleAreaListener); } Point startPoint = myEditor.visualPositionToXY(myEditor.offsetToVisualPosition(startOffset)); Point endPoint = myEditor.visualPositionToXY(myEditor.offsetToVisualPosition(endOffset)); Point point = new Point((startPoint.x + endPoint.x) / 2, startPoint.y); return new RelativePoint(myEditor.getContentComponent(), point); }
public JComponent getPreferredFocusableComponent() { return myElements.length > 1 ? myFileChooser : myEditor.getContentComponent(); }
public ReplacementBalloonPositionTracker(Editor editor) { super(editor.getContentComponent()); myEditor = editor; }
private void addListeners() { myEditor .getDocument() .addDocumentListener( new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { if (!myChangeGuard && !myFinishing) { hide(); } } }, this); final CaretListener caretListener = new CaretAdapter() { @Override public void caretPositionChanged(CaretEvent e) { if (!myChangeGuard && !myFinishing) { hide(); } } }; final SelectionListener selectionListener = new SelectionListener() { @Override public void selectionChanged(final SelectionEvent e) { if (!myChangeGuard && !myFinishing) { hide(); } } }; final EditorMouseListener mouseListener = new EditorMouseAdapter() { @Override public void mouseClicked(EditorMouseEvent e) { e.consume(); hide(); } }; myEditor.getCaretModel().addCaretListener(caretListener); myEditor.getSelectionModel().addSelectionListener(selectionListener); myEditor.addEditorMouseListener(mouseListener); Disposer.register( this, new Disposable() { @Override public void dispose() { myEditor.getCaretModel().removeCaretListener(caretListener); myEditor.getSelectionModel().removeSelectionListener(selectionListener); myEditor.removeEditorMouseListener(mouseListener); } }); JComponent editorComponent = myEditor.getContentComponent(); if (editorComponent.isShowing()) { Disposer.register( this, new UiNotifyConnector( editorComponent, new Activatable() { @Override public void showNotify() {} @Override public void hideNotify() { hideLookup(false); } })); } myList.addListSelectionListener( new ListSelectionListener() { private LookupElement oldItem = null; @Override public void valueChanged(@NotNull ListSelectionEvent e) { if (!myUpdating) { final LookupElement item = getCurrentItem(); fireCurrentItemChanged(oldItem, item); oldItem = item; } } }); new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent e, int clickCount) { setFocusDegree(FocusDegree.FOCUSED); markSelectionTouched(); if (clickCount == 2) { CommandProcessor.getInstance() .executeCommand( myProject, new Runnable() { @Override public void run() { finishLookup(NORMAL_SELECT_CHAR); } }, "", null); } return true; } }.installOn(myList); }