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

The following examples show how to use com.intellij.openapi.editor.ex.EditorEx. 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: TextEditorComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
public TextEditorComponent(@Nonnull final Project project, @Nonnull final VirtualFile file, @Nonnull final DesktopTextEditorImpl textEditor) {
  super(new BorderLayout(), textEditor);

  myProject = project;
  myFile = file;
  myTextEditor = textEditor;

  myDocument = FileDocumentManager.getInstance().getDocument(myFile);
  LOG.assertTrue(myDocument != null);
  myDocument.addDocumentListener(new MyDocumentListener(), this);

  myEditor = createEditor();
  add(myEditor.getComponent(), BorderLayout.CENTER);
  myModified = isModifiedImpl();
  myValid = isEditorValidImpl();
  LOG.assertTrue(myValid);

  MyVirtualFileListener myVirtualFileListener = new MyVirtualFileListener();
  myFile.getFileSystem().addVirtualFileListener(myVirtualFileListener);
  Disposer.register(this, () -> myFile.getFileSystem().removeVirtualFileListener(myVirtualFileListener));
  MessageBusConnection myConnection = project.getMessageBus().connect(this);
  myConnection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener());

  myEditorHighlighterUpdater = new EditorHighlighterUpdater(myProject, this, (EditorEx)myEditor, myFile);
}
 
Example #2
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private Runnable doExecute() {
  EditorEx editor = getPossiblyInjectedEditor();
  int offset = getOffset(editor);

  PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
  if (file == null) return createDisposalContinuation();

  final Info info;
  final DocInfo docInfo;
  try {
    info = getInfoAt(editor, file, offset, myBrowseMode);
    if (info == null) return createDisposalContinuation();
    docInfo = info.getInfo();
  }
  catch (IndexNotReadyException e) {
    showDumbModeNotification(myProject);
    return createDisposalContinuation();
  }

  LOG.debug("Obtained info about element under cursor");
  return () -> addHighlighterAndShowHint(info, docInfo, editor);
}
 
Example #3
Source File: SelectionQuotingTypedHandlerTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testRuby7852ErrantEditor() {
  myFixture.configureByText(PlainTextFileType.INSTANCE, "\"aaa\"\nbbb\n\n");
  myFixture.getEditor().getCaretModel().moveToOffset(0);
  myFixture.getEditor().getSelectionModel().setSelection(0, 5);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), '\'', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult("'aaa'\nbbb\n\n");

  myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getLineStartOffset(3));
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), 'A', ((EditorEx)myFixture.getEditor()).getDataContext());
      typedAction.actionPerformed(myFixture.getEditor(), 'B', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.checkResult("'aaa'\nbbb\n\nAB");
}
 
Example #4
Source File: SwapSelectionBoundariesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Editor editor, DataContext dataContext) {
  if (!(editor instanceof EditorEx)) {
    return;
  }
  final SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection()) {
    return;
  }

  EditorEx editorEx = (EditorEx)editor;
  final int start = selectionModel.getSelectionStart();
  final int end = selectionModel.getSelectionEnd();
  final CaretModel caretModel = editor.getCaretModel();
  boolean moveToEnd = caretModel.getOffset() == start;
  editorEx.setStickySelection(false);
  editorEx.setStickySelection(true);
  if (moveToEnd) {
    caretModel.moveToOffset(end);
  }
  else {
    caretModel.moveToOffset(start);
  }
}
 
Example #5
Source File: EditorFragmentComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @param component Should be provided if editor is not currently displayable.
 *                  Makes for correct rendering on multi-monitor configurations.
 */
private static EditorFragmentComponent createEditorFragmentComponent(Component component,
                                                                     Editor editor,
                                                                     int startLine,
                                                                     int endLine,
                                                                     boolean showFolding,
                                                                     boolean showGutter,
                                                                     boolean useCaretRowBackground) {
  final EditorEx editorEx = (EditorEx)editor;
  final Color old = editorEx.getBackgroundColor();
  Color backColor = getBackgroundColor(editor, useCaretRowBackground);
  editorEx.setBackgroundColor(backColor);
  EditorFragmentComponent fragmentComponent = new EditorFragmentComponent(component, editorEx, startLine, endLine, showFolding, showGutter);
  fragmentComponent.setBackground(backColor);

  editorEx.setBackgroundColor(old);
  return fragmentComponent;
}
 
