public SoyLayeredHighlighter( @Nullable Project project, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) { // Creating main highlighter. super(new SoySyntaxHighlighter(), colors); // Highlighter for the outer language. FileType type = null; if (project == null || virtualFile == null) { type = StdFileTypes.PLAIN_TEXT; } else { Language language = TemplateDataLanguageMappings.getInstance(project).getMapping(virtualFile); if (language != null) type = language.getAssociatedFileType(); if (type == null) type = SoyLanguage.getDefaultTemplateLang(); } SyntaxHighlighter outerHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(type, project, virtualFile); registerLayer(OTHER, new LayerDescriptor(outerHighlighter, "")); }
private void createUIComponents() { final EditorFactory editorFactory = EditorFactory.getInstance(); jsonDocument = editorFactory.createDocument(EMPTY_TEXT); jsonEditor = editorFactory.createEditor(jsonDocument, project, JsonFileType.INSTANCE, false); final EditorSettings settings = jsonEditor.getSettings(); settings.setWhitespacesShown(true); settings.setLineMarkerAreaShown(false); settings.setIndentGuidesShown(false); settings.setLineNumbersShown(true); settings.setFoldingOutlineShown(false); settings.setRightMarginShown(false); settings.setVirtualSpace(false); settings.setWheelFontChangeEnabled(false); settings.setUseSoftWraps(false); settings.setAdditionalColumnsCount(0); settings.setAdditionalLinesCount(1); final EditorColorsScheme colorsScheme = jsonEditor.getColorsScheme(); colorsScheme.setColor(EditorColors.CARET_ROW_COLOR, null); jsonEditor.getContentComponent().setFocusable(true); jsonPanel = (JPanel) jsonEditor.getComponent(); }
@Override public JComponent createTaskInfoPanel(Project project) { myTaskTextPane = new JTextPane(); final JBScrollPane scrollPane = new JBScrollPane(myTaskTextPane); myTaskTextPane.setContentType(new HTMLEditorKit().getContentType()); final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); int fontSize = editorColorsScheme.getEditorFontSize(); final String fontName = editorColorsScheme.getEditorFontName(); final Font font = new Font(fontName, Font.PLAIN, fontSize); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }" + "pre {font-family: Courier; display: inline; ine-height: 50px; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; background-color:" + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}" + "code {font-family: Courier; display: flex; float: left; background-color:" + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}"; ((HTMLDocument)myTaskTextPane.getDocument()).getStyleSheet().addRule(bodyRule); myTaskTextPane.setEditable(false); if (!UIUtil.isUnderDarcula()) { myTaskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()); } myTaskTextPane.setBorder(new EmptyBorder(20, 20, 0, 10)); myTaskTextPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE); return scrollPane; }
public static void drawAnswerPlaceholder(@NotNull final Editor editor, @NotNull final AnswerPlaceholder placeholder, @NotNull final JBColor color) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); final TextAttributes textAttributes = new TextAttributes(scheme.getDefaultForeground(), scheme.getDefaultBackground(), null, EffectType.BOXED, Font.PLAIN); textAttributes.setEffectColor(color); int startOffset = placeholder.getOffset(); if (startOffset == -1) { return; } final int length = placeholder.isActive() ? placeholder.getRealLength() : placeholder.getVisibleLength(placeholder.getActiveSubtaskIndex()); Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(placeholder, editor.getDocument()); startOffset = offsets.first; int endOffset = offsets.second; if (placeholder.isActive()) { drawAnswerPlaceholder(editor, startOffset, endOffset, textAttributes, PLACEHOLDERS_LAYER); } else if (!placeholder.getUseLength() && length != 0) { drawAnswerPlaceholderFromPrevStep(editor, startOffset, endOffset); } }
@Override public void updateView() { EditorColorsScheme scheme = myOptions.getSelectedScheme(); myEditor.setColorsScheme(scheme); EditorHighlighter highlighter = null; if (myPage instanceof EditorHighlightingProvidingColorSettingsPage) { highlighter = ((EditorHighlightingProvidingColorSettingsPage)myPage).createEditorHighlighter(scheme); } if (highlighter == null) { final SyntaxHighlighter pageHighlighter = myPage.getHighlighter(); highlighter = HighlighterFactory.createHighlighter(pageHighlighter, scheme); } myEditor.setHighlighter(highlighter); updateHighlighters(); myEditor.reinitSettings(); }
@Nullable @Override public TextAttributes getTextAttributes(@NotNull EditorColorsScheme scheme, @NotNull ArrangementSettingsToken token, boolean selected) { if (selected) { TextAttributes attributes = new TextAttributes(); attributes.setForegroundColor(scheme.getColor(EditorColors.SELECTION_FOREGROUND_COLOR)); attributes.setBackgroundColor(scheme.getColor(EditorColors.SELECTION_BACKGROUND_COLOR)); return attributes; } else if (SUPPORTED_TYPES.contains(token)) { return getAttributes(scheme, JavaHighlightingColors.KEYWORD); } else if (SUPPORTED_MODIFIERS.contains(token)) { getAttributes(scheme, JavaHighlightingColors.KEYWORD); } return null; }
public void testScopeBased() throws Exception { NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_SOURCE, null)); NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null)); NamedScopeManager scopeManager = NamedScopeManager.getInstance(getProject()); scopeManager.addScope(xScope); scopeManager.addScope(utilScope); EditorColorsManager manager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); manager.addColorsScheme(scheme); EditorColorsManager.getInstance().setGlobalScheme(scheme); TextAttributesKey xKey = ScopeAttributesUtil.getScopeTextAttributeKey(xScope.getName()); TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, EffectType.BOXED, Font.ITALIC); scheme.setAttributes(xKey, xAttributes); TextAttributesKey utilKey = ScopeAttributesUtil.getScopeTextAttributeKey(utilScope.getName()); TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD); scheme.setAttributes(utilKey, utilAttributes); try { testFile(BASE_PATH + "/scopeBased/x/X.java").projectRoot(BASE_PATH + "/scopeBased").checkSymbolNames().test(); } finally { scopeManager.removeAllSets(); } }
@Override public void update(PresentationData presentation) { String newName = getValue().getName(); int nameEndOffset = newName.length(); int todoItemCount = getTodoItemCount(getValue()); int fileCount = getFileCount(getValue()); newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount); myHighlightedRegions.clear(); TextAttributes textAttributes = new TextAttributes(); if (CopyPasteManager.getInstance().isCutElement(getValue())) { textAttributes.setForegroundColor(CopyPasteManager.CUT_COLOR); } myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes)); EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme(); myHighlightedRegions.add( new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES))); presentation.setIcon(ModuleType.get(getValue()).getIcon()); presentation.setPresentableText(newName); }
@NotNull public static LineMarkerInfo createMethodSeparatorLineMarker(@NotNull PsiElement startFrom, @NotNull EditorColorsManager colorsManager) { LineMarkerInfo info = new LineMarkerInfo<PsiElement>( startFrom, startFrom.getTextRange(), null, Pass.UPDATE_ALL, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT ); EditorColorsScheme scheme = colorsManager.getGlobalScheme(); info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR); info.separatorPlacement = SeparatorPlacement.TOP; return info; }
protected static Editor createEditor(String text, int column, int line, int selectedLine) { EditorFactory editorFactory = EditorFactory.getInstance(); Document editorDocument = editorFactory.createDocument(text); EditorEx editor = (EditorEx)editorFactory.createViewer(editorDocument); EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); editor.setColorsScheme(scheme); EditorSettings settings = editor.getSettings(); settings.setWhitespacesShown(true); settings.setLineMarkerAreaShown(false); settings.setIndentGuidesShown(false); settings.setFoldingOutlineShown(false); settings.setAdditionalColumnsCount(0); settings.setAdditionalLinesCount(0); settings.setRightMarginShown(true); settings.setRightMargin(60); LogicalPosition pos = new LogicalPosition(line, column); editor.getCaretModel().moveToLogicalPosition(pos); if (selectedLine >= 0) { editor.getSelectionModel().setSelection(editorDocument.getLineStartOffset(selectedLine), editorDocument.getLineEndOffset(selectedLine)); } return editor; }
@NotNull @Override public EditorColorsScheme[] getAllSchemes() { List<EditorColorsScheme> schemes = mySchemeManager.getAllSchemes(); EditorColorsScheme[] result = schemes.toArray(new EditorColorsScheme[schemes.size()]); Arrays.sort(result, new Comparator<EditorColorsScheme>() { @Override public int compare(@NotNull EditorColorsScheme s1, @NotNull EditorColorsScheme s2) { if (isDefaultScheme(s1) && !isDefaultScheme(s2)) return -1; if (!isDefaultScheme(s1) && isDefaultScheme(s2)) return 1; if (s1.getName().equals(DEFAULT_NAME)) return -1; if (s2.getName().equals(DEFAULT_NAME)) return 1; return s1.getName().compareToIgnoreCase(s2.getName()); } }); return result; }
@NotNull @Override protected List<EditorHighlighterProvider> buildExtensions(@NotNull String stringKey, @NotNull final FileType key) { List<EditorHighlighterProvider> fromEP = super.buildExtensions(stringKey, key); if (fromEP.isEmpty()) { EditorHighlighterProvider defaultProvider = new EditorHighlighterProvider() { @Override public EditorHighlighter getEditorHighlighter(@Nullable Project project, @NotNull FileType fileType, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) { return EditorHighlighterFactory.getInstance().createEditorHighlighter( SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, virtualFile), colors); } }; return Collections.singletonList(defaultProvider); } return fromEP; }
@Override @NotNull public NewColorAndFontPanel createPanel(@NotNull ColorAndFontOptions options) { FontEditorPreview previewPanel = new FontEditorPreview(options, false) { @Override protected EditorColorsScheme updateOptionsScheme(EditorColorsScheme selectedScheme) { return ConsoleViewUtil.updateConsoleColorScheme(selectedScheme); } }; return new NewColorAndFontPanel(new SchemesPanel(options), new ConsoleFontOptions(options), previewPanel, "Font", null, null){ @Override public boolean containsFontOptions() { return true; } }; }
public void testInfoTestAttributes() throws Exception { LanguageExtensionPoint<Annotator> extension = new LanguageExtensionPoint<Annotator>(); extension.language="TEXT"; extension.implementationClass = TestAnnotator.class.getName(); PlatformTestUtil.registerExtension(ExtensionPointName.create(LanguageAnnotators.EP_NAME), extension, getTestRootDisposable()); myFixture.configureByText(PlainTextFileType.INSTANCE, "foo"); EditorColorsScheme scheme = new EditorColorsSchemeImpl(new DefaultColorsScheme()){{initFonts();}}; scheme.setAttributes(HighlighterColors.TEXT, new TextAttributes(Color.black, Color.white, null, null, Font.PLAIN)); ((EditorEx)myFixture.getEditor()).setColorsScheme(scheme); myFixture.doHighlighting(); MarkupModel model = DocumentMarkupModel.forDocument(myFixture.getEditor().getDocument(), getProject(), false); RangeHighlighter[] highlighters = model.getAllHighlighters(); assertEquals(1, highlighters.length); TextAttributes attributes = highlighters[0].getTextAttributes(); assertNotNull(attributes); assertNull(attributes.getBackgroundColor()); assertNull(attributes.getForegroundColor()); }
@NotNull private static JTextPane createTaskTextPane() { final JTextPane taskTextPane = new JTextPane(); taskTextPane.setContentType(new HTMLEditorKit().getContentType()); final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); int fontSize = editorColorsScheme.getEditorFontSize(); final String fontName = editorColorsScheme.getEditorFontName(); final Font font = new Font(fontName, Font.PLAIN, fontSize); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument)taskTextPane.getDocument()).getStyleSheet().addRule(bodyRule); taskTextPane.setEditable(false); if (!UIUtil.isUnderDarcula()) { taskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()); } taskTextPane.setBorder(new EmptyBorder(15, 20, 0, 100)); return taskTextPane; }
public void setUI(final TreeUI ui) { super.setUI(ui); // [vova] we cannot create this hash in constructor and just clear it here. The // problem is that setUI is invoked by constructor of superclass. myHighlightAttributes = new HashMap<HighlightSeverity, Map<SimpleTextAttributes, SimpleTextAttributes>>(); final EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme(); final TextAttributes attributes = globalScheme.getAttributes(JavaHighlightingColors.STRING); myBindingAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, UIUtil.getTreeForeground()); myClassAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getTreeForeground()); myPackageAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, Color.GRAY); myTitleAttributes =new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, attributes.getForegroundColor()); myUnknownAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_WAVED, Color.RED); }
private SoyFileType() { super(SoyLanguage.INSTANCE); FileTypeEditorHighlighterProviders.INSTANCE.addExplicitExtension( this, (@Nullable Project project, @NotNull FileType fileType, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme editorColorsScheme) -> new SoyLayeredHighlighter(project, virtualFile, editorColorsScheme)); }
public static void drawAnswerPlaceholderFromPrevStep(@NotNull Editor editor, int start, int end) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); Color color = scheme.getColor(EditorColors.TEARLINE_COLOR); SimpleTextAttributes attributes = SimpleTextAttributes.GRAY_ATTRIBUTES; final TextAttributes textAttributes = new TextAttributes(attributes.getFgColor(), color, null, null, attributes.getFontStyle()); drawAnswerPlaceholder(editor, start, end, textAttributes, HighlighterLayer.LAST); }
private void updatePreviewHighlighter(EditorEx editor) { EditorColorsScheme scheme = editor.getColorsScheme(); editor.getSettings().setCaretRowShown(false); EditorHighlighter highlighter = this.createHighlighter(scheme); if (highlighter != null) { editor.setHighlighter(highlighter); } }
@Override public LineMarkerInfo getLineMarkerInfo(final PsiElement element) { if (element instanceof LuaReturnStatement && LuaApplicationSettings.getInstance().SHOW_TAIL_CALLS_IN_GUTTER) { LuaReturnStatement e = (LuaReturnStatement) element; if (e.isTailCall()) return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), LuaIcons.TAIL_RECURSION, Pass.UPDATE_ALL, tailCallTooltip, null, GutterIconRenderer.Alignment.LEFT); } if (myDaemonSettings.SHOW_METHOD_SEPARATORS) { if (element instanceof LuaDocComment) { LuaDocCommentOwner owner = ((LuaDocComment) element).getOwner(); if (owner instanceof LuaFunctionDefinition) { TextRange range = new TextRange(element.getTextOffset(), owner.getTextRange().getEndOffset()); LineMarkerInfo<PsiElement> info = new LineMarkerInfo<PsiElement>(element, range, null, Pass.UPDATE_ALL, NullableFunction.NULL, null, GutterIconRenderer.Alignment.RIGHT); EditorColorsScheme scheme = myColorsManager.getGlobalScheme(); info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR); info.separatorPlacement = SeparatorPlacement.TOP; return info; } } } return null; }
public static void applyHighlightRange(ArrayList<TextRange> ranges, Project project, Editor editor) { if (project == null) { return; } EditorColorsScheme scheme = editor.getColorsScheme(); TextAttributes attributes = scheme.getAttributes(TemplateColors.TEMPLATE_VARIABLE_ATTRIBUTES); for (TextRange textRange : ranges) { HighlightManager.getInstance(project).addRangeHighlight( editor, textRange.getBegin(), textRange.getEnd(), attributes, true, null); } }
private CommandInputForm(final JFrame ideFrame, Component sourceComponent, AnActionEvent originalEvent) { super(ideFrame, true); this.ideFrame = ideFrame; this.setUndecorated(true); this.sourceComponent = sourceComponent; this.originalEvent = originalEvent; this.add(topPanel); EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); Font commandFont = new Font(scheme.getConsoleFontName(), Font.PLAIN, scheme.getConsoleFontSize()); commandField.setFont(commandFont); this.pack(); popupMenu = new JPopupMenu(); topPanel.setComponentPopupMenu(popupMenu); topPanel.setBorder(BorderFactory.createLineBorder(JBColor.gray)); this.setAlwaysOnTop(true); commandField.setRequestFocusEnabled(true); commandField.addActionListener(e -> { }); KeyStroke escKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); commandField.registerKeyboardAction(e -> { popupMenu.setVisible(false); CommandInputForm.this.setVisible(false); CommandInputForm.this.dispose(); currTyped = null; focusOnIdeFrame(ideFrame); }, escKeyStroke, JComponent.WHEN_FOCUSED); commandField.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(DocumentEvent documentEvent) { onTextChange(); } }); }
public RythmLayeredSyntaxHighlighter(Project project, EditorColorsScheme scheme, FileType ptype, VirtualFile virtualFile) { super(new RythmSyntaxHighlighter(), scheme); FileType type = null; //Test for Java implementation FileType type1 = null; if (project == null || virtualFile == null) { type = StdFileTypes.PLAIN_TEXT; } else { Language language = TemplateDataLanguageMappings.getInstance(project).getMapping(virtualFile); if (language != null) type = language.getAssociatedFileType(); if (type == null) { type = RythmLanguage.getDefaultTemplateLang(); //Test for Java implementation //type1 = RythmLanguage.getLanguage(); } } SyntaxHighlighter outerHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(type, project, virtualFile); registerLayer(TEXT, new LayerDescriptor(outerHighlighter, "")); //Test for Java implementation /* SyntaxHighlighter middleHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(type1, project, virtualFile); registerLayer(TEXT, new LayerDescriptor(middleHighlighter, "")); */ }
public void invokeHint(Runnable hideRunnable) { myHideRunnable = hideRunnable; if (!canShowHint()) { hideHint(); return; } if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); TextAttributes attributes = scheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR); attributes = NavigationUtil.patchAttributesColor(attributes, myCurrentRange, myEditor); myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(myCurrentRange.getStartOffset(), myCurrentRange.getEndOffset(), HighlighterLayer.SELECTION + 1, attributes, HighlighterTargetArea.EXACT_RANGE); Component internalComponent = myEditor.getContentComponent(); myStoredCursor = internalComponent.getCursor(); internalComponent.addKeyListener(myEditorKeyListener); internalComponent.setCursor(hintCursor()); if (LOG.isDebugEnabled()) { LOG.debug("internalComponent.setCursor(hintCursor())"); } } else { evaluateAndShowHint(); } }
private GroovyFileType() { super(GroovyLanguage.INSTANCE); FileTypeEditorHighlighterProviders.INSTANCE.addExplicitExtension(this, new EditorHighlighterProvider() { @Override public EditorHighlighter getEditorHighlighter(@Nullable Project project, @NotNull FileType fileType, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) { return new GroovyEditorHighlighter(colors); } }); GROOVY_FILE_TYPES.add(this); }
public void addImportedScheme(@NotNull EditorColorsScheme imported) { MyColorScheme newScheme = new MyColorScheme(imported); initScheme(newScheme); mySchemes.put(imported.getName(), newScheme); selectScheme(newScheme.getName()); resetSchemesCombo(null); }
public LookupCellRenderer(LookupImpl lookup) { EditorColorsScheme scheme = lookup.getEditor().getColorsScheme(); myNormalFont = scheme.getFont(EditorFontType.PLAIN); myBoldFont = scheme.getFont(EditorFontType.BOLD); myLookup = lookup; myNameComponent = new MySimpleColoredComponent(); myNameComponent.setIpad(JBUI.insetsLeft(2)); myNameComponent.setMyBorder(null); myTailComponent = new MySimpleColoredComponent(); myTailComponent.setIpad(new Insets(0, 0, 0, 0)); myTypeLabel = new MySimpleColoredComponent(); myTypeLabel.setIpad(new Insets(0, 0, 0, 0)); myPanel = new LookupPanel(); myPanel.add(myNameComponent, BorderLayout.WEST); myPanel.add(myTailComponent, BorderLayout.CENTER); myTailComponent.setBorder(new EmptyBorder(0, 0, 0, AFTER_TAIL)); myPanel.add(myTypeLabel, BorderLayout.EAST); myTypeLabel.setBorder(new EmptyBorder(0, 0, 0, AFTER_TYPE)); myNormalMetrics = myLookup.getEditor().getComponent().getFontMetrics(myNormalFont); myBoldMetrics = myLookup.getEditor().getComponent().getFontMetrics(myBoldFont); }
@Nullable private static ExternalLintAnnotationInput collectInformation(@NotNull PsiFile psiFile, @Nullable Editor editor) { if (psiFile.getContext() != null || !SassLintConfigFileUtil.isSassFile(psiFile)) { return null; } VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null || !virtualFile.isInLocalFileSystem()) { return null; } if (psiFile.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider) { return null; } Project project = psiFile.getProject(); SassLintProjectComponent component = project.getComponent(SassLintProjectComponent.class); if (!component.isSettingsValid() || !component.isEnabled()) { return null; } Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); if (document == null) { return null; } String fileContent = document.getText(); if (StringUtil.isEmptyOrSpaces(fileContent)) { return null; } EditorColorsScheme colorsScheme = editor != null ? editor.getColorsScheme() : null; // tabSize = getTabSize(editor); // tabSize = 4; return new ExternalLintAnnotationInput(project, psiFile, fileContent, colorsScheme); }
public void testSharedScopeBased() throws Exception { NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_ANY, null)); NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null)); NamedScopesHolder scopeManager = DependencyValidationManager.getInstance(getProject()); scopeManager.addScope(xScope); scopeManager.addScope(utilScope); EditorColorsManager manager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); manager.addColorsScheme(scheme); EditorColorsManager.getInstance().setGlobalScheme(scheme); TextAttributesKey xKey = ScopeAttributesUtil.getScopeTextAttributeKey(xScope.getName()); TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, null, Font.ITALIC); scheme.setAttributes(xKey, xAttributes); TextAttributesKey utilKey = ScopeAttributesUtil.getScopeTextAttributeKey(utilScope.getName()); TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD); scheme.setAttributes(utilKey, utilAttributes); NamedScope projectScope = PackagesScopesProvider.getInstance(myProject).getProjectProductionScope(); TextAttributesKey projectKey = ScopeAttributesUtil.getScopeTextAttributeKey(projectScope.getName()); TextAttributes projectAttributes = new TextAttributes(null, null, Color.blue, EffectType.BOXED, Font.ITALIC); scheme.setAttributes(projectKey, projectAttributes); try { testFile(BASE_PATH + "/scopeBased/x/Shared.java").projectRoot(BASE_PATH + "/scopeBased").checkSymbolNames().test(); } finally { scopeManager.removeAllSets(); } }
@Override public void apply(EditorColorsScheme scheme) { if (myGetSetBackground != null) { myGetSetBackground.apply(scheme); } if (myGetSetForeground != null) { myGetSetForeground.apply(scheme); } }
private void highlightBrace(@NotNull TextRange braceRange, boolean matched) { EditorColorsScheme scheme = myEditor.getColorsScheme(); final TextAttributes attributes = matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES) : scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES); RangeHighlighter rbraceHighlighter = myEditor.getMarkupModel().addRangeHighlighter( braceRange.getStartOffset(), braceRange.getEndOffset(), HighlighterLayer.LAST + 1, attributes, HighlighterTargetArea.EXACT_RANGE); rbraceHighlighter.setGreedyToLeft(false); rbraceHighlighter.setGreedyToRight(false); registerHighlighter(rbraceHighlighter); }
@NotNull public static List<DividerSeparator> createVisibleSeparators(@NotNull Editor editor1, @NotNull Editor editor2, @NotNull DividerSeparatorPaintable paintable) { final List<DividerSeparator> separators = new ArrayList<DividerSeparator>(); final Transformation[] transformations = new Transformation[]{getTransformation(editor1), getTransformation(editor2)}; final Interval leftInterval = getVisibleInterval(editor1); final Interval rightInterval = getVisibleInterval(editor2); final int height1 = editor1.getLineHeight(); final int height2 = editor2.getLineHeight(); final EditorColorsScheme scheme = editor1.getColorsScheme(); paintable.process(new DividerSeparatorPaintable.Handler() { @Override public boolean process(int line1, int line2) { if (leftInterval.startLine > line1 + 1 && rightInterval.startLine > line2 + 1) return true; if (leftInterval.endLine < line1 && rightInterval.endLine < line2) return false; separators.add(createSeparator(transformations, line1, line2, height1, height2, scheme)); return true; } }); return separators; }
@NotNull private static DividerSeparator createSeparator(@NotNull Transformation[] transformations, int line1, int line2, int height1, int height2, @Nullable EditorColorsScheme scheme) { int start1 = transformations[0].transform(line1); int start2 = transformations[1].transform(line2); return new DividerSeparator(start1, start2, start1 + height1, start2 + height2, scheme); }
@Override protected void setUp() throws Exception { super.setUp(); mySavedScheme = EditorColorsManager.getInstance().getGlobalScheme(); myTestScheme = (EditorColorsScheme)mySavedScheme.clone(); myTestScheme.setName("EditingTest.testScheme"); EditorColorsManager.getInstance().addColorsScheme(myTestScheme); EditorColorsManager.getInstance().setGlobalScheme(myTestScheme); }
@NotNull @Override public EditorHighlighter createEditorHighlighter(@NotNull final FileType fileType, @NotNull final EditorColorsScheme settings, final Project project) { if (fileType instanceof LanguageFileType) { return FileTypeEditorHighlighterProviders.INSTANCE.forFileType(fileType).getEditorHighlighter(project, fileType, null, settings); } SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, null); return createEditorHighlighter(highlighter, settings); }
public ColorAndFontDescription(@NotNull String name, @Nullable String group, @Nullable String type, @Nullable EditorColorsScheme scheme, @Nullable Icon icon, @Nullable String toolTip) { myName = name; myGroup = group; myType = type; myScheme = scheme; myIcon = icon; myToolTip = toolTip; }
public void apply(@NotNull EditorColorsScheme scheme) { scheme.setFontPreferences(getFontPreferences()); scheme.setLineSpacing(myLineSpacing); scheme.setQuickDocFontSize(getQuickDocFontSize()); scheme.setConsoleFontPreferences(getConsoleFontPreferences()); scheme.setConsoleLineSpacing(getConsoleLineSpacing()); for (EditorSchemeAttributeDescriptor descriptor : myDescriptors) { descriptor.apply(scheme); } }
public static void uninstall() { JBColor.setDark(false); IconLoader.setUseDarkIcons(false); if (DarculaLaf.NAME.equals(EditorColorsManager.getInstance().getGlobalScheme().getName())) { final EditorColorsScheme scheme = EditorColorsManager.getInstance().getScheme(EditorColorsScheme.DEFAULT_SCHEME_NAME); if (scheme != null) { EditorColorsManager.getInstance().setGlobalScheme(scheme); } } update(); }
public static SimpleTextAttributes getSimpleTextAttributes(@Nullable final ItemPresentation presentation, @NotNull EditorColorsScheme colorsScheme) { if (presentation instanceof ColoredItemPresentation) { final TextAttributesKey textAttributesKey = ((ColoredItemPresentation) presentation).getTextAttributesKey(); if (textAttributesKey == null) return SimpleTextAttributes.REGULAR_ATTRIBUTES; final TextAttributes textAttributes = colorsScheme.getAttributes(textAttributesKey); return textAttributes == null ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.fromTextAttributes(textAttributes); } return SimpleTextAttributes.REGULAR_ATTRIBUTES; }
private HighlightingSessionImpl(@NotNull PsiFile psiFile, @Nullable Editor editor, @NotNull DaemonProgressIndicator progressIndicator, EditorColorsScheme editorColorsScheme) { myPsiFile = psiFile; myEditor = editor; myProgressIndicator = progressIndicator; myEditorColorsScheme = editorColorsScheme; myProject = psiFile.getProject(); myDocument = PsiDocumentManager.getInstance(myProject).getDocument(psiFile); }