Java 类com.intellij.openapi.editor.ex.util.EditorUtil 实例源码

项目:intellij-ce-playground    文件:bigFile.java   
private void paintAfterLineEndBackgroundSegments(@NotNull Graphics g,
                                                 @NotNull IterationState iterationState,
                                                 @NotNull Point position,
                                                 @NotNull Color defaultBackground,
                                                 int lineHeight) {
  while (iterationState.hasPastLineEndBackgroundSegment()) {
    TextAttributes backgroundAttributes = iterationState.getPastLineEndBackgroundAttributes();
    int width = EditorUtil.getSpaceWidth(backgroundAttributes.getFontType(), this) * iterationState.getPastLineEndBackgroundSegmentWidth();
    Color color = getBackgroundColor(backgroundAttributes);
    if (color != null && !color.equals(defaultBackground)) {
      g.setColor(color);
      g.fillRect(position.x, position.y, width, lineHeight);
    }
    position.x += width;
    iterationState.advanceToNextPastLineEndBackgroundSegment();
  }
}
项目:intellij-ce-playground    文件:bigFile.java   
private int getTextSegmentWidth(@NotNull CharSequence text,
                                int start,
                                int end,
                                int xStart,
                                @JdkConstants.FontStyle int fontType,
                                @NotNull Rectangle clip) {
  int x = xStart;

  for (int i = start; i < end && xStart < clip.x + clip.width; i++) {
    char c = text.charAt(i);
    if (c == '\t') {
      x = EditorUtil.nextTabStop(x, this);
    }
    else {
      x += EditorUtil.charWidth(c, fontType, this);
    }
    if (x > clip.x + clip.width) {
      break;
    }
  }
  return x - xStart;
}
项目:intellij-ce-playground    文件:bigFile.java   
public Dimension getPreferredSize() {
  if (myUseNewRendering) return myView.getPreferredSize();
  if (ourIsUnitTestMode && getUserData(DO_DOCUMENT_UPDATE_TEST) == null) {
    return new Dimension(1, 1);
  }

  final Dimension draft = getSizeWithoutCaret();
  final int additionalSpace = shouldRespectAdditionalColumns()
                              ? mySettings.getAdditionalColumnsCount() * EditorUtil.getSpaceWidth(Font.PLAIN, this)
                              : 0;

  if (!myDocument.isInBulkUpdate()) {
    for (Caret caret : myCaretModel.getAllCarets()) {
      if (caret.isUpToDate()) {
        int caretX = visualPositionToXY(caret.getVisualPosition()).x;
        draft.width = Math.max(caretX, draft.width);
      }
    }
  }
  draft.width += additionalSpace;
  return draft;
}
项目:intellij-ce-playground    文件:bigFile.java   
@Override
public void setPrefixTextAndAttributes(@Nullable String prefixText, @Nullable TextAttributes attributes) {
  myPrefixText = prefixText == null ? null : prefixText.toCharArray();
  myPrefixAttributes = attributes;
  myPrefixWidthInPixels = 0;
  if (myPrefixText != null) {
    for (char c : myPrefixText) {
      LOG.assertTrue(myPrefixAttributes != null);
      if (myPrefixAttributes != null) {
        myPrefixWidthInPixels += EditorUtil.charWidth(c, myPrefixAttributes.getFontType(), this);
      }
    }
  }
  mySoftWrapModel.recalculate();
  if (myUseNewRendering) myView.setPrefix(prefixText, attributes);
}
项目:intellij-ce-playground    文件:SoftWrapModelImpl.java   
/**
 * Called on editor settings change. Current model is expected to drop all cached information about the settings if any.
 */