Example #6
Source File: ExportToFileUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final Document document = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true);
  ((DocumentImpl)document).setAcceptSlashR(true);

  myTextArea = EditorFactory.getInstance().createEditor(document, myProject, PlainTextFileType.INSTANCE, true);
  final EditorSettings settings = myTextArea.getSettings();
  settings.setLineNumbersShown(false);
  settings.setLineMarkerAreaShown(false);
  settings.setFoldingOutlineShown(false);
  settings.setRightMarginShown(false);
  settings.setAdditionalLinesCount(0);
  settings.setAdditionalColumnsCount(0);
  settings.setAdditionalPageAtBottom(false);
  ((EditorEx)myTextArea).setBackgroundColor(UIUtil.getInactiveTextFieldBackgroundColor());
  return myTextArea.getComponent();
}
 
Example #7
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 #8
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 #9
Source File: FoldingPopupManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseMoved(@Nonnull EditorMouseEvent e) {
  myAlarm.cancelAllRequests();
  Editor editor = e.getEditor();
  if (editor.getUserData(DISABLED) != null) return;
  if (e.getArea() == EditorMouseEventArea.EDITING_AREA) {
    MouseEvent mouseEvent = e.getMouseEvent();
    Point point = mouseEvent.getPoint();
    FoldRegion fold = ((EditorEx)editor).getFoldingModel().getFoldingPlaceholderAt(point);
    TooltipController controller = TooltipController.getInstance();
    if (fold != null && !fold.shouldNeverExpand()) {
      myAlarm.addRequest(() -> {
        if (editor.getUserData(DISABLED) != null || !editor.getComponent().isShowing() || !fold.isValid() || fold.isExpanded()) return;
        DocumentFragment range = createDocumentFragment(fold);
        Point p = SwingUtilities.convertPoint((Component)mouseEvent.getSource(), point, editor.getComponent().getRootPane().getLayeredPane());
        controller.showTooltip(editor, p, new DocumentFragmentTooltipRenderer(range), false, FOLDING_TOOLTIP_GROUP);
      }, TOOLTIP_DELAY_MS);
    }
    else {
      controller.cancelTooltip(FOLDING_TOOLTIP_GROUP, mouseEvent, true);
    }
  }
}
 
Example #10
Source File: ActiveEditorsOutlineService.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Gets all of the {@link EditorEx} editors open to Dart files.
 */
public List<EditorEx> getActiveDartEditors() {
  if (project.isDisposed()) {
    return Collections.emptyList();
  }
  final FileEditor[] editors = FileEditorManager.getInstance(project).getSelectedEditors();
  final List<EditorEx> dartEditors = new ArrayList<>();
  for (FileEditor fileEditor : editors) {
    if (!(fileEditor instanceof TextEditor)) continue;
    final TextEditor textEditor = (TextEditor)fileEditor;
    final Editor editor = textEditor.getEditor();
    if (editor instanceof EditorEx && !editor.isDisposed()) {
      dartEditors.add((EditorEx)editor);
    }
  }
  return dartEditors;
}
 
Example #11
Source File: IdeUtils.java    From StringManipulation with Apache License 2.0 6 votes vote down vote up
public static EditorImpl createEditorPreview(String text, boolean editable) {
	EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
	ColorAndFontOptions options = new ColorAndFontOptions();
	options.reset();
	options.selectScheme(scheme.getName());

	EditorFactory editorFactory = EditorFactory.getInstance();
	Document editorDocument = editorFactory.createDocument(text);
	EditorEx editor = (EditorEx) (editable ? editorFactory.createEditor(editorDocument) : editorFactory.createViewer(editorDocument));
	editor.setColorsScheme(scheme);
	EditorSettings settings = editor.getSettings();
	settings.setLineNumbersShown(true);
	settings.setWhitespacesShown(false);
	settings.setLineMarkerAreaShown(false);
	settings.setIndentGuidesShown(false);
	settings.setFoldingOutlineShown(false);
	settings.setAdditionalColumnsCount(0);
	settings.setAdditionalLinesCount(0);
	settings.setRightMarginShown(false);

	return (EditorImpl) editor;
}
 
