mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-74010 outliner-like code folding improvements
This commit is contained in:
@@ -102,7 +102,7 @@
|
||||
text="Recursive"
|
||||
description="Toggle whether to show the images from subfolders recursively"
|
||||
icon="AllIcons.ObjectBrowser.FlattenPackages">
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" keymap="$default"/>
|
||||
<keyboard-shortcut first-keystroke="alt MULTIPLY" keymap="$default"/>
|
||||
</action>
|
||||
<separator/>
|
||||
<reference id="Images.ToggleTransparencyChessboard"/>
|
||||
|
||||
@@ -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<FoldRegion> 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<FoldRegion>() {
|
||||
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];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+99
@@ -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<FoldRegion> regionTreeIterator = FoldingUtil.createFoldTreeIterator(editor);
|
||||
Deque<FoldRegion> currentStack = new LinkedList<FoldRegion>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
+36
-1
@@ -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<FoldRegion> getFoldRegionsForSelection(@NotNull Editor editor, @Nullable Caret caret) {
|
||||
FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions();
|
||||
if (caret == null) {
|
||||
caret = editor.getCaretModel().getPrimaryCaret();
|
||||
}
|
||||
if (caret.hasSelection()) {
|
||||
List<FoldRegion> result = new ArrayList<FoldRegion>(allRegions.length);
|
||||
List<FoldRegion> result = new ArrayList<FoldRegion>();
|
||||
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<FoldRegion> 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<FoldRegion> result = new ArrayList<FoldRegion>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+50
@@ -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<FoldRegion> regions = getFoldRegionsForCaret(editor, caret, true);
|
||||
editor.getFoldingModel().runBatchFoldingOperation(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (FoldRegion region : regions) {
|
||||
region.setExpanded(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -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);
|
||||
}
|
||||
}
|
||||
+22
@@ -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);
|
||||
}
|
||||
}
|
||||
+22
@@ -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);
|
||||
}
|
||||
}
|
||||
+22
@@ -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);
|
||||
}
|
||||
}
|
||||
+22
@@ -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);
|
||||
}
|
||||
}
|
||||
+49
@@ -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<FoldRegion> regions = getFoldRegionsForCaret(editor, caret, false);
|
||||
editor.getFoldingModel().runBatchFoldingOperation(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (FoldRegion region : regions) {
|
||||
region.setExpanded(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+22
@@ -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);
|
||||
}
|
||||
}
|
||||
+22
@@ -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);
|
||||
}
|
||||
}
|
||||
+22
@@ -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);
|
||||
}
|
||||
}
|
||||
+22
@@ -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);
|
||||
}
|
||||
}
|
||||
+22
@@ -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);
|
||||
}
|
||||
}
|
||||
+46
@@ -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<FoldRegion> 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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -325,6 +325,50 @@
|
||||
<keyboard-shortcut first-keystroke="control ADD"/>
|
||||
<keyboard-shortcut first-keystroke="control EQUALS"/>
|
||||
</action>
|
||||
<action id="ExpandRegionRecursively">
|
||||
<keyboard-shortcut first-keystroke="control alt ADD"/>
|
||||
<keyboard-shortcut first-keystroke="control alt EQUALS"/>
|
||||
</action>
|
||||
<action id="ExpandToLevel1">
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" second-keystroke="1"/>
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" second-keystroke="NUMPAD1"/>
|
||||
</action>
|
||||
<action id="ExpandToLevel2">
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" second-keystroke="2"/>
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" second-keystroke="NUMPAD2"/>
|
||||
</action>
|
||||
<action id="ExpandToLevel3">
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" second-keystroke="3"/>
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" second-keystroke="NUMPAD3"/>
|
||||
</action>
|
||||
<action id="ExpandToLevel4">
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" second-keystroke="4"/>
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" second-keystroke="NUMPAD4"/>
|
||||
</action>
|
||||
<action id="ExpandToLevel5">
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" second-keystroke="5"/>
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" second-keystroke="NUMPAD5"/>
|
||||
</action>
|
||||
<action id="ExpandAllToLevel1">
|
||||
<keyboard-shortcut first-keystroke="control shift MULTIPLY" second-keystroke="1"/>
|
||||
<keyboard-shortcut first-keystroke="control shift MULTIPLY" second-keystroke="NUMPAD1"/>
|
||||
</action>
|
||||
<action id="ExpandAllToLevel2">
|
||||
<keyboard-shortcut first-keystroke="control shift MULTIPLY" second-keystroke="2"/>
|
||||
<keyboard-shortcut first-keystroke="control shift MULTIPLY" second-keystroke="NUMPAD2"/>
|
||||
</action>
|
||||
<action id="ExpandAllToLevel3">
|
||||
<keyboard-shortcut first-keystroke="control shift MULTIPLY" second-keystroke="3"/>
|
||||
<keyboard-shortcut first-keystroke="control shift MULTIPLY" second-keystroke="NUMPAD3"/>
|
||||
</action>
|
||||
<action id="ExpandAllToLevel4">
|
||||
<keyboard-shortcut first-keystroke="control shift MULTIPLY" second-keystroke="4"/>
|
||||
<keyboard-shortcut first-keystroke="control shift MULTIPLY" second-keystroke="NUMPAD4"/>
|
||||
</action>
|
||||
<action id="ExpandAllToLevel5">
|
||||
<keyboard-shortcut first-keystroke="control shift MULTIPLY" second-keystroke="5"/>
|
||||
<keyboard-shortcut first-keystroke="control shift MULTIPLY" second-keystroke="NUMPAD5"/>
|
||||
</action>
|
||||
<action id="EditorLeftWithSelection">
|
||||
<keyboard-shortcut first-keystroke="shift LEFT"/>
|
||||
</action>
|
||||
@@ -391,6 +435,10 @@
|
||||
<keyboard-shortcut first-keystroke="control SUBTRACT"/>
|
||||
<keyboard-shortcut first-keystroke="control MINUS"/>
|
||||
</action>
|
||||
<action id="CollapseRegionRecursively">
|
||||
<keyboard-shortcut first-keystroke="control alt SUBTRACT"/>
|
||||
<keyboard-shortcut first-keystroke="control alt MINUS"/>
|
||||
</action>
|
||||
<action id="PreviousOccurence">
|
||||
<keyboard-shortcut first-keystroke="control alt UP"/>
|
||||
</action>
|
||||
|
||||
@@ -101,6 +101,16 @@
|
||||
<action id="ExpandAllRegions">
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY" />
|
||||
</action>
|
||||
<action id="ExpandAllToLevel1"/>
|
||||
<action id="ExpandAllToLevel2"/>
|
||||
<action id="ExpandAllToLevel3"/>
|
||||
<action id="ExpandAllToLevel4"/>
|
||||
<action id="ExpandAllToLevel5"/>
|
||||
<action id="ExpandToLevel1"/>
|
||||
<action id="ExpandToLevel2"/>
|
||||
<action id="ExpandToLevel3"/>
|
||||
<action id="ExpandToLevel4"/>
|
||||
<action id="ExpandToLevel5"/>
|
||||
<action id="ExternalJavaDoc">
|
||||
<keyboard-shortcut first-keystroke="shift F2" />
|
||||
</action>
|
||||
|
||||
@@ -60,9 +60,11 @@
|
||||
<action id="CollapseSelection" />
|
||||
<action id="CommentByLineComment">
|
||||
<keyboard-shortcut first-keystroke="control SLASH" />
|
||||
<keyboard-shortcut first-keystroke="control DIVIDE" />
|
||||
<keyboard-shortcut first-keystroke="shift control C" />
|
||||
</action>
|
||||
<action id="CollapseRegionRecursively">
|
||||
<keyboard-shortcut first-keystroke="control DIVIDE"/>
|
||||
</action>
|
||||
<action id="Compile">
|
||||
<keyboard-shortcut first-keystroke="F9" />
|
||||
</action>
|
||||
@@ -128,6 +130,19 @@
|
||||
<action id="EvaluateExpression">
|
||||
<keyboard-shortcut first-keystroke="control F9" />
|
||||
</action>
|
||||
<action id="ExpandAllToLevel1"/>
|
||||
<action id="ExpandAllToLevel2"/>
|
||||
<action id="ExpandAllToLevel3"/>
|
||||
<action id="ExpandAllToLevel4"/>
|
||||
<action id="ExpandAllToLevel5"/>
|
||||
<action id="ExpandRegionRecursively">
|
||||
<keyboard-shortcut first-keystroke="control MULTIPLY"/>
|
||||
</action>
|
||||
<action id="ExpandToLevel1"/>
|
||||
<action id="ExpandToLevel2"/>
|
||||
<action id="ExpandToLevel3"/>
|
||||
<action id="ExpandToLevel4"/>
|
||||
<action id="ExpandToLevel5"/>
|
||||
<action id="ExtractMethod">
|
||||
<keyboard-shortcut first-keystroke="shift alt M" />
|
||||
</action>
|
||||
|
||||
@@ -221,9 +221,27 @@
|
||||
<action id="ExpandRegion" class="com.intellij.codeInsight.folding.impl.actions.ExpandRegionAction"/>
|
||||
<action id="CollapseRegion" class="com.intellij.codeInsight.folding.impl.actions.CollapseRegionAction"/>
|
||||
<separator/>
|
||||
<action id="ExpandRegionRecursively" class="com.intellij.codeInsight.folding.impl.actions.ExpandRegionRecursivelyAction"/>
|
||||
<action id="CollapseRegionRecursively" class="com.intellij.codeInsight.folding.impl.actions.CollapseRegionRecursivelyAction"/>
|
||||
<separator/>
|
||||
<action id="ExpandAllRegions" class="com.intellij.codeInsight.folding.impl.actions.ExpandAllRegionsAction"/>
|
||||
<action id="CollapseAllRegions" class="com.intellij.codeInsight.folding.impl.actions.CollapseAllRegionsAction"/>
|
||||
<separator/>
|
||||
<group id="ExpandToLevel" popup="true">
|
||||
<action id="ExpandToLevel1" class="com.intellij.codeInsight.folding.impl.actions.ExpandToLevel1Action"/>
|
||||
<action id="ExpandToLevel2" class="com.intellij.codeInsight.folding.impl.actions.ExpandToLevel2Action"/>
|
||||
<action id="ExpandToLevel3" class="com.intellij.codeInsight.folding.impl.actions.ExpandToLevel3Action"/>
|
||||
<action id="ExpandToLevel4" class="com.intellij.codeInsight.folding.impl.actions.ExpandToLevel4Action"/>
|
||||
<action id="ExpandToLevel5" class="com.intellij.codeInsight.folding.impl.actions.ExpandToLevel5Action"/>
|
||||
</group>
|
||||
<group id="ExpandAllToLevel" popup="true">
|
||||
<action id="ExpandAllToLevel1" class="com.intellij.codeInsight.folding.impl.actions.ExpandAllToLevel1Action"/>
|
||||
<action id="ExpandAllToLevel2" class="com.intellij.codeInsight.folding.impl.actions.ExpandAllToLevel2Action"/>
|
||||
<action id="ExpandAllToLevel3" class="com.intellij.codeInsight.folding.impl.actions.ExpandAllToLevel3Action"/>
|
||||
<action id="ExpandAllToLevel4" class="com.intellij.codeInsight.folding.impl.actions.ExpandAllToLevel4Action"/>
|
||||
<action id="ExpandAllToLevel5" class="com.intellij.codeInsight.folding.impl.actions.ExpandAllToLevel5Action"/>
|
||||
</group>
|
||||
<separator/>
|
||||
<group id="LanguageSpecificFoldingGroup">
|
||||
<action id="ExpandDocComments" class="com.intellij.codeInsight.folding.impl.actions.ExpandDocCommentsAction"/>
|
||||
<action id="CollapseDocComments" class="com.intellij.codeInsight.folding.impl.actions.CollapseDocCommentsAction"/>
|
||||
|
||||
Reference in New Issue
Block a user