From f6e8e7c8d5eb49b06612818fc58c1c9040faaed4 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Fri, 25 Mar 2011 21:04:32 +0300 Subject: [PATCH] tag tree highlighting: support for changing number of levels to highlight --- .../src/META-INF/XmlPlugin.xml | 2 + .../WebEditorAppearanceConfigurable.java | 26 ---- .../options/editor/WebEditorOptions.java | 10 ++ .../HtmlTagTreeHighlightingColors.java | 28 +++-- .../HtmlTagTreeHighlightingConfigurable.form | 53 +++++++++ .../HtmlTagTreeHighlightingConfigurable.java | 112 ++++++++++++++++++ .../HtmlTagTreeHighlightingPass.java | 2 +- .../options/colors/pages/HTMLColorsPage.java | 26 ++-- 8 files changed, 209 insertions(+), 50 deletions(-) create mode 100644 xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingConfigurable.form create mode 100644 xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingConfigurable.java diff --git a/platform/platform-resources/src/META-INF/XmlPlugin.xml b/platform/platform-resources/src/META-INF/XmlPlugin.xml index c3fc74bea79a..a75f44f3e3fb 100644 --- a/platform/platform-resources/src/META-INF/XmlPlugin.xml +++ b/platform/platform-resources/src/META-INF/XmlPlugin.xml @@ -87,6 +87,8 @@ + + diff --git a/xml/impl/src/com/intellij/application/options/editor/WebEditorAppearanceConfigurable.java b/xml/impl/src/com/intellij/application/options/editor/WebEditorAppearanceConfigurable.java index e4823acf0781..4f68031c75f2 100644 --- a/xml/impl/src/com/intellij/application/options/editor/WebEditorAppearanceConfigurable.java +++ b/xml/impl/src/com/intellij/application/options/editor/WebEditorAppearanceConfigurable.java @@ -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 +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingConfigurable.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingConfigurable.java new file mode 100644 index 000000000000..0b15e38f5eb1 --- /dev/null +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingConfigurable.java @@ -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() { + } +} diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingPass.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingPass.java index 26ff294aa781..e43b19e9205e 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingPass.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/HtmlTagTreeHighlightingPass.java @@ -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(); diff --git a/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java b/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java index b7e035101ac2..c5e5ce97780d 100644 --- a/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java +++ b/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java @@ -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