Example #12
Source File: GoalEditor.java    From MavenHelper with Apache License 2.0 6 votes vote down vote up
@NotNull
private static Editor createEditor() {
	EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
	ColorAndFontOptions options = new ColorAndFontOptions();
	options.reset();
	options.selectScheme(scheme.getName());
	EditorFactory editorFactory = EditorFactory.getInstance();
	Document editorDocument = editorFactory.createDocument("");


	EditorEx editor = (EditorEx) (true ? editorFactory.createEditor(editorDocument) : editorFactory.createViewer(editorDocument));
	editor.setColorsScheme(scheme);
	EditorSettings settings = editor.getSettings();
	settings.setLineNumbersShown(false);
	settings.setUseSoftWraps(true);
	settings.setWhitespacesShown(false);
	settings.setLineMarkerAreaShown(false);
	settings.setIndentGuidesShown(false);
	settings.setFoldingOutlineShown(false);
	settings.setAdditionalColumnsCount(0);
	settings.setAdditionalLinesCount(0);
	settings.setRightMarginShown(false);

	return editor;
}
 
Example #13
Source File: DiffLineSeparatorRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void paint(Editor editor, Graphics g, Rectangle r) {
  if (!myCondition.get()) return;

  int y = r.y;
  int lineHeight = myEditor.getLineHeight();

  EditorGutterComponentEx gutter = ((EditorEx)editor).getGutterComponentEx();
  int annotationsOffset = gutter.getAnnotationsAreaOffset();
  int annotationsWidth = gutter.getAnnotationsAreaWidth();
  if (annotationsWidth != 0) {
    g.setColor(editor.getColorsScheme().getColor(EditorColors.GUTTER_BACKGROUND));
    g.fillRect(annotationsOffset, y, annotationsWidth, lineHeight);
  }

  draw(g, 0, y, lineHeight, myEditor.getColorsScheme());
}
 
Example #14
Source File: PromptConsole.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
private void setupOutputEditor() {
    ((EditorEx) m_outputEditor).getContentComponent().setFocusCycleRoot(false);
    ((EditorEx) m_outputEditor).setHorizontalScrollbarVisible(true);
    ((EditorEx) m_outputEditor).setVerticalScrollbarVisible(true);
    ((EditorEx) m_outputEditor).getScrollPane().setBorder(null);

    EditorSettings editorSettings = ((EditorEx) m_outputEditor).getSettings();
    editorSettings.setLineNumbersShown(false);
    editorSettings.setIndentGuidesShown(false);
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setFoldingOutlineShown(true);
    editorSettings.setRightMarginShown(false);
    editorSettings.setVirtualSpace(false);
    editorSettings.setAdditionalPageAtBottom(false);
    editorSettings.setAdditionalLinesCount(0);
    editorSettings.setAdditionalColumnsCount(0);
    editorSettings.setLineCursorWidth(1);
    editorSettings.setCaretRowShown(false);

    // output only editor
    m_outputEditor.setRendererMode(true);

    // tiny separation between output and prompt
    m_outputEditor.getComponent().setBorder(new SideBorder(JBColor.LIGHT_GRAY, SideBorder.BOTTOM));
}
 
Example #15
Source File: ActiveEditorsOutlineService.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Gets all of the {@link EditorEx} editors open to Dart files.
 */
public List<EditorEx> getActiveDartEditors() {
  if (project.isDisposed()) {
    return Collections.emptyList();
  }
  final FileEditor[] editors = FileEditorManager.getInstance(project).getSelectedEditors();
  final List<EditorEx> dartEditors = new ArrayList<>();
  for (FileEditor fileEditor : editors) {
    if (!(fileEditor instanceof TextEditor)) continue;
    final TextEditor textEditor = (TextEditor)fileEditor;
    final Editor editor = textEditor.getEditor();
    if (editor instanceof EditorEx && !editor.isDisposed()) {
      dartEditors.add((EditorEx)editor);
    }
  }
  return dartEditors;
}
 