public void reinitSettings() {
  boolean softWrapsUsedBefore = myUseSoftWraps;
  myUseSoftWraps = areSoftWrapsEnabledInEditor();

  int tabWidthBefore = myTabWidth;
  myTabWidth = EditorUtil.getTabSize(myEditor);

  boolean fontsChanged = false;
  if (!myFontPreferences.equals(myEditor.getColorsScheme().getFontPreferences())
      && myEditorTextRepresentationHelper instanceof DefaultEditorTextRepresentationHelper) {
    fontsChanged = true;
    myEditor.getColorsScheme().getFontPreferences().copyTo(myFontPreferences);
    ((DefaultEditorTextRepresentationHelper)myEditorTextRepresentationHelper).clearSymbolWidthCache();
    myPainter.reinit();
  }

  if ((myUseSoftWraps ^ softWrapsUsedBefore) || (tabWidthBefore >= 0 && myTabWidth != tabWidthBefore) || fontsChanged) {
    myApplianceManager.reset();
    myDeferredFoldRegions.clear();
    myStorage.removeAll();
    myEditor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
  }
}
项目:intellij-ce-playground    文件:bigFile.java   
@Override
public int getMaxWidthInRange(int startOffset, int endOffset) {
  if (myUseNewRendering) return myView.getMaxWidthInRange(startOffset, endOffset);
  int width = 0;
  int start = offsetToVisualLine(startOffset);
  int end = offsetToVisualLine(endOffset);

  for (int i = start; i <= end; i++) {
    int lastColumn = EditorUtil.getLastVisualLineColumnNumber(this, i) + 1;
    int lineWidth = visualPositionToXY(new VisualPosition(i, lastColumn)).x;

    if (lineWidth > width) {
      width = lineWidth;
    }
  }

  return width;
}
项目:intellij-ce-playground    文件:bigFile.java   
private void paintAfterLineEndBackgroundSegments(@NotNull Graphics g,
                                                 @NotNull IterationState iterationState,
                                                 @NotNull Point position,
                                                 @NotNull Color defaultBackground,
                                                 int lineHeight) {
  while (iterationState.hasPastLineEndBackgroundSegment()) {
    TextAttributes backgroundAttributes = iterationState.getPastLineEndBackgroundAttributes();
    int width =
      EditorUtil.getSpaceWidth(backgroundAttributes.getFontType(), this) * iterationState.getPastLineEndBackgroundSegmentWidth();
    Color color = getBackgroundColor(backgroundAttributes);
    if (color != null && !color.equals(defaultBackground)) {
      g.setColor(color);
      g.fillRect(position.x, position.y, width, lineHeight);
    }
    position.x += width;
    iterationState.advanceToNextPastLineEndBackgroundSegment();
  }
}
项目:intellij-ce-playground    文件:ConsoleGutterComponent.java   
public ConsoleGutterComponent(@NotNull Editor editor, @NotNull GutterContentProvider gutterContentProvider, boolean atLineStart) {
  this.editor = (EditorImpl)editor;
  this.gutterContentProvider = gutterContentProvider;
  this.atLineStart = atLineStart;

  if (atLineStart) {
    setOpaque(gutterContentProvider.getLineStartGutterOverlap(editor) == 0);
  }
  else {
    addListeners();
    setOpaque(false);
  }

  int spaceWidth = EditorUtil.getSpaceWidth(Font.PLAIN, editor);
  // at line start: icon/one-char symbol + space
  gap = atLineStart ? spaceWidth * GutterContentProvider.MAX_LINE_END_GUTTER_WIDTH_IN_CHAR : spaceWidth;
  maxContentWidth = atLineStart ? gap : 0;
}
项目:intellij-ce-playground    文件:bigFile.java   
private void drawCharsCached(@NotNull Graphics g,
                             CharSequence data,
                             int start,
                             int end,
                             int x,
                             int y,
                             @JdkConstants.FontStyle int fontType,
                             Color color,
                             boolean drawWhitespace) {
  FontInfo fnt = EditorUtil.fontForChar(data.charAt(start), fontType, this);
  if (myLastCache != null && spacesOnly(data, start, end) && fnt.charWidth(' ') == myLastCache.spaceWidth) {
    // we don't care about font if we only need to paint spaces and space width matches
    myLastCache.addContent(g, data, start, end, x, y, null, drawWhitespace);
  }
  else {
    drawCharsCached(g, data, start, end, x, y, fnt, color, drawWhitespace);
  }
}
项目:intellij-ce-playground    文件:bigFile.java   
private int getTextSegmentWidth(@NotNull CharSequence text,
                                int start,
                                int end,
                                int xStart,
                                @JdkConstants.FontStyle int fontType,
                                @NotNull Rectangle clip) {
  int x = xStart;

  for (int i = start; i < end && xStart < clip.x + clip.width; i++) {
    char c = text.charAt(i);
    if (c == '\t') {
      x = EditorUtil.nextTabStop(x, this);
    }
    else {
      x += EditorUtil.charWidth(c, fontType, this);
    }
    if (x > clip.x + clip.width) {
      break;
    }
  }
  return x - xStart;
}
项目:intellij-ce-playground    文件:bigFile.java   
public Dimension getPreferredSize() {
  if (myUseNewRendering) return myView.getPreferredSize();
  if (ourIsUnitTestMode && getUserData(DO_DOCUMENT_UPDATE_TEST) == null) {
    return new Dimension(1, 1);
  }

  final Dimension draft = getSizeWithoutCaret();
  final int additionalSpace = shouldRespectAdditionalColumns()
                              ? mySettings.getAdditionalColumnsCount() * EditorUtil.getSpaceWidth(Font.PLAIN, this)
                              : 0;

  if (!myDocument.isInBulkUpdate()) {
    for (Caret caret : myCaretModel.getAllCarets()) {
      if (caret.isUpToDate()) {
        int caretX = visualPositionToXY(caret.getVisualPosition()).x;
        draft.width = Math.max(caretX, draft.width);
      }
    }
  }
  draft.width += additionalSpace;
  return draft;
}
项目:intellij-ce-playground    文件:TogglePresentationModeAction.java   
private static void tweakEditorAndFireUpdateUI(UISettings settings, boolean inPresentation) {
  EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
  int fontSize = inPresentation ? settings.PRESENTATION_MODE_FONT_SIZE : globalScheme.getEditorFontSize();
  if (inPresentation) {
    ourSavedConsoleFontSize = globalScheme.getConsoleFontSize();
    globalScheme.setConsoleFontSize(fontSize);
  }
  else {
    globalScheme.setConsoleFontSize(ourSavedConsoleFontSize);
  }
  for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
    if (editor instanceof EditorEx) {
      ((EditorEx)editor).setFontSize(fontSize);
    }
  }
  UISettings.getInstance().fireUISettingsChanged();
  LafManager.getInstance().updateUI();
  EditorUtil.reinitSettings();
}
项目:intellij-ce-playground    文件:GrExecuteCommandAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getProject();
  final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
  final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
  if (project == null || editor == null || virtualFile == null) return;

  final Document document = editor.getDocument();
  final TextRange selectedRange = EditorUtil.getSelectionInAnyMode(editor);
  final String command = (selectedRange.isEmpty() ? document.getText() : document.getText(selectedRange));

  final GroovyConsole existingConsole = virtualFile.getUserData(GroovyConsole.GROOVY_CONSOLE);
  if (existingConsole == null) {
    GroovyConsole.getOrCreateConsole(project, virtualFile, new Consumer<GroovyConsole>() {
      @Override
      public void consume(GroovyConsole console) {
        console.execute(command);
      }
    });
  }
  else {
    existingConsole.execute(command);
  }
}
项目:intellij-ce-playground    文件:CodeInsightTestFixtureImpl.java   
private void checkResultByFile(@NonNls @NotNull String expectedFile,
                               @NotNull PsiFile originalFile,
                               boolean stripTrailingSpaces) throws IOException {
  if (!stripTrailingSpaces) {
    EditorUtil.fillVirtualSpaceUntilCaret(myEditor);
  }
  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

  final String fileText = originalFile.getText();
  final String path = getTestDataPath() + "/" + expectedFile;

  /*final VirtualFile result = LocalFileSystem.getInstance().findFileByPath(path);
  final int caret = myEditor.getCaretModel().getOffset();
  final String newText = myFile == originalFile ? fileText.substring(0, caret) + "<caret>" + fileText.substring(caret) : fileText;
  VfsUtil.saveText(result, newText);*/

  VirtualFile virtualFile = originalFile.getVirtualFile();
  String charset = virtualFile == null? null : virtualFile.getCharset().name();
  checkResult(expectedFile, stripTrailingSpaces, SelectionAndCaretMarkupLoader.fromFile(path, charset), fileText);

}
项目:intellij-ce-playground    文件:EditorCoordinateMapper.java   
private int visualLineStartOffset(int offset, boolean leanForward) {
  EditorImpl editor = myView.getEditor();
  int result = EditorUtil.getNotFoldedLineStartOffset(editor, offset);

  SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel();
  List<? extends SoftWrap> softWraps = softWrapModel.getRegisteredSoftWraps();
  int currentOrPrevWrapIndex = softWrapModel.getSoftWrapIndex(offset);
  SoftWrap currentOrPrevWrap;
  if (currentOrPrevWrapIndex < 0) {
    currentOrPrevWrapIndex = - currentOrPrevWrapIndex - 2;
    currentOrPrevWrap = currentOrPrevWrapIndex < 0 || currentOrPrevWrapIndex >= softWraps.size() ? null :
                        softWraps.get(currentOrPrevWrapIndex);
  }
  else {
    currentOrPrevWrap = leanForward ? softWraps.get(currentOrPrevWrapIndex) : null;
  }
  if (currentOrPrevWrap != null && currentOrPrevWrap.getStart() > result) {
    result = currentOrPrevWrap.getStart();
  }
  return result;
}
项目:intellij-ce-playground    文件:SelectionModelImpl.java   
public static void doSelectLineAtCaret(Editor editor) {
  int lineNumber = editor.getCaretModel().getLogicalPosition().line;
  Document document = editor.getDocument();
  if (lineNumber >= document.getLineCount()) {
    return;
  }

  Pair<LogicalPosition, LogicalPosition> lines = EditorUtil.calcCaretLineRange(editor);
  LogicalPosition lineStart = lines.first;
  LogicalPosition nextLineStart = lines.second;

  int start = editor.logicalPositionToOffset(lineStart);
  int end = editor.logicalPositionToOffset(nextLineStart);

  //myEditor.getCaretModel().moveToOffset(start);
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  editor.getSelectionModel().removeSelection();
  editor.getSelectionModel().setSelection(start, end);
}
项目:intellij-ce-playground    文件:EditorGutterComponentImpl.java   
private void calcAnnotationExtraSize() {
  myTextAnnotationExtraSize = 0;
  if (!myEditor.isInDistractionFreeMode() || isMirrored()) return;

  Window frame = SwingUtilities.getWindowAncestor(myEditor.getComponent());
  if (frame == null) return;

  EditorSettings settings = myEditor.getSettings();
  int rightMargin = settings.getRightMargin(myEditor.getProject());
  if (rightMargin <= 0) return;

  JComponent editorComponent = myEditor.getComponent();
  RelativePoint point = new RelativePoint(editorComponent, new Point(0, 0));
  Point editorLocationInWindow = point.getPoint(frame);

  int editorLocationX = (int)editorLocationInWindow.getX();
  int rightMarginX = rightMargin * EditorUtil.getSpaceWidth(Font.PLAIN, myEditor) + editorLocationX;

  int width = editorLocationX + editorComponent.getWidth();
  if (rightMarginX < width && editorLocationX < width - rightMarginX) {
    int centeredSize = (width - rightMarginX - editorLocationX) / 2 - (getLineMarkerAreaWidth() + getLineNumberAreaWidth());
    myTextAnnotationExtraSize = Math.max(0, centeredSize - myTextAnnotationGuttersSize);
  }
}
项目:intellij-ce-playground    文件:TextBasedSoftWrapPainter.java   
/**
 * Tries to find fonts that are capable to display all unicode symbols used by the current painter.
 */
