com.intellij.openapi.editor.highlighter.EditorHighlighterFactory Java Examples

The following examples show how to use com.intellij.openapi.editor.highlighter.EditorHighlighterFactory. 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: WeaveEditor.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
private void updateTab(@NotNull JBTabsPaneImpl tabsPane, int index, WeaveIdentifier identifier, @NotNull WeaveDataType dataType) {
    Icon icon = iconsMap.containsKey(dataType.getText()) ? iconsMap.get(dataType.getText()) : AllIcons.FileTypes.Any_type;

    String title = (identifier == null ? "output" : identifier.getName());

    tabsPane.setTitleAt(index, title);
    tabsPane.setIconAt(index, icon);
    contentTypes.put(title, dataType.getText());

    VirtualFile vfile = inputOutputFiles.get(title);
    if (vfile != null) {
        vfile.putUserData(newFileDataTypeKey, dataType.getText());
        FileContentUtilCore.reparseFiles(vfile);
    }

    Editor oldEditor = editors.get(title);
    FileType newType = fileTypes.containsKey(dataType.getText()) ? fileTypes.get(dataType.getText()) : FileTypes.UNKNOWN;
    ((EditorEx) oldEditor).setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(project, newType));
}
 
Example #2
Source File: LatteIndexPatternBuilder.java    From intellij-latte with MIT License 6 votes vote down vote up
@Nullable
@Override
public Lexer getIndexingLexer(@NotNull PsiFile file) {
	if (!(file instanceof LatteFile)) {
		return null;
	}
	VirtualFile virtualFile = file.getVirtualFile();
	if (virtualFile == null) {
		virtualFile = file.getViewProvider().getVirtualFile();
	}

	try {
		LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE);
		EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file.getProject(), virtualFile);
		return new LexerEditorHighlighterLexer(highlighter, false);
	} finally {
		LayeredLexer.ourDisableLayersFlag.set(Boolean.FALSE);
	}
}
 
Example #3
Source File: DiffUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static EditorHighlighter createEditorHighlighter(@Nullable Project project, @Nonnull DocumentContent content) {
  FileType type = content.getContentType();
  VirtualFile file = content.getHighlightFile();
  Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);

  EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
  if (language != null) {
    SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file);
    return highlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme());
  }
  if (file != null) {
    if ((type == null || type == PlainTextFileType.INSTANCE) || file.getFileType() == type || file instanceof LightVirtualFile) {
      return highlighterFactory.createEditorHighlighter(project, file);
    }
  }
  if (type != null) {
    return highlighterFactory.createEditorHighlighter(project, type);
  }
  return null;
}
 
Example #4
Source File: SyntaxHighlighterOverEditorHighlighter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public SyntaxHighlighterOverEditorHighlighter(SyntaxHighlighter _highlighter, VirtualFile file, Project project) {
  if (file.getFileType() == PlainTextFileType.INSTANCE) { // optimization for large files, PlainTextSyntaxHighlighterFactory is slow
    highlighter = new PlainSyntaxHighlighter();
    lexer = highlighter.getHighlightingLexer();
  } else {
    highlighter = _highlighter;
    LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE);
    EditorHighlighter editorHighlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, file);

    try {
      if (editorHighlighter instanceof LayeredLexerEditorHighlighter) {
        lexer = new LexerEditorHighlighterLexer(editorHighlighter, false);
      }
      else {
        lexer = highlighter.getHighlightingLexer();
      }
    }
    finally {
      LayeredLexer.ourDisableLayersFlag.set(null);
    }
  }
}
 
Example #5
Source File: FileTypeEditorHighlighterProviders.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected List<EditorHighlighterProvider> buildExtensions(String stringKey, final FileType key) {
  List<EditorHighlighterProvider> fromEP = super.buildExtensions(stringKey, key);
  if (fromEP.isEmpty()) {
    EditorHighlighterProvider defaultProvider = new EditorHighlighterProvider() {
      @Override
      public EditorHighlighter getEditorHighlighter(@Nullable Project project,
                                                    @Nonnull FileType fileType,
                                                    @Nullable VirtualFile virtualFile,
                                                    @Nonnull EditorColorsScheme colors) {
        return EditorHighlighterFactory.getInstance().createEditorHighlighter(
          SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, virtualFile), colors);
      }
    };
    return Collections.singletonList(defaultProvider);
  }
  return fromEP;
}
 
Example #6
Source File: FileTemplateConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
private EditorHighlighter createHighlighter() {
  if (myTemplate != null && myVelocityFileType != UnknownFileType.INSTANCE) {
    return EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, new LightVirtualFile("aaa." + myTemplate.getExtension() + ".ft"));
  }

  FileType fileType = null;
  if (myTemplate != null) {
    fileType = FileTypeManager.getInstance().getFileTypeByExtension(myTemplate.getExtension());
  }
  if (fileType == null) {
    fileType = PlainTextFileType.INSTANCE;
  }

  SyntaxHighlighter originalHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, null, null);
  if (originalHighlighter == null) {
    originalHighlighter = new PlainSyntaxHighlighter();
  }

  final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  LayeredLexerEditorHighlighter highlighter = new LayeredLexerEditorHighlighter(new TemplateHighlighter(), scheme);
  highlighter.registerLayer(FileTemplateTokenType.TEXT, new LayerDescriptor(originalHighlighter, ""));
  return highlighter;
}
 