Example #16
Source File: TemplateEditorUI.java    From CodeGen with MIT License 6 votes vote down vote up
public void refresh(@NotNull CodeTemplate codeTemplate) {
    id.setText(codeTemplate.getId());
    displayTextField.setText(codeTemplate.getDisplay());
    extensionTextField.setText(codeTemplate.getExtension());
    filenameTextField.setText(codeTemplate.getFilename());
    subPathTextField.setText(codeTemplate.getSubPath());
    orderTextField.setText(StringUtils.nullOr(codeTemplate.getOrder(), 1) + "");
    resourceCheckBox.setSelected(StringUtils.nullOr(codeTemplate.getResources(), false));
    // create editor
    String template = StringUtils.isEmpty(codeTemplate.getTemplate()) ? "" : codeTemplate.getTemplate();
    String extension = StringUtils.isEmpty(codeTemplate.getExtension()) ? "vm" : codeTemplate.getExtension();
    if (editor == null) {
        editor = createEditor(template, extension);
    } else {
        ((EditorEx) editor).setHighlighter(
                highlighterFactory.createEditorHighlighter(null, FileProviderFactory.getFileType(extension)));
        editor.getDocument().setText(template);
    }
    this.rootPanel.repaint();
}
 
Example #17
Source File: EditorTextField.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void setDocument(Document document) {
  if (myDocument != null) {
    uninstallDocumentListener(true);
  }

  myDocument = document;
  installDocumentListener();
  if (myEditor != null) {
    //MainWatchPanel watches the oldEditor's focus in order to remove debugger combobox when focus is lost
    //we should first transfer focus to new oldEditor and only then remove current oldEditor
    //MainWatchPanel check that oldEditor.getParent == newEditor.getParent and does not remove oldEditor in such cases

    boolean isFocused = isFocusOwner();
    EditorEx newEditor = createEditor();
    releaseEditor(myEditor);
    myEditor = newEditor;
    add(myEditor.getComponent(), BorderLayout.CENTER);

    validate();
    if (isFocused) {
      myEditor.getContentComponent().requestFocus();
    }
  }
}
 
Example #18
Source File: CommentByBlockCommentHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean breaksExistingComment(int offset, boolean includingAfterLineComment) {
  if (!(myCommenter instanceof CodeDocumentationAwareCommenter) || !(myEditor instanceof EditorEx) || offset == 0) return false;
  CodeDocumentationAwareCommenter commenter = (CodeDocumentationAwareCommenter)myCommenter;
  HighlighterIterator it = ((EditorEx)myEditor).getHighlighter().createIterator(offset - 1);
  IElementType tokenType = it.getTokenType();
  return (tokenType != null &&
          (it.getEnd() > offset &&
           (tokenType == commenter.getLineCommentTokenType() || tokenType == commenter.getBlockCommentTokenType() || tokenType == commenter.getDocumentationCommentTokenType()) ||
           includingAfterLineComment && it.getEnd() == offset && tokenType == commenter.getLineCommentTokenType() && !(commenter instanceof CommenterWithLineSuffix)));
}
 
Example #19
Source File: ApplyPatchChange.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void createResultHighlighters() {
  LineRange resultRange = getResultRange();
  if (resultRange == null) return;
  EditorEx editor = myViewer.getResultEditor();

  int startLine = resultRange.start;
  int endLine = resultRange.end;

  TextDiffType type = getDiffType();
  boolean resolved = isRangeApplied();

  myHighlighters.addAll(DiffDrawUtil.createHighlighter(editor, startLine, endLine, type, false, resolved, false));
}
 
Example #20
Source File: PopupPositionManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void positionPopupInBestPosition(final JBPopup hint, @Nullable final Editor editor, @Nullable DataContext dataContext, @Nonnull Position... relationToExistingPopup) {
  final LookupEx lookup = LookupManager.getActiveLookup(editor);
  if (lookup != null && lookup.getCurrentItem() != null && lookup.getComponent().isShowing()) {
    new PositionAdjuster(lookup.getComponent()).adjust(hint, relationToExistingPopup);
    lookup.addLookupListener(new LookupListener() {
      @Override
      public void lookupCanceled(@Nonnull LookupEvent event) {
        if (hint.isVisible()) {
          hint.cancel();
        }
      }
    });
    return;
  }

  final PositionAdjuster positionAdjuster = createPositionAdjuster(hint);
  if (positionAdjuster != null) {
    positionAdjuster.adjust(hint, relationToExistingPopup);
    return;
  }

  if (editor != null && editor.getComponent().isShowing() && editor instanceof EditorEx) {
    dataContext = ((EditorEx)editor).getDataContext();
  }

  if (dataContext != null) {
    if (hint.canShow()) {
      hint.showInBestPositionFor(dataContext);
    }
    else {
      hint.setLocation(hint.getBestPositionFor(dataContext));
    }
  }
}
 