@Override
public void reinit() {
  // We use dummy component here in order to being able to work with font metrics.
  JLabel component = new JLabel();

  myCanUse = true;
  for (Map.Entry<SoftWrapDrawingType, char[]> entry : mySymbols.entrySet()) {
    SoftWrapDrawingType type = entry.getKey();
    char c = entry.getValue()[0];
    FontInfo fontInfo = EditorUtil.fontForChar(c, Font.PLAIN, myEditor);
    if (!fontInfo.canDisplay(c)) {
      myCanUse = false;
      myFonts.put(type, null);
      myVGaps.put(type, null);
      myWidths[type.ordinal()] = 0;
    }
    else {
      myFonts.put(type, fontInfo);
      FontMetrics metrics = component.getFontMetrics(fontInfo.getFont());
      myWidths[type.ordinal()] = metrics.charWidth(c);
      int vGap = metrics.getDescent();
      myVGaps.put(type, vGap);
    }
  }
}
项目:intellij-ce-playground    文件:EditorImpl.java   
@Override
public void setPrefixTextAndAttributes(@Nullable String prefixText, @Nullable TextAttributes attributes) {
  myPrefixText = prefixText == null ? null : prefixText.toCharArray();
  myPrefixAttributes = attributes;
  myPrefixWidthInPixels = 0;
  if (myPrefixText != null) {
    for (char c : myPrefixText) {
      LOG.assertTrue(myPrefixAttributes != null);
      if (myPrefixAttributes != null) {
        myPrefixWidthInPixels += EditorUtil.charWidth(c, myPrefixAttributes.getFontType(), this);
      }
    }
  }
  mySoftWrapModel.recalculate();
  if (myUseNewRendering) myView.setPrefix(prefixText, attributes);
}
项目:intellij-ce-playground    文件:EditorImpl.java   
private void paintAfterLineEndBackgroundSegments(@NotNull Graphics g,
                                                 @NotNull IterationState iterationState,
                                                 @NotNull Point position,
                                                 @NotNull Color defaultBackground,
                                                 int lineHeight) {
  while (iterationState.hasPastLineEndBackgroundSegment()) {
    TextAttributes backgroundAttributes = iterationState.getPastLineEndBackgroundAttributes();
    int width = EditorUtil.getSpaceWidth(backgroundAttributes.getFontType(), this) * iterationState.getPastLineEndBackgroundSegmentWidth();
    Color color = getBackgroundColor(backgroundAttributes);
    if (color != null && !color.equals(defaultBackground)) {
      g.setColor(color);
      g.fillRect(position.x, position.y, width, lineHeight);
    }
    position.x += width;
    iterationState.advanceToNextPastLineEndBackgroundSegment();
  }
}
项目:intellij-ce-playground    文件:EditorImpl.java   
private void drawCharsCached(@NotNull Graphics g,
                             CharSequence data,
                             int start,
                             int end,
                             int x,
                             int y,
                             @JdkConstants.FontStyle int fontType,
                             Color color,
                             boolean drawWhitespace) {
  FontInfo fnt = EditorUtil.fontForChar(data.charAt(start), fontType, this);
  if (myLastCache != null && spacesOnly(data, start, end) && fnt.charWidth(' ') == myLastCache.spaceWidth) {
    // we don't care about font if we only need to paint spaces and space width matches
    myLastCache.addContent(g, data, start, end, x, y, null, drawWhitespace);
  }
  else {
    drawCharsCached(g, data, start, end, x, y, fnt, color, drawWhitespace);
  }
}
项目:intellij-ce-playground    文件:EditorImpl.java   
private int getTextSegmentWidth(@NotNull CharSequence text,
                                int start,
                                int end,
                                int xStart,
                                @JdkConstants.FontStyle int fontType,
                                @NotNull Rectangle clip) {
  int x = xStart;

  for (int i = start; i < end && xStart < clip.x + clip.width; i++) {
    char c = text.charAt(i);
    if (c == '\t') {
      x = EditorUtil.nextTabStop(x, this);
    }
    else {
      x += EditorUtil.charWidth(c, fontType, this);
    }
    if (x > clip.x + clip.width) {
      break;
    }
  }
  return x - xStart;
}
项目:intellij-ce-playground    文件:LookupCellRenderer.java   
@Nullable
Font getFontAbleToDisplay(LookupElementPresentation p) {
  String sampleString = p.getItemText() + p.getTailText() + p.getTypeText();

  // assume a single font can display all lookup item chars
  Set<Font> fonts = ContainerUtil.newHashSet();
  for (int i = 0; i < sampleString.length(); i++) {
    fonts.add(EditorUtil.fontForChar(sampleString.charAt(i), Font.PLAIN, myLookup.getEditor()).getFont());
  }

  eachFont: for (Font font : fonts) {
    if (font.equals(myNormalFont)) continue;

    for (int i = 0; i < sampleString.length(); i++) {
      if (!font.canDisplay(sampleString.charAt(i))) {
        continue eachFont;
      }
    }
    return font;
  }
  return null;
}
项目:intellij-ce-playground    文件:RenameWrongRefFix.java   
@Override
  public void invoke(@NotNull Project project, final Editor editor, PsiFile file) {
    if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
    PsiReferenceExpression[] refs = CreateFromUsageUtils.collectExpressions(myRefExpr, PsiMember.class, PsiFile.class);
    PsiElement element = PsiTreeUtil.getParentOfType(myRefExpr, PsiMember.class, PsiFile.class);
    LookupElement[] items = collectItems();
    ReferenceNameExpression refExpr = new ReferenceNameExpression(items, myRefExpr.getReferenceName());

    TemplateBuilderImpl builder = new TemplateBuilderImpl(element);
    for (PsiReferenceExpression expr : refs) {
      if (!expr.equals(myRefExpr)) {
        builder.replaceElement(expr.getReferenceNameElement(), OTHER_VARIABLE_NAME, INPUT_VARIABLE_NAME, false);
      }
      else {
        builder.replaceElement(expr.getReferenceNameElement(), INPUT_VARIABLE_NAME, refExpr, true);
      }
    }

    final float proportion = EditorUtil.calcVerticalScrollProportion(editor);
    editor.getCaretModel().moveToOffset(element.getTextRange().getStartOffset());

    /*for (int i = refs.length - 1; i >= 0; i--) {
      TextRange range = refs[i].getReferenceNameElement().getTextRange();
      document.deleteString(range.getStartOffset(), range.getEndOffset());
    }
*/
    Template template = builder.buildInlineTemplate();
    editor.getCaretModel().moveToOffset(element.getTextRange().getStartOffset());

    TemplateManager.getInstance(project).startTemplate(editor, template);

    EditorUtil.setVerticalScrollProportion(editor, proportion);
  }