Example #7
Source File: DetailViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
protected Editor createEditor(@Nullable Project project, Document document, VirtualFile file) {
  EditorEx editor = (EditorEx)EditorFactory.getInstance().createViewer(document, project);

  final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project);

  editor.setFile(file);
  editor.setHighlighter(highlighter);

  EditorSettings settings = editor.getSettings();
  settings.setAnimatedScrolling(false);
  settings.setRefrainFromScrolling(false);
  settings.setLineNumbersShown(true);
  settings.setFoldingOutlineShown(false);
  if (settings instanceof SettingsImpl) {
    ((SettingsImpl)settings).setSoftWrapAppliancePlace(SoftWrapAppliancePlaces.PREVIEW);
  }
  editor.getFoldingModel().setFoldingEnabled(false);

  return editor;
}
 
Example #8
Source File: TemplateEditorUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static Editor createEditor(boolean isReadOnly, final Document document, final Project project) {
  EditorFactory editorFactory = EditorFactory.getInstance();
  Editor editor = (isReadOnly ? editorFactory.createViewer(document, project) : editorFactory.createEditor(document, project));

  EditorSettings editorSettings = editor.getSettings();
  editorSettings.setVirtualSpace(false);
  editorSettings.setLineMarkerAreaShown(false);
  editorSettings.setIndentGuidesShown(false);
  editorSettings.setLineNumbersShown(false);
  editorSettings.setFoldingOutlineShown(false);

  EditorColorsScheme scheme = editor.getColorsScheme();
  scheme.setColor(EditorColors.CARET_ROW_COLOR, null);

  VirtualFile file = FileDocumentManager.getInstance().getFile(document);
  if (file != null) {
    EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project);
    ((EditorEx) editor).setHighlighter(highlighter);
  }

  return editor;
}
 
Example #9
Source File: EditorHighlighterCache.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Lexer getLexerBasedOnLexerHighlighter(CharSequence text, VirtualFile virtualFile, Project project) {
  EditorHighlighter highlighter = null;

  PsiFile psiFile = virtualFile != null ? PsiManager.getInstance(project).findFile(virtualFile) : null;
  final Document document = psiFile != null ? PsiDocumentManager.getInstance(project).getDocument(psiFile) : null;
  final EditorHighlighter cachedEditorHighlighter;
  boolean alreadyInitializedHighlighter = false;

  if (document != null &&
      (cachedEditorHighlighter = getEditorHighlighterForCachesBuilding(document)) != null &&
      PlatformIdTableBuilding.checkCanUseCachedEditorHighlighter(text, cachedEditorHighlighter)) {
    highlighter = cachedEditorHighlighter;
    alreadyInitializedHighlighter = true;
  }
  else if (virtualFile != null) {
    highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, virtualFile);
  }

  if (highlighter != null) {
    return new LexerEditorHighlighterLexer(highlighter, alreadyInitializedHighlighter);
  }
  return null;
}
 
Example #10
Source File: DiffHighlighterFactoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public EditorHighlighter createHighlighter() {
  if (myFileType == null || myProject == null) return null;
  if ((myFile != null && myFile.getFileType() == myFileType) || myFile instanceof LightVirtualFile) {
    return EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myFile);
  }
  return EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myFileType);
}
 
Example #11
Source File: MethodSignatureComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected EditorEx createEditor() {
  EditorEx editor = super.createEditor();
  final String fileName = getFileName();
  if (fileName != null) {
    editor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(getProject(), fileName));
  }
  editor.getSettings().setWhitespacesShown(false);
  editor.setHorizontalScrollbarVisible(true);
  editor.setVerticalScrollbarVisible(true);
  return editor;
}
 
Example #12
Source File: ActionUsagePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void configureByText(final String usageText, FileType fileType) {
  Document document = myEditor.getDocument();
  String text = StringUtil.convertLineSeparators(usageText);
  document.replaceString(0, document.getTextLength(), text);
  final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  myEditor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(fileType, scheme, null));
  setupSpots(document);
}
 
Example #13
Source File: IntentionUsagePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void configureByText(final String usageText, FileType fileType) {
  Document document = myEditor.getDocument();
  String text = StringUtil.convertLineSeparators(usageText);
  document.replaceString(0, document.getTextLength(), text);
  final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  myEditor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(fileType, scheme, null));
  setupSpots(document);
}
 