Example #21
Source File: EditorComboBox.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
  if (!((EditorEx)myEditorField.getEditor()).processKeyTyped(e)) {
    return super.processKeyBinding(ks, e, condition, pressed);
  }
  return true;
}
 
Example #22
Source File: LineStatusMarkerPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private EditorFragmentComponent createEditorComponent(@Nullable FileType fileType, @javax.annotation.Nullable List<DiffFragment> wordDiff) {
  if (myRange.getType() == Range.INSERTED) return null;

  EditorEx uEditor = (EditorEx)EditorFactory.getInstance().createViewer(myTracker.getVcsDocument(), myTracker.getProject());
  uEditor.setColorsScheme(myEditor.getColorsScheme());

  DiffUtil.setEditorCodeStyle(myTracker.getProject(), uEditor, fileType);

  EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
  uEditor.setHighlighter(highlighterFactory.createEditorHighlighter(myTracker.getProject(), getFileName(myTracker.getDocument())));

  if (wordDiff != null) {
    int vcsStartShift = myTracker.getVcsTextRange(myRange).getStartOffset();
    for (DiffFragment fragment : wordDiff) {
      int vcsStart = vcsStartShift + fragment.getStartOffset1();
      int vcsEnd = vcsStartShift + fragment.getEndOffset1();
      TextDiffType type = getDiffType(fragment);

      DiffDrawUtil.createInlineHighlighter(uEditor, vcsStart, vcsEnd, type);
    }
  }

  EditorFragmentComponent fragmentComponent =
          EditorFragmentComponent.createEditorFragmentComponent(uEditor, myRange.getVcsLine1(), myRange.getVcsLine2(), false, false);

  EditorFactory.getInstance().releaseEditor(uEditor);

  return fragmentComponent;
}
 
Example #23
Source File: ThreesideTextDiffViewerEx.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void consume(Graphics g) {
  EditorEx editor1 = getEditor(ThreeSide.BASE);
  EditorEx editor2 = getEditor(ThreeSide.RIGHT);

  int width = editor1.getScrollPane().getVerticalScrollBar().getWidth();
  DiffDividerDrawUtil.paintPolygonsOnScrollbar((Graphics2D)g, width, editor1, editor2, myPaintable);

  myFoldingModel.paintOnScrollbar((Graphics2D)g, width);
}
 
Example #24
Source File: ConsoleExecuteAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public final void update(@Nonnull AnActionEvent e) {
  EditorEx editor = myConsoleView.getConsoleEditor();
  boolean enabled = !editor.isRendererMode() && isEnabled() &&
                    (myExecuteActionHandler.isEmptyCommandExecutionAllowed() || !StringUtil.isEmptyOrSpaces(editor.getDocument().getCharsSequence()));
  if (enabled) {
    Lookup lookup = LookupManager.getActiveLookup(editor);
    // we should check getCurrentItem() also - fast typing could produce outdated lookup, such lookup reports isCompletion() true
    enabled = lookup == null || !lookup.isCompletion() || lookup.getCurrentItem() == null ||
              (lookup instanceof LookupImpl && ((LookupImpl)lookup).getFocusDegree() == LookupImpl.FocusDegree.UNFOCUSED);
  }

  e.getPresentation().setEnabled(enabled);
}
 
Example #25
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
static EditorHighlighter getLazyParsableHighlighterIfAny(Project project, Editor editor, PsiFile psiFile) {
  if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) {
    return ((EditorEx)editor).getHighlighter();
  }
  PsiElement elementAt = psiFile.findElementAt(editor.getCaretModel().getOffset());
  for (PsiElement e : SyntaxTraverser.psiApi().parents(elementAt).takeWhile(Conditions.notEqualTo(psiFile))) {
    if (!(PsiUtilCore.getElementType(e) instanceof ILazyParseableElementType)) continue;
    Language language = ILazyParseableElementType.LANGUAGE_KEY.get(e.getNode());
    if (language == null) continue;
    TextRange range = e.getTextRange();
    final int offset = range.getStartOffset();
    SyntaxHighlighter syntaxHighlighter =
            SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, psiFile.getVirtualFile());
    LexerEditorHighlighter highlighter = new LexerEditorHighlighter(syntaxHighlighter, editor.getColorsScheme()) {
      @Nonnull
      @Override
      public HighlighterIterator createIterator(int startOffset) {
        return new HighlighterIteratorWrapper(super.createIterator(Math.max(startOffset - offset, 0))) {
          @Override
          public int getStart() {
            return super.getStart() + offset;
          }

          @Override
          public int getEnd() {
            return super.getEnd() + offset;
          }
        };
      }
    };
    highlighter.setText(editor.getDocument().getText(range));
    return highlighter;
  }
  return ((EditorEx)editor).getHighlighter();
}
 