项目:intellij-ce-playground    文件:bigFile.java   
private void initTabPainter() {
  myTabPainter = new ArrowPainter(
    ColorProvider.byColorsScheme(myScheme, EditorColors.WHITESPACES_COLOR),
    new Computable.PredefinedValueComputable<Integer>(EditorUtil.getSpaceWidth(Font.PLAIN, this)),
    new Computable<Integer>() {
      @Override
      public Integer compute() {
        return getCharHeight();
      }
    }
  );
}
项目:intellij-ce-playground    文件:bigFile.java   
/**
 * Allows to answer how much width requires given char to be represented on a screen.
 *
 * @param c        target character
 * @param fontType font type to use for representation of the given character
 * @param currentX current <code>'x'</code> position on a line where given character should be displayed
 * @return width required to represent given char with the given settings on a screen;
 *         <code>'0'</code> if given char is a line break
 */
private int charToVisibleWidth(char c, @JdkConstants.FontStyle int fontType, int currentX) {
  if (c == '\n') {
    return 0;
  }

  if (c == '\t') {
    return EditorUtil.nextTabStop(currentX, this) - currentX;
  }
  return EditorUtil.charWidth(c, fontType, this);
}
项目:intellij-ce-playground    文件:RunIdeConsoleAction.java   
@NotNull
private static String getCommand(@NotNull Editor editor) {
  TextRange selectedRange = EditorUtil.getSelectionInAnyMode(editor);
  Document document = editor.getDocument();
  if (selectedRange.getLength() == 0) {
    int line = document.getLineNumber(selectedRange.getStartOffset());
    selectedRange = TextRange.create(document.getLineStartOffset(line), document.getLineEndOffset(line));
  }
  return document.getText(selectedRange);
}
项目:intellij-ce-playground    文件:ToggleDistractionFreeModeAction.java   
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  Project project = e.getProject();
  RegistryValue value = Registry.get(key);
  boolean enter = !value.asBoolean();
  value.setValue(enter);

  if (project == null) return;

  PropertiesComponent p = PropertiesComponent.getInstance();
  UISettings ui = UISettings.getInstance();
  EditorSettingsExternalizable.OptionSet eo = EditorSettingsExternalizable.getInstance().getOptions();
  DaemonCodeAnalyzerSettings ds = DaemonCodeAnalyzerSettings.getInstance();

  String before = "BEFORE.DISTRACTION.MODE.";
  String after = "AFTER.DISTRACTION.MODE.";
  if (enter) {
    applyAndSave(p, ui, eo, ds, before, after, false);
    TogglePresentationModeAction.storeToolWindows(project);
  }
  else {
    applyAndSave(p, ui, eo, ds, after, before, true);    
    TogglePresentationModeAction.restoreToolWindows(project, true, false);
  }

  UISettings.getInstance().fireUISettingsChanged();
  LafManager.getInstance().updateUI();
  EditorUtil.reinitSettings();
  DaemonCodeAnalyzer.getInstance(project).settingsChanged();
  EditorFactory.getInstance().refreshAllEditors();
}
项目:intellij-ce-playground    文件:ConsoleHistoryController.java   
protected int insertTextMultiline(String text, Editor editor, Document document) {
  TextRange selection = EditorUtil.getSelectionInAnyMode(editor);

  int start = document.getLineStartOffset(document.getLineNumber(selection.getStartOffset()));
  int end = document.getLineEndOffset(document.getLineNumber(selection.getEndOffset()));

  document.replaceString(start, end, text);
  editor.getSelectionModel().setSelection(start, start + text.length());
  return start;
}
项目:intellij-ce-playground    文件:ConsoleGutterComponent.java   
@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));
  }
}
项目:intellij-ce-playground    文件:bigFile.java   
@Override
public int logicalPositionToOffset(@NotNull LogicalPosition pos, boolean softWrapAware) {
  if (myUseNewRendering) return myView.logicalPositionToOffset(pos);
  if (softWrapAware) {
    return mySoftWrapModel.logicalPositionToOffset(pos);
  }
  assertReadAccess();
  if (myDocument.getLineCount() == 0) return 0;

  if (pos.line < 0) throw new IndexOutOfBoundsException("Wrong line: " + pos.line);
  if (pos.column < 0) throw new IndexOutOfBoundsException("Wrong column:" + pos.column);

  if (pos.line >= myDocument.getLineCount()) {
    return myDocument.getTextLength();
  }

  int start = myDocument.getLineStartOffset(pos.line);
  if (pos.column == 0) return start;
  int end = myDocument.getLineEndOffset(pos.line);

  int x = getDocument().getLineNumber(start) == 0 ? getPrefixTextWidthInPixels() : 0;

  int result = EditorUtil.calcSoftWrapUnawareOffset(this, myDocument.getImmutableCharSequence(), start, end, pos.column,
                                                    EditorUtil.getTabSize(this), x, new int[]{0}, null);
  if (result >= 0) {
    return result;
  }

  return end;
}
项目:intellij-ce-playground    文件:CodeFormatterFacade.java   
private int wrapPositionForTabbedTextWithoutOptimization(@NotNull Editor editor,
                                                         @NotNull CharSequence text,
                                                         int spaceSize,
                                                         int startLineOffset,
                                                         int endLineOffset,
                                                         int targetRangeEndOffset)
{
  int width = 0;
  int x = 0;
  int newX;
  int symbolWidth;
  int result = Integer.MAX_VALUE;
  boolean wrapLine = false;
  for (int i = startLineOffset; i < Math.min(endLineOffset, targetRangeEndOffset); i++) {
    char c = text.charAt(i);
    switch (c) {
      case '\t':
        newX = EditorUtil.nextTabStop(x, editor);
        int diffInPixels = newX - x;
        symbolWidth = diffInPixels / spaceSize;
        if (diffInPixels % spaceSize > 0) {
          symbolWidth++;
        }
        break;
      default: newX = x + EditorUtil.charWidth(c, Font.PLAIN, editor); symbolWidth = 1;
    }
    if (width + symbolWidth + FormatConstants.RESERVED_LINE_WRAP_WIDTH_IN_COLUMNS >= myRightMargin
        && (Math.min(endLineOffset, targetRangeEndOffset) - i) >= FormatConstants.RESERVED_LINE_WRAP_WIDTH_IN_COLUMNS)
    {
      result = i - 1;
    }
    if (width + symbolWidth >= myRightMargin) {
      wrapLine = true;
      break;
    }
    x = newX;
    width += symbolWidth;
  }
  return wrapLine ? result : -1;
}
项目:intellij-ce-playground    文件:ListTemplatesHandler.java   
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
    return;
  }
  EditorUtil.fillVirtualSpaceUntilCaret(editor);

  PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
  int offset = editor.getCaretModel().getOffset();
  List<TemplateImpl> applicableTemplates = TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier(editor, file, false);

  Map<TemplateImpl, String> matchingTemplates = filterTemplatesByPrefix(applicableTemplates, editor, offset, false, true);
  MultiMap<String, CustomLiveTemplateLookupElement> customTemplatesLookupElements = getCustomTemplatesLookupItems(editor, file, offset);

  if (matchingTemplates.isEmpty()) {
    for (TemplateImpl template : applicableTemplates) {
      matchingTemplates.put(template, null);
    }
  }

  if (matchingTemplates.isEmpty() && customTemplatesLookupElements.isEmpty()) {
    HintManager.getInstance().showErrorHint(editor, CodeInsightBundle.message("templates.no.defined"));
    return;
  }

  showTemplatesLookup(project, editor, file, matchingTemplates, customTemplatesLookupElements);
}
项目:intellij-ce-playground    文件:ConsoleGutterComponent.java   
private void addListeners() {
  addMouseMotionListener(this);

  addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (!e.isPopupTrigger()) {
        gutterContentProvider.doAction(EditorUtil.yPositionToLogicalLine(editor, e.getPoint()), editor);
      }
    }
  });
}
项目:intellij-ce-playground    文件:bigFile.java   
private void initTabPainter() {
  myTabPainter = new ArrowPainter(
    ColorProvider.byColorsScheme(myScheme, EditorColors.WHITESPACES_COLOR),
    new Computable.PredefinedValueComputable<Integer>(EditorUtil.getSpaceWidth(Font.PLAIN, this)),
    new Computable<Integer>() {
      @Override
      public Integer compute() {
        return getCharHeight();
      }
    }
  );
}
项目:intellij-ce-playground    文件:bigFile.java   
private void paintRightMargin(@NotNull Graphics g, @NotNull Rectangle clip) {
  Color rightMargin = myScheme.getColor(EditorColors.RIGHT_MARGIN_COLOR);
  if (!mySettings.isRightMarginShown() || rightMargin == null) {
    return;
  }
  int x = mySettings.getRightMargin(myProject) * EditorUtil.getSpaceWidth(Font.PLAIN, this);
  if (x >= clip.x && x < clip.x + clip.width) {
    g.setColor(rightMargin);
    UIUtil.drawLine(g, x, clip.y, x, clip.y + clip.height);
  }
}
项目:intellij-ce-playground    文件:EditorHyperlinkSupport.java   
@Nullable
public Runnable getLinkNavigationRunnable(final LogicalPosition logical) {
  if (EditorUtil.inVirtualSpace(myEditor, logical)) {
    return null;
  }

  final RangeHighlighter range = findLinkRangeAt(this.myEditor.logicalPositionToOffset(logical));
  if (range != null) {
    final HyperlinkInfo hyperlinkInfo = getHyperlinkInfo(range);
    if (hyperlinkInfo != null) {
      return new Runnable() {
        @Override
        public void run() {
          if (hyperlinkInfo instanceof HyperlinkInfoBase) {
            final Point point = myEditor.logicalPositionToXY(logical);
            final MouseEvent event = new MouseEvent(myEditor.getContentComponent(), 0, 0, 0, point.x, point.y, 1, false);
            ((HyperlinkInfoBase)hyperlinkInfo).navigate(myProject, new RelativePoint(event));
          }
          else {
            hyperlinkInfo.navigate(myProject);
          }
          linkFollowed(myEditor, getHyperlinks(0, myEditor.getDocument().getTextLength(),myEditor), range);
        }
      };
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:bigFile.java   
@Override
public void mouseReleased(@NotNull MouseEvent e) {
  myMousePressArea = null;
  runMouseReleasedCommand(e);
  if (!e.isConsumed() && myMousePressedEvent != null && !myMousePressedEvent.isConsumed() &&
      Math.abs(e.getX() - myMousePressedEvent.getX()) < EditorUtil.getSpaceWidth(Font.PLAIN, EditorImpl.this) &&
      Math.abs(e.getY() - myMousePressedEvent.getY()) < getLineHeight()) {
    runMouseClickedCommand(e);
  }
}
项目:intellij-ce-playground    文件:bigFile.java   
@Override
protected void processMouseWheelEvent(@NotNull MouseWheelEvent e) {
  if (mySettings.isWheelFontChangeEnabled() && !MouseGestureManager.getInstance().hasTrackpad()) {
    if (EditorUtil.isChangeFontSize(e)) {
      int size = myScheme.getEditorFontSize() - e.getWheelRotation();
      if (size >= MIN_FONT_SIZE) {
        setFontSize(size, SwingUtilities.convertPoint(this, e.getPoint(), getViewport()));
      }
      return;
    }
  }

  super.processMouseWheelEvent(e);
}