tag tree highlighting: support for changing number of levels to highlight

This commit is contained in:
Eugene Kudelevsky
2011-03-25 21:04:32 +03:00
parent 4de66b793f
commit f6e8e7c8d5
8 changed files with 209 additions and 50 deletions
@@ -87,6 +87,8 @@
<editorSmartKeysConfigurable instance="com.intellij.application.options.editor.WebEditorOptionsProvider"/>
<editorAppearanceConfigurable instance="com.intellij.application.options.editor.WebEditorAppearanceConfigurable"/>
<editorAppearanceConfigurable instance="com.intellij.codeInsight.daemon.impl.tagTreeHighlighting.HtmlTagTreeHighlightingConfigurable"/>
<autoImportOptionsProvider instance="com.intellij.application.options.XmlAutoImportOptionsProvider"/>
<highlightErrorFilter implementation="com.intellij.codeInsight.highlighting.HtmlClosingTagErrorFilter"/>
@@ -15,16 +15,8 @@
*/
package com.intellij.application.options.editor;
import com.intellij.codeInsight.daemon.impl.tagTreeHighlighting.HtmlTagTreeHighlightingPass;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.options.BeanConfigurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.xml.XmlBundle;
/**
@@ -36,23 +28,5 @@ public class WebEditorAppearanceConfigurable extends BeanConfigurable<WebEditorO
checkBox("breadcrumbsEnabled", XmlBundle.message("xml.editor.options.breadcrumbs.title"));
checkBox("breadcrumbsEnabledInXml", XmlBundle.message("xml.editor.options.breadcrumbs.for.xml.title"));
checkBox("showCssColorPreviewInGutter", "Show CSS Color preview icon in gutter");
checkBox("tagTreeHighlightingEnabled", "Enable HTML tag tree highlighting");
}
@Override
public void apply() throws ConfigurationException {
super.apply();
clearTagTreeHighlighting();
}
private static void clearTagTreeHighlighting() {
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
for (FileEditor fileEditor : FileEditorManager.getInstance(project).getAllEditors()) {
if (fileEditor instanceof TextEditor) {
final Editor editor = ((TextEditor)fileEditor).getEditor();
HtmlTagTreeHighlightingPass.clearHighlightingAndLineMarkers(editor, project);
}
}
}
}
}
@@ -47,7 +47,9 @@ public class WebEditorOptions implements PersistentStateComponent<WebEditorOptio
private boolean myAutomaticallyStartAttribute = true;
private boolean myZenCodingEnabled = true;
private int myZenCodingExpandShortcut = TemplateSettings.TAB_CHAR;
private boolean myTagTreeHighlightingEnabled = true;
private int myTagTreeHighlightingLevelCount = 6;
public static WebEditorOptions getInstance() {
return ServiceManager.getService(WebEditorOptions.class);
@@ -125,6 +127,14 @@ public class WebEditorOptions implements PersistentStateComponent<WebEditorOptio
myAutomaticallyInsertRequiredSubTags = automaticallyInsertRequiredSubTags;
}
public void setTagTreeHighlightingLevelCount(int tagTreeHighlightingLevelCount) {
myTagTreeHighlightingLevelCount = tagTreeHighlightingLevelCount;
}
public int getTagTreeHighlightingLevelCount() {
return myTagTreeHighlightingLevelCount;
}
public void setTagTreeHighlightingEnabled(boolean tagTreeHighlightingEnabled) {
myTagTreeHighlightingEnabled = tagTreeHighlightingEnabled;
}
@@ -15,7 +15,9 @@
*/
package com.intellij.codeInsight.daemon.impl.tagTreeHighlighting;
import com.intellij.application.options.editor.WebEditorOptions;
import com.intellij.openapi.editor.colors.ColorKey;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
@@ -23,17 +25,25 @@ import java.awt.*;
* @author Eugene.Kudelevsky
*/
public class HtmlTagTreeHighlightingColors {
// todo: support adding any number of keys
public static final ColorKey[] COLOR_KEYS = new ColorKey[6];
private static ColorKey[] ourColorKeys = null;
static {
final Color[] baseColors = new Color[]{Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA};
for (int i = 0; i < COLOR_KEYS.length; i++) {
COLOR_KEYS[i] = ColorKey.createColorKey("HTML_TAG_TREE_LEVEL" + i, baseColors[i % baseColors.length]);
}
}
private static final Color[] DEFAULT_COLORS = new Color[]{Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA};
private HtmlTagTreeHighlightingColors() {
}
@NotNull
public static ColorKey[] getColorKeys() {
final int levelCount = WebEditorOptions.getInstance().getTagTreeHighlightingLevelCount();
if (ourColorKeys == null || ourColorKeys.length != levelCount) {
ourColorKeys = new ColorKey[levelCount];
for (int i = 0; i < ourColorKeys.length; i++) {
ourColorKeys[i] = ColorKey.createColorKey("HTML_TAG_TREE_LEVEL" + i, DEFAULT_COLORS[i % DEFAULT_COLORS.length]);
}
}
return ourColorKeys;
}
}
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.codeInsight.daemon.impl.tagTreeHighlighting.HtmlTagTreeHighlightingConfigurable">
<grid id="27dc6" binding="myContentPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="422" height="55"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="b5068" class="javax.swing.JCheckBox" binding="myEnableTagTreeHighlightingCheckBox">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Enable HTML tag tree highlighting"/>
</properties>
</component>
<grid id="30544" binding="myLevelsPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="84b2a" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="3" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Levels to highlight:"/>
</properties>
</component>
<component id="f41b2" class="javax.swing.JSpinner" binding="myLevelsSpinner">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="50" height="-1"/>
<maximum-size width="50" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
<hspacer id="dd839">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</form>
@@ -0,0 +1,112 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInsight.daemon.impl.tagTreeHighlighting;
import com.intellij.application.options.editor.WebEditorOptions;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.util.ui.UIUtil;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author Eugene.Kudelevsky
*/
public class HtmlTagTreeHighlightingConfigurable implements UnnamedConfigurable {
private JCheckBox myEnableTagTreeHighlightingCheckBox;
private JSpinner myLevelsSpinner;
private JPanel myLevelsPanel;
private JPanel myContentPanel;
public HtmlTagTreeHighlightingConfigurable() {
myLevelsSpinner.setModel(new SpinnerNumberModel(1, 1, 50, 1));
myEnableTagTreeHighlightingCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final boolean enabled = myEnableTagTreeHighlightingCheckBox.isSelected();
UIUtil.setEnabled(myLevelsPanel, enabled, true);
}
});
}
@Override
public JComponent createComponent() {
return myContentPanel;
}
@Override
public boolean isModified() {
final WebEditorOptions options = WebEditorOptions.getInstance();
if (myEnableTagTreeHighlightingCheckBox.isSelected() != options.isTagTreeHighlightingEnabled()) {
return true;
}
if (getLevelCount() != options.getTagTreeHighlightingLevelCount()) {
return true;
}
return false;
}
@Override
public void apply() throws ConfigurationException {
final WebEditorOptions options = WebEditorOptions.getInstance();
options.setTagTreeHighlightingEnabled(myEnableTagTreeHighlightingCheckBox.isSelected());
options.setTagTreeHighlightingLevelCount(getLevelCount());
clearTagTreeHighlighting();
}
private int getLevelCount() {
return ((Integer)myLevelsSpinner.getValue()).intValue();
}
private static void clearTagTreeHighlighting() {
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
for (FileEditor fileEditor : FileEditorManager.getInstance(project).getAllEditors()) {
if (fileEditor instanceof TextEditor) {
final Editor editor = ((TextEditor)fileEditor).getEditor();
HtmlTagTreeHighlightingPass.clearHighlightingAndLineMarkers(editor, project);
}
}
}
}
@Override
public void reset() {
final WebEditorOptions options = WebEditorOptions.getInstance();
final boolean enabled = options.isTagTreeHighlightingEnabled();
myEnableTagTreeHighlightingCheckBox.setSelected(enabled);
myLevelsSpinner.setValue(options.getTagTreeHighlightingLevelCount());
UIUtil.setEnabled(myLevelsPanel, enabled, true);
}
@Override
public void disposeUIResources() {
}
}
@@ -240,7 +240,7 @@ public class HtmlTagTreeHighlightingPass extends TextEditorHighlightingPass {
private static Color[] getBaseColors() {
final ColorKey[] colorKeys = HtmlTagTreeHighlightingColors.COLOR_KEYS;
final ColorKey[] colorKeys = HtmlTagTreeHighlightingColors.getColorKeys();
final Color[] colors = new Color[colorKeys.length];
final EditorColorsScheme colorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.daemon.impl.tagTreeHighlighting.HtmlTagTreeHighl
import com.intellij.ide.highlighter.HtmlFileHighlighter;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.editor.XmlHighlighterColors;
import com.intellij.openapi.editor.colors.ColorKey;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
@@ -42,19 +43,6 @@ public class HTMLColorsPage implements ColorSettingsPage {
};
private static final String FULL_PRODUCT_NAME = ApplicationNamesInfo.getInstance().getFullProductName();
private static final ColorDescriptor[] COLOR_DESCRIPTORS;
static {
COLOR_DESCRIPTORS = new ColorDescriptor[HtmlTagTreeHighlightingColors.COLOR_KEYS.length];
for (int i = 0; i < COLOR_DESCRIPTORS.length; i++) {
COLOR_DESCRIPTORS[i] = new ColorDescriptor(OptionsBundle.message("options.html.attribute.descriptor.tag.tree", i + 1),
HtmlTagTreeHighlightingColors.COLOR_KEYS[i], ColorDescriptor.Kind.BACKGROUND);
}
// todo: make preview for it
}
@NotNull
public String getDisplayName() {
return OptionsBundle.message("options.html.display.name");
@@ -71,7 +59,17 @@ public class HTMLColorsPage implements ColorSettingsPage {
@NotNull
public ColorDescriptor[] getColorDescriptors() {
return COLOR_DESCRIPTORS;
// todo: make preview for it
final ColorKey[] colorKeys = HtmlTagTreeHighlightingColors.getColorKeys();
final ColorDescriptor[] colorDescriptors = new ColorDescriptor[colorKeys.length];
for (int i = 0; i < colorDescriptors.length; i++) {
colorDescriptors[i] = new ColorDescriptor(OptionsBundle.message("options.html.attribute.descriptor.tag.tree", i + 1),
colorKeys[i], ColorDescriptor.Kind.BACKGROUND);
}
return colorDescriptors;
}
@NotNull