Example #26
Source File: ShowTextPopupHyperlinkInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(Project project) {
  Application.get().invokeLater(() -> {
    Document document = EditorFactory.getInstance().createDocument(StringUtil.convertLineSeparators(myText));
    EditorTextField textField = new EditorTextField(document, project, PlainTextFileType.INSTANCE, true, false) {
      @Override
      protected EditorEx createEditor() {
        EditorEx editor = super.createEditor();
        editor.getScrollPane().setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        editor.getScrollPane().setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        editor.getSettings().setUseSoftWraps(true);
        return editor;
      }
    };

    Window frame = TargetAWT.to(WindowManager.getInstance().getWindow(project));
    if(frame != null) {
      Dimension size = frame.getSize();
      if(size != null) {
        textField.setPreferredSize(new Dimension(size.width / 2, size.height / 2));
      }
    }

    JBPopupFactory.getInstance()
            .createComponentPopupBuilder(textField, textField)
            .setTitle(myTitle)
            .setResizable(true)
            .setMovable(true)
            .setRequestFocus(true)
            .createPopup()
            .showCenteredInCurrentWindow(project);
  });
}
 
Example #27
Source File: DiffPanelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void initEditorSettings(@Nullable Editor editor) {
  if (editor == null) {
    return;
  }
  Project project = editor.getProject();
  DiffMergeSettings settings = project == null ? null : ServiceManager.getService(project, DiffToolSettings.class);
  for (DiffMergeEditorSetting property : DiffMergeEditorSetting.values()) {
    property.apply(editor, settings == null ? property.getDefault() : settings.getPreference(property));
  }
  ((EditorEx)editor).getGutterComponentEx().setShowDefaultGutterPopup(false);
}
 
Example #28
Source File: MergePanel2.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void setHighlighterSettings(@Nullable EditorColorsScheme settings, @Nonnull EditorPlace place) {
  if (settings == null) {
    settings = EditorColorsManager.getInstance().getGlobalScheme();
  }
  Editor editor = place.getEditor();
  DiffEditorState editorState = place.getState();
  if (editor != null) {
    ((EditorEx)editor).setHighlighter(EditorHighlighterFactory.getInstance().
            createEditorHighlighter(editorState.getFileType(), settings, editorState.getProject()));
  }
}
 
Example #29
Source File: TypedHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isOpeningQuote(@Nonnull Editor editor, @Nonnull QuoteHandler quoteHandler, int offset) {
  HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset);
  if (iterator.atEnd()) {
    LOG.assertTrue(false);
    return false;
  }

  return quoteHandler.isOpeningQuote(iterator, offset);
}
 
Example #30
Source File: EditorFragmentComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static LightweightHint showEditorFragmentHint(Editor editor, TextRange range, boolean showFolding, boolean hideByAnyKey) {
  if (!(editor instanceof EditorEx)) return null;
  JRootPane rootPane = editor.getComponent().getRootPane();
  if (rootPane == null) return null;
  JLayeredPane layeredPane = rootPane.getLayeredPane();
  int lineHeight = editor.getLineHeight();
  int overhang = editor.getScrollingModel().getVisibleArea().y - editor.logicalPositionToXY(editor.offsetToLogicalPosition(range.getEndOffset())).y;
  int yRelative = overhang > 0 && overhang < lineHeight ? lineHeight - overhang + JBUIScale.scale(LINE_BORDER_THICKNESS + EMPTY_BORDER_THICKNESS) : 0;
  Point point = SwingUtilities.convertPoint(((EditorEx)editor).getScrollPane().getViewport(), -2, yRelative, layeredPane);
  return showEditorFragmentHintAt(editor, range, point.y, true, showFolding, hideByAnyKey, true, false);
}