added settings for new types of foldable blocks
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 24 Nov 2015 12:10:53 +0000 (15:10 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Fri, 27 Nov 2015 09:30:12 +0000 (12:30 +0300)
python/src/META-INF/python-core.xml
python/src/com/jetbrains/python/PythonFoldingBuilder.java
python/src/com/jetbrains/python/PythonFoldingOptionsProvider.java [new file with mode: 0644]
python/src/com/jetbrains/python/PythonFoldingSettings.java [new file with mode: 0644]

index 56be30cd9bb6ca94d5717cae197ced8e40c85ece..3e4ba4cb5750887d2e97db52c8b869fbd9dcbf9a 100644 (file)
 
     <lang.inspectionSuppressor language="Python" implementationClass="com.jetbrains.python.inspections.PyInspectionsSuppressor"/>
     <refactoring.invertBoolean implementation="com.jetbrains.python.refactoring.invertBoolean.PyInvertBooleanDelegate"/>
+
+    <!--folding-->
+    <codeFoldingOptionsProvider instance="com.jetbrains.python.PythonFoldingOptionsProvider"/>
+    <applicationService serviceInterface="com.jetbrains.python.PythonFoldingSettings"
+                        serviceImplementation="com.jetbrains.python.PythonFoldingSettings"/>
   </extensions>
 
   <extensionPoints>
index c140769194b084459a84bcce3c87be0eb0b8d708..26c73d5f8cfae93982358b9bdb30beb28eda330d 100644 (file)
@@ -235,11 +235,20 @@ public class PythonFoldingBuilder extends CustomFoldingBuilder implements DumbAw
         // method will be collapsed, no need to also collapse docstring
         return false;
       }
-      return CodeFoldingSettings.getInstance().COLLAPSE_DOC_COMMENTS;
+      if (getDocStringOwnerType(node) != null) {
+        return CodeFoldingSettings.getInstance().COLLAPSE_DOC_COMMENTS;
+      }
+      return PythonFoldingSettings.getInstance().isCollapseLongStrings();
+    }
+    if (node.getElementType() == PyTokenTypes.END_OF_LINE_COMMENT) {
+      return PythonFoldingSettings.getInstance().isCollapseSequentialComments();
     }
     if (node.getElementType() == PyElementTypes.STATEMENT_LIST && node.getTreeParent().getElementType() == PyElementTypes.FUNCTION_DECLARATION) {
       return CodeFoldingSettings.getInstance().COLLAPSE_METHODS;
     }
+    if (FOLDABLE_COLLECTIONS_LITERALS.contains(node.getElementType())) {
+      return PythonFoldingSettings.getInstance().isCollapseLongCollections();
+    }
     return false;
   }
 
diff --git a/python/src/com/jetbrains/python/PythonFoldingOptionsProvider.java b/python/src/com/jetbrains/python/PythonFoldingOptionsProvider.java
new file mode 100644 (file)
index 0000000..dd090ac
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2000-2015 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.jetbrains.python;
+
+import com.intellij.application.options.editor.CodeFoldingOptionsProvider;
+import com.intellij.openapi.options.BeanConfigurable;
+
+public class PythonFoldingOptionsProvider extends BeanConfigurable<PythonFoldingSettings> implements CodeFoldingOptionsProvider {
+  protected PythonFoldingOptionsProvider(PythonFoldingSettings instance) {
+    super(instance);
+    checkBox("COLLAPSE_LONG_STRINGS", "Long string literals");
+    checkBox("COLLAPSE_LONG_COLLECTIONS", "Long collection literals");
+    checkBox("COLLAPSE_SEQUENTIAL_COMMENTS", "Sequential comments");
+  }
+}
diff --git a/python/src/com/jetbrains/python/PythonFoldingSettings.java b/python/src/com/jetbrains/python/PythonFoldingSettings.java
new file mode 100644 (file)
index 0000000..714483d
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2000-2015 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.jetbrains.python;
+
+import com.intellij.openapi.components.*;
+import com.intellij.util.xmlb.XmlSerializerUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+@State(
+  name = "PythonFoldingSettings",
+  storages = @Storage(file = StoragePathMacros.APP_CONFIG + "/editor.codeinsight.xml")
+)
+public class PythonFoldingSettings implements PersistentStateComponent<PythonFoldingSettings> {
+  public boolean COLLAPSE_LONG_STRINGS = false;
+  public boolean COLLAPSE_LONG_COLLECTIONS = false;
+  public boolean COLLAPSE_SEQUENTIAL_COMMENTS = false;
+
+  @Nullable
+  @Override
+  public PythonFoldingSettings getState() {
+    return this;
+  }
+
+  @NotNull
+  public static PythonFoldingSettings getInstance() {
+    return ServiceManager.getService(PythonFoldingSettings.class);
+  }
+
+  @Override
+  public void loadState(PythonFoldingSettings state) {
+    XmlSerializerUtil.copyBean(state, this);
+  }
+
+  public boolean isCollapseLongStrings() {
+    return COLLAPSE_LONG_STRINGS;
+  }
+
+  public boolean isCollapseLongCollections() {
+    return COLLAPSE_LONG_COLLECTIONS;
+  }
+
+  public boolean isCollapseSequentialComments() {
+    return COLLAPSE_SEQUENTIAL_COMMENTS;
+  }
+
+}