Skip to content

Commit

Permalink
feat: add "Collaps All" button to ouline view
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Jan 14, 2025
1 parent 9cdd1e1 commit 871d73a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions org.eclipse.lsp4e/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ notification.category.label = LSP
notification.event.label = LSP Notification
command.toggle.highlight.label = Toggle Mark Occurrences
command.toggle.highlight.name = Toggle Highlight
command.toggle.outline.collapseAll.name = Collapse All
command.toggle.outline.collapseAll.label = Collapse All
command.toggle.outline.sort.name = Sort
command.toggle.outline.sort.label = Sort
command.toggle.outline.hideFields.name = Hide Fields
Expand Down
24 changes: 24 additions & 0 deletions org.eclipse.lsp4e/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@

<!-- outline: define commands -->
<extension point="org.eclipse.ui.commands">
<command
categoryId="org.eclipse.lsp4e.category"
id="org.eclipse.lsp4e.collapseAllOutline"
name="%command.toggle.outline.collapseAll.name" />
<command
categoryId="org.eclipse.lsp4e.category"
id="org.eclipse.lsp4e.toggleSortOutline"
Expand Down Expand Up @@ -770,6 +774,9 @@

<!-- outline: register command handlers -->
<extension point="org.eclipse.ui.handlers">
<handler commandId="org.eclipse.lsp4e.collapseAllOutline">
<class class="org.eclipse.lsp4e.outline.CollapseAllOutlineHandler" />
</handler>
<handler commandId="org.eclipse.lsp4e.toggleSortOutline">
<class class="org.eclipse.lsp4e.outline.ToggleSortOutlineHandler" />
</handler>
Expand All @@ -786,6 +793,10 @@

<!-- outline: command images -->
<extension point="org.eclipse.ui.commandImages">
<image
commandId="org.eclipse.lsp4e.collapseAllOutline"
disabledIcon="platform:/plugin/org.eclipse.jdt.ui/icons/full/dlcl16/collapseall.png"
icon="platform:/plugin/org.eclipse.jdt.ui/icons/full/elcl16/collapseall.png" />
<image
commandId="org.eclipse.lsp4e.toggleSortOutline"
disabledIcon="icons/full/dlcl16/alphab_sort_co.png"
Expand All @@ -805,6 +816,19 @@
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.views.ContentOutline?after=additions">
<command
commandId="org.eclipse.lsp4e.collapseAllOutline"
id="org.eclipse.lsp4e.outline.toolbar.collapseAll"
label="%command.toggle.outline.collapseAll.label"
style="push">
<visibleWhen>
<reference definitionId="org.eclipse.lsp4e.activeEditorHasCNFOutlinePage" />
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.views.ContentOutline?after=org.eclipse.lsp4e.outline.toolbar.collapseAll">
<command
commandId="org.eclipse.lsp4e.toggleSortOutline"
id="org.eclipse.lsp4e.outline.toolbar.sort"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ private static boolean isOffsetInRange(int offset, Range range, IDocument docume
}
}

public void collapseTree() {
outlineViewer.collapseAll();
}

@Override
public void dispose() {
preferences.removePreferenceChangeListener(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2025 Vegard IT GmbH and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Sebastian Thomschke (Vegard IT GmbH) - initial implementation.
*******************************************************************************/
package org.eclipse.lsp4e.outline;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.lsp4e.ui.UI;
import org.eclipse.ui.views.contentoutline.ContentOutline;

public class CollapseAllOutlineHandler extends AbstractHandler {

@Override
public @Nullable Object execute(ExecutionEvent event) {
final var workbenchPage = UI.getActivePage();
if (workbenchPage != null //
&& workbenchPage.getActivePart() instanceof ContentOutline outline
&& outline.getCurrentPage() instanceof CNFOutlinePage page) {
page.collapseTree();
}
return null;
}
}

0 comments on commit 871d73a

Please sign in to comment.