Skip to content

Commit

Permalink
Merge CSS and XML folding settings (WEB-21768)
Browse files Browse the repository at this point in the history
  • Loading branch information
zolotov committed Jul 8, 2016
1 parent ebbe04b commit 9b64521
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ public XmlCodeFoldingOptionsProvider() {
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"));
}
}
16 changes: 16 additions & 0 deletions xml/xml-psi-api/src/com/intellij/lang/XmlCodeFoldingSettings.java
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@
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;
Expand All @@ -43,19 +52,25 @@ public boolean isCollapseEntities() {
return myState.COLLAPSE_ENTITIES;
}

@Override
public boolean isCollapseDataUri() {
return myState.COLLAPSE_DATA_URI;
}

@Override
public State getState() {
return myState;
}

@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;
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -28,7 +28,6 @@
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;
Expand Down Expand Up @@ -266,7 +265,7 @@ protected boolean isEntity(PsiElement psi) {
}

private static boolean isAttributeShouldBeFolded(XmlAttribute child) {
return child.getContainingFile() instanceof HtmlFileImpl &&
return HtmlUtil.isHtmlFile(child.getContainingFile()) &&
HtmlUtil.STYLE_ATTRIBUTE_NAME.equalsIgnoreCase(child.getName());
}

Expand Down

0 comments on commit 9b64521

Please sign in to comment.