diff --git a/images/src/META-INF/ImagesPlugin.xml b/images/src/META-INF/ImagesPlugin.xml index ef623446c56a..78da74881f62 100644 --- a/images/src/META-INF/ImagesPlugin.xml +++ b/images/src/META-INF/ImagesPlugin.xml @@ -102,7 +102,7 @@ text="Recursive" description="Toggle whether to show the images from subfolders recursively" icon="AllIcons.ObjectBrowser.FlattenPackages"> - + diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUtil.java index a3acb0d6c768..c84781ab36c3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -23,10 +23,7 @@ import com.intellij.openapi.util.TextRange; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; public class FoldingUtil { private FoldingUtil() {} @@ -82,4 +79,48 @@ public class FoldingUtil { final int offset = editor.getCaretModel().getOffset(); return range.contains(offset) && range.getStartOffset() != offset; } + + /** + * Iterates fold regions tree in a depth-first order (pre-order) + */ + public static Iterator createFoldTreeIterator(@NotNull Editor editor) { + final FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions(); + Arrays.sort(allRegions, RangeMarker.BY_START_OFFSET); // It's already sorted in this way in current implementation, but we don't want to depend on that here + return new Iterator() { + private int sectionStart; + private int current; + private int sectionEnd; + + { + advanceSection(); + } + + private void advanceSection() { + sectionStart = sectionEnd; + //noinspection StatementWithEmptyBody + for (sectionEnd = sectionStart + 1; + sectionEnd < allRegions.length && allRegions[sectionEnd].getStartOffset() == allRegions[sectionStart].getStartOffset(); + sectionEnd++); + current = sectionEnd; + } + + @Override + public boolean hasNext() { + return current > sectionStart || sectionEnd < allRegions.length; + } + + @Override + public FoldRegion next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + if (current <= sectionStart) { + advanceSection(); + } + return allRegions[--current]; + } + }; + } + + } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/BaseExpandToLevelAction.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/BaseExpandToLevelAction.java new file mode 100644 index 000000000000..67a503dd5851 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/BaseExpandToLevelAction.java @@ -0,0 +1,99 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +import com.intellij.codeInsight.folding.CodeFoldingManager; +import com.intellij.codeInsight.folding.impl.FoldingUtil; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.editor.Caret; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.FoldRegion; +import com.intellij.openapi.editor.actionSystem.EditorAction; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Deque; +import java.util.Iterator; +import java.util.LinkedList; + +public abstract class BaseExpandToLevelAction extends EditorAction { + protected BaseExpandToLevelAction(final int level, final boolean expandAll) { + super(new BaseFoldingHandler() { + @Override + protected void doExecute(final Editor editor, @Nullable Caret caret, DataContext dataContext) { + assert editor.getProject() != null; + CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(editor.getProject()); + foldingManager.updateFoldRegions(editor); + + if (caret == null) { + caret = editor.getCaretModel().getPrimaryCaret(); + } + int offset = caret.getOffset(); + FoldRegion rootRegion = null; + if (!expandAll) { + rootRegion = FoldingUtil.findFoldRegionStartingAtLine(editor, editor.getDocument().getLineNumber(offset)); + if (rootRegion == null) { + FoldRegion[] regions = FoldingUtil.getFoldRegionsAtOffset(editor, offset); + if (regions.length > 0) { + rootRegion = regions[0]; + } + } + if (rootRegion == null) { + return; + } + } + final FoldRegion root = rootRegion; + final int[] rootLevel = new int[] {root == null ? 1 : -1}; + + editor.getFoldingModel().runBatchFoldingOperation(new Runnable() { + @Override + public void run() { + Iterator regionTreeIterator = FoldingUtil.createFoldTreeIterator(editor); + Deque currentStack = new LinkedList(); + while (regionTreeIterator.hasNext()) { + FoldRegion region = regionTreeIterator.next(); + while (!currentStack.isEmpty() && !isChild(currentStack.peek(), region)) { + if (currentStack.remove() == root) { + rootLevel[0] = -1; + } + } + currentStack.push(region); + int currentLevel = currentStack.size(); + + if (region == root) { + rootLevel[0] = currentLevel; + } + if (rootLevel[0] >= 0) { + int relativeLevel = currentLevel - rootLevel[0]; + + if (relativeLevel < level) { + region.setExpanded(true); + } + else if (relativeLevel == level) { + region.setExpanded(false); + } + } + } + } + }); + } + }); + } + + private static boolean isChild(@NotNull FoldRegion parent, @NotNull FoldRegion child) { + return child.getStartOffset() >= parent.getStartOffset() && child.getEndOffset() <= parent.getEndOffset(); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/BaseFoldingHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/BaseFoldingHandler.java index 2f26021e1a72..8da22a780db4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/BaseFoldingHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/BaseFoldingHandler.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInsight.folding.impl.actions; +import com.intellij.codeInsight.folding.impl.FoldingUtil; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; @@ -33,13 +34,16 @@ public abstract class BaseFoldingHandler extends EditorActionHandler { return editor.getProject() != null; } + /** + * Returns fold regions inside selection, or all regions in editor, if selection doesn't exist or doesn't contain fold regions. + */ protected List getFoldRegionsForSelection(@NotNull Editor editor, @Nullable Caret caret) { FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions(); if (caret == null) { caret = editor.getCaretModel().getPrimaryCaret(); } if (caret.hasSelection()) { - List result = new ArrayList(allRegions.length); + List result = new ArrayList(); for (FoldRegion region : allRegions) { if (region.getStartOffset() >= caret.getSelectionStart() && region.getEndOffset() <= caret.getSelectionEnd()) { result.add(region); @@ -51,4 +55,35 @@ public abstract class BaseFoldingHandler extends EditorActionHandler { } return Arrays.asList(allRegions); } + + /** + * Returns a region corresponding to current caret position, and all regions contained in it. + */ + protected List getFoldRegionsForCaret(@NotNull Editor editor, @Nullable Caret caret, boolean toCollapse) { + if (caret == null) { + caret = editor.getCaretModel().getPrimaryCaret(); + } + int offset = caret.getOffset(); + FoldRegion rootRegion = FoldingUtil.findFoldRegionStartingAtLine(editor, editor.getDocument().getLineNumber(offset)); + if (rootRegion == null || rootRegion.isExpanded() != toCollapse) { + rootRegion = null; + FoldRegion[] regions = FoldingUtil.getFoldRegionsAtOffset(editor, offset); + for (FoldRegion region : regions) { + if (region.isExpanded() == toCollapse) { + rootRegion = region; + break; + } + } + } + List result = new ArrayList(); + if (rootRegion != null) { + FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions(); + for (FoldRegion region : allRegions) { + if (region.getStartOffset() >= rootRegion.getStartOffset() && region.getEndOffset() <= rootRegion.getEndOffset()) { + result.add(region); + } + } + } + return result; + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseRegionRecursivelyAction.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseRegionRecursivelyAction.java new file mode 100644 index 000000000000..56ec6ece89de --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/CollapseRegionRecursivelyAction.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +import com.intellij.codeInsight.folding.CodeFoldingManager; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.editor.Caret; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.FoldRegion; +import com.intellij.openapi.editor.actionSystem.EditorAction; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class CollapseRegionRecursivelyAction extends EditorAction { + public CollapseRegionRecursivelyAction() { + super(new BaseFoldingHandler() { + @Override + public void doExecute(final Editor editor, @Nullable Caret caret, DataContext dataContext) { + assert editor.getProject() != null; + CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(editor.getProject()); + foldingManager.updateFoldRegions(editor); + + final List regions = getFoldRegionsForCaret(editor, caret, true); + editor.getFoldingModel().runBatchFoldingOperation(new Runnable() { + @Override + public void run() { + for (FoldRegion region : regions) { + region.setExpanded(false); + } + } + }); + } + }); + } +} + diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel1Action.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel1Action.java new file mode 100644 index 000000000000..294f2a17a1ef --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel1Action.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +public class ExpandAllToLevel1Action extends BaseExpandToLevelAction { + public ExpandAllToLevel1Action() { + super(1, true); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel2Action.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel2Action.java new file mode 100644 index 000000000000..26dbd5dca1dd --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel2Action.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +public class ExpandAllToLevel2Action extends BaseExpandToLevelAction { + public ExpandAllToLevel2Action() { + super(2, true); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel3Action.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel3Action.java new file mode 100644 index 000000000000..dc5644a2e01e --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel3Action.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +public class ExpandAllToLevel3Action extends BaseExpandToLevelAction { + public ExpandAllToLevel3Action() { + super(3, true); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel4Action.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel4Action.java new file mode 100644 index 000000000000..29a73acc86b4 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel4Action.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +public class ExpandAllToLevel4Action extends BaseExpandToLevelAction { + public ExpandAllToLevel4Action() { + super(4, true); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel5Action.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel5Action.java new file mode 100644 index 000000000000..740aa925ec6e --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandAllToLevel5Action.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +public class ExpandAllToLevel5Action extends BaseExpandToLevelAction { + public ExpandAllToLevel5Action() { + super(5, true); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandRegionRecursivelyAction.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandRegionRecursivelyAction.java new file mode 100644 index 000000000000..9d87d2775a64 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandRegionRecursivelyAction.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +import com.intellij.codeInsight.folding.CodeFoldingManager; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.editor.Caret; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.FoldRegion; +import com.intellij.openapi.editor.actionSystem.EditorAction; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class ExpandRegionRecursivelyAction extends EditorAction { + public ExpandRegionRecursivelyAction() { + super(new BaseFoldingHandler() { + @Override + public void doExecute(final Editor editor, @Nullable Caret caret, DataContext dataContext) { + assert editor.getProject() != null; + CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(editor.getProject()); + foldingManager.updateFoldRegions(editor); + + final List regions = getFoldRegionsForCaret(editor, caret, false); + editor.getFoldingModel().runBatchFoldingOperation(new Runnable() { + @Override + public void run() { + for (FoldRegion region : regions) { + region.setExpanded(true); + } + } + }); + } + }); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel1Action.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel1Action.java new file mode 100644 index 000000000000..f2927fe50fbb --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel1Action.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +public class ExpandToLevel1Action extends BaseExpandToLevelAction { + public ExpandToLevel1Action() { + super(1, false); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel2Action.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel2Action.java new file mode 100644 index 000000000000..4b7e45c2d496 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel2Action.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +public class ExpandToLevel2Action extends BaseExpandToLevelAction { + public ExpandToLevel2Action() { + super(2, false); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel3Action.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel3Action.java new file mode 100644 index 000000000000..4abde8cf121f --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel3Action.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +public class ExpandToLevel3Action extends BaseExpandToLevelAction { + public ExpandToLevel3Action() { + super(3, false); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel4Action.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel4Action.java new file mode 100644 index 000000000000..41519aabe0f2 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel4Action.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +public class ExpandToLevel4Action extends BaseExpandToLevelAction { + public ExpandToLevel4Action() { + super(4, false); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel5Action.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel5Action.java new file mode 100644 index 000000000000..86f2b721f96b --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandToLevel5Action.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2014 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.folding.impl.actions; + +public class ExpandToLevel5Action extends BaseExpandToLevelAction { + public ExpandToLevel5Action() { + super(5, false); + } +} diff --git a/platform/lang-impl/testSources/com/intellij/codeInsight/folding/impl/FoldingUtilTest.java b/platform/lang-impl/testSources/com/intellij/codeInsight/folding/impl/FoldingUtilTest.java new file mode 100644 index 000000000000..94c413a94d10 --- /dev/null +++ b/platform/lang-impl/testSources/com/intellij/codeInsight/folding/impl/FoldingUtilTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2014 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.folding.impl; + +import com.intellij.openapi.editor.FoldRegion; +import com.intellij.testFramework.EditorTestUtil; +import com.intellij.testFramework.LightPlatformCodeInsightTestCase; + +import java.util.Iterator; + +public class FoldingUtilTest extends LightPlatformCodeInsightTestCase { + public void testFoldTreeIterator() { + configureFromFileText(getTestName(false) + ".txt", + "abcdefghijklmnopqrstuvwxyz"); + EditorTestUtil.addFoldRegion(myEditor, 0, 10, ".", true); + EditorTestUtil.addFoldRegion(myEditor, 0, 5, ".", false); + EditorTestUtil.addFoldRegion(myEditor, 1, 2, ".", true); + EditorTestUtil.addFoldRegion(myEditor, 7, 10, ".", false); + EditorTestUtil.addFoldRegion(myEditor, 10, 11, ".", true); + + StringBuilder b = new StringBuilder(); + Iterator it = FoldingUtil.createFoldTreeIterator(myEditor); + while (it.hasNext()) { + FoldRegion region = it.next(); + if (b.length() > 0) { + b.append('|'); + } + b.append(region.getStartOffset()).append(',').append(region.getEndOffset()); + } + + assertEquals("0,10|0,5|1,2|7,10|10,11", b.toString()); + } +} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index 154fb71fdefb..0770c310c5c7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -5656,7 +5656,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi public void run() { myFoldingModel.flushCaretShift(); range.setExpanded(expansion); - if (e.isShiftDown()) { + if (e.isAltDown()) { for (FoldRegion region : myFoldingModel.getAllFoldRegions()) { if (region.getStartOffset() >= range.getStartOffset() && region.getEndOffset() <= range.getEndOffset()) { region.setExpanded(expansion); diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index 0987f05de9d8..196ad7263213 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -405,10 +405,26 @@ action.MethodHierarchy.description=Browse method hierarchy for the selected meth action.CallHierarchy.text=Call Hierarch_y action.CallHierarchy.description=Browse call hierarchy for the selected method group.FoldingGroup.text=Folding +group.ExpandToLevel.text=Expand to l_evel +action.ExpandToLevel1.text=_1 +action.ExpandToLevel2.text=_2 +action.ExpandToLevel3.text=_3 +action.ExpandToLevel4.text=_4 +action.ExpandToLevel5.text=_5 +group.ExpandAllToLevel.text=Expand all to _level +action.ExpandAllToLevel1.text=_1 +action.ExpandAllToLevel2.text=_2 +action.ExpandAllToLevel3.text=_3 +action.ExpandAllToLevel4.text=_4 +action.ExpandAllToLevel5.text=_5 action.ExpandRegion.text=E_xpand action.ExpandRegion.description=Expand folding region at caret +action.ExpandRegionRecursively.text=Expand _Recursively +action.ExpandRegionRecursively.description=Expand block at caret recursively action.CollapseRegion.text=_Collapse action.CollapseRegion.description=Collapse folding region at caret +action.CollapseRegionRecursively.text=Coll_apse Recursively +action.CollapseRegionRecursively.description=Collapse block at caret recursively action.ExpandAllRegions.text=_Expand All action.ExpandAllRegions.description=Expand all folding regions (in selection) action.CollapseAllRegions.text=Collapse _All diff --git a/platform/platform-resources/src/idea/Keymap_Default.xml b/platform/platform-resources/src/idea/Keymap_Default.xml index 37f7ce4293ed..2c1c6abe70fa 100644 --- a/platform/platform-resources/src/idea/Keymap_Default.xml +++ b/platform/platform-resources/src/idea/Keymap_Default.xml @@ -325,6 +325,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -391,6 +435,10 @@ + + + + diff --git a/platform/platform-resources/src/idea/Keymap_Eclipse.xml b/platform/platform-resources/src/idea/Keymap_Eclipse.xml index ecc3b0488e6b..59719444faed 100644 --- a/platform/platform-resources/src/idea/Keymap_Eclipse.xml +++ b/platform/platform-resources/src/idea/Keymap_Eclipse.xml @@ -101,6 +101,16 @@ + + + + + + + + + + diff --git a/platform/platform-resources/src/idea/Keymap_Netbeans.xml b/platform/platform-resources/src/idea/Keymap_Netbeans.xml index b38699989ca3..99c55b40fd8c 100644 --- a/platform/platform-resources/src/idea/Keymap_Netbeans.xml +++ b/platform/platform-resources/src/idea/Keymap_Netbeans.xml @@ -60,9 +60,11 @@ - + + + @@ -128,6 +130,19 @@ + + + + + + + + + + + + + diff --git a/platform/platform-resources/src/idea/LangActions.xml b/platform/platform-resources/src/idea/LangActions.xml index fe3855c35475..54c76d61bf1a 100644 --- a/platform/platform-resources/src/idea/LangActions.xml +++ b/platform/platform-resources/src/idea/LangActions.xml @@ -221,9 +221,27 @@ + + + + + + + + + + + + + + + + + +