Example #14
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 #15
Source File: RecentLocationsDataModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void applySyntaxHighlighting(Project project, EditorEx editor, Document document, EditorColorsScheme colorsScheme, TextRange textRange, IdeDocumentHistoryImpl.PlaceInfo placeInfo) {
  EditorHighlighter editorHighlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(placeInfo.getFile(), colorsScheme, project);
  editorHighlighter.setEditor(new LightHighlighterClient(document, project));
  editorHighlighter.setText(document.getText(TextRange.create(0, textRange.getEndOffset())));
  int startOffset = textRange.getStartOffset();

  for (HighlighterIterator iterator = editorHighlighter.createIterator(startOffset); !iterator.atEnd() && iterator.getEnd() <= textRange.getEndOffset(); iterator.advance()) {
    if (iterator.getStart() >= startOffset) {
      editor.getMarkupModel().addRangeHighlighter(iterator.getStart() - startOffset, iterator.getEnd() - startOffset, 999, iterator.getTextAttributes(), HighlighterTargetArea.EXACT_RANGE);
    }
  }
}
 
Example #16
Source File: TemplateEditor.java    From EasyCode with MIT License 5 votes vote down vote up
/**
 * 重置
 *
 * @param name    模板名称
 * @param content 文本内容
 */
public void reset(String name, String content) {
    if (content != null && this.editor != null) {
        // 重置语法高亮
        ((EditorEx) editor).setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(project, new LightVirtualFile(name + ".ft")));
        // 重置文本内容
        WriteCommandAction.runWriteCommandAction(project, () -> this.editor.getDocument().setText(content));
    }
}
 
Example #17
Source File: DesktopTextEditorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected Runnable loadEditorInBackground() {
  EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(myFile, scheme, myProject);
  EditorEx editor = (EditorEx)getEditor();
  highlighter.setText(editor.getDocument().getImmutableCharSequence());
  return () -> editor.setHighlighter(highlighter);
}
 
Example #18
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 #19
Source File: EditorHighlighterUpdater.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected EditorHighlighter createHighlighter() {
  EditorHighlighter highlighter = myFile != null
                                  ? EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myFile)
                                  : new EmptyEditorHighlighter(EditorColorsManager.getInstance().getGlobalScheme().getAttributes(HighlighterColors.TEXT));
  highlighter.setText(myEditor.getDocument().getImmutableCharSequence());
  return highlighter;
}
 
Example #20
Source File: CsvEditorHighlighterProvider.java    From intellij-csv-validator with Apache License 2.0 4 votes vote down vote up
@Override
public EditorHighlighter getEditorHighlighter(@Nullable Project project, @NotNull FileType fileType, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) {
    return EditorHighlighterFactory.getInstance().createEditorHighlighter(CsvSyntaxHighlighterFactory.getSyntaxHighlighter(CsvLanguage.INSTANCE, project, virtualFile), colors);
}
 
Example #21
Source File: HighlighterFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static EditorHighlighter createHighlighter(SyntaxHighlighter highlighter, EditorColorsScheme settings) {
  return EditorHighlighterFactory.getInstance().createEditorHighlighter(highlighter, settings);
}
 
Example #22
Source File: HighlighterFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static EditorHighlighter createHighlighter(Project project, String fileName) {
  return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, fileName);
}
 
Example #23
Source File: ConsoleExecutionEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void initComponent() {
  myConsoleEditor.setContextMenuGroupId(IdeActions.GROUP_CONSOLE_EDITOR_POPUP);
  myConsoleEditor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(getVirtualFile(), myConsoleEditor.getColorsScheme(), getProject()));
  myConsolePromptDecorator.update();
}
 
Example #24
Source File: GeneralCodeStylePanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected EditorHighlighter createHighlighter(final EditorColorsScheme scheme) {
  //noinspection NullableProblems
  return EditorHighlighterFactory.getInstance().createEditorHighlighter(getFileType(), scheme, null);
}
 
Example #25
Source File: TabbedLanguageCodeStylePanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected EditorHighlighter createHighlighter(EditorColorsScheme scheme) {
  //noinspection NullableProblems
  return EditorHighlighterFactory.getInstance().createEditorHighlighter(getFileType(), scheme, null);
}
 
Example #26
Source File: HighlighterFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static EditorHighlighter createHighlighter(Project project, VirtualFile file) {
  return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, file);
}
 
Example #27
Source File: HighlighterFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static EditorHighlighter createHighlighter(Project project, FileType fileType) {
  return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, fileType);
}
 
Example #28
Source File: HighlighterFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static EditorHighlighter createHighlighter(EditorColorsScheme settings, String fileName, Project project) {
  return EditorHighlighterFactory.getInstance().createEditorHighlighter(settings, fileName, project);
}
 
Example #29
Source File: HighlighterFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static EditorHighlighter createHighlighter(FileType fileType, EditorColorsScheme settings, Project project) {
  return EditorHighlighterFactory.getInstance().createEditorHighlighter(fileType, settings, project);
}
 
Example #30
Source File: HighlighterFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static EditorHighlighter createHighlighter(@Nonnull VirtualFile vFile, EditorColorsScheme settings, Project project) {
  return EditorHighlighterFactory.getInstance().createEditorHighlighter(vFile, settings, project);
}