Merge CSS and XML folding settings (WEB-21768)

This commit is contained in:
Alexander Zolotov
2016-07-08 12:25:08 +03:00
parent ebbe04be72
commit 9b645211e3
6 changed files with 99 additions and 5 deletions
@@ -375,6 +375,7 @@ group.code.folding=Code Folding
checkbox.collapse.xml.tags=XML tags
checkbox.collapse.html.style.attribute=HTML 'style' attribute
checkbox.collapse.entities=XML entities
checkbox.collapse.data.uri=Data URIs
checkbox.collapse.anonymous.classes=<html>Anonymous classes</html>
checkbox.collapse.closures=<html>"Closures" (anonymous classes implementing one method, before Java 8)</html>
checkbox.collapse.generic.constructor.parameters=<html>Generic constructor and method parameters</html>
@@ -29,5 +29,6 @@ public class XmlCodeFoldingOptionsProvider extends BeanConfigurable<XmlFoldingSe
checkBox("COLLAPSE_XML_TAGS", ApplicationBundle.message("checkbox.collapse.xml.tags"));
checkBox("COLLAPSE_HTML_STYLE_ATTRIBUTE", ApplicationBundle.message("checkbox.collapse.html.style.attribute"));
checkBox("COLLAPSE_ENTITIES", ApplicationBundle.message("checkbox.collapse.entities"));
checkBox("COLLAPSE_DATA_URI", ApplicationBundle.message("checkbox.collapse.data.uri"));
}
}
@@ -1,7 +1,23 @@
/*
* Copyright 2000-2016 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.lang;
public interface XmlCodeFoldingSettings {
boolean isCollapseXmlTags();
boolean isCollapseHtmlStyleAttribute();
boolean isCollapseEntities();
boolean isCollapseDataUri();
}
@@ -0,0 +1,62 @@
/*
* Copyright 2000-2016 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.application.options.editor;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.Nullable;
/**
* User: zolotov
* Date: 4/18/13
* @deprecated use {@link XmlFoldingSettings}
* todo: delete after 2017.1 release
*/
@State(
name="CssFoldingSettings",
storages= {
@Storage(value = "editor.codeinsight.xml", deprecated = true)}
)
public class CssFoldingSettings implements PersistentStateComponent<CssFoldingSettings> {
public static CssFoldingSettings getInstance() {
return ServiceManager.getService(CssFoldingSettings.class);
}
private boolean myCollapseDataUri = true;
public boolean isCollapseDataUri() {
return myCollapseDataUri;
}
@SuppressWarnings("UnusedDeclaration")
public void setCollapseDataUri(boolean value) {
myCollapseDataUri = value;
}
@Nullable
@Override
public CssFoldingSettings getState() {
return this;
}
@Override
public void loadState(CssFoldingSettings state) {
XmlSerializerUtil.copyBean(state, this);
}
}
@@ -20,15 +20,24 @@ import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
@State(name = "XmlFoldingSettings", storages = @Storage("editor.codeinsight.xml"))
public class XmlFoldingSettings implements XmlCodeFoldingSettings, PersistentStateComponent<XmlFoldingSettings.State> {
private XmlFoldingSettings.State myState;
private final XmlFoldingSettings.State myState = new State();
public static XmlFoldingSettings getInstance() {
return ServiceManager.getService(XmlFoldingSettings.class);
}
public XmlFoldingSettings() {
// todo: remove after 2017.1 release
CssFoldingSettings cssFoldingSettings = CssFoldingSettings.getInstance();
if (cssFoldingSettings != null) {
myState.COLLAPSE_DATA_URI = cssFoldingSettings.isCollapseDataUri();
}
}
@Override
public boolean isCollapseXmlTags() {
return myState.COLLAPSE_XML_TAGS;
@@ -43,6 +52,11 @@ public class XmlFoldingSettings implements XmlCodeFoldingSettings, PersistentSta
return myState.COLLAPSE_ENTITIES;
}
@Override
public boolean isCollapseDataUri() {
return myState.COLLAPSE_DATA_URI;
}
@Override
public State getState() {
return myState;
@@ -50,12 +64,13 @@ public class XmlFoldingSettings implements XmlCodeFoldingSettings, PersistentSta
@Override
public void loadState(State state) {
myState = state;
XmlSerializerUtil.copyBean(state, myState);
}
public static final class State {
public boolean COLLAPSE_XML_TAGS = false;
public boolean COLLAPSE_HTML_STYLE_ATTRIBUTE = true;
public boolean COLLAPSE_ENTITIES = true;
public boolean COLLAPSE_DATA_URI = true;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -28,7 +28,6 @@ import com.intellij.openapi.util.UnfairTextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.impl.source.html.HtmlFileImpl;
import com.intellij.psi.impl.source.xml.XmlEntityRefImpl;
import com.intellij.psi.impl.source.xml.XmlTokenImpl;
import com.intellij.psi.tree.TokenSet;
@@ -266,7 +265,7 @@ public abstract class XmlCodeFoldingBuilder implements FoldingBuilder, DumbAware
}
private static boolean isAttributeShouldBeFolded(XmlAttribute child) {
return child.getContainingFile() instanceof HtmlFileImpl &&
return HtmlUtil.isHtmlFile(child.getContainingFile()) &&
HtmlUtil.STYLE_ATTRIBUTE_NAME.equalsIgnoreCase(child.getName());
}