Skip to content

Commit

Permalink
Add hide fields toolbar button to outline view (fix #1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
travkin79 committed Aug 29, 2024
1 parent 538aed3 commit ff90685
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 1 deletion.
Binary file added org.eclipse.lsp4e/icons/full/dlcl16/fields_co.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/elcl16/fields_co.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions org.eclipse.lsp4e/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ command.toggle.highlight.label = Toggle Mark Occurrences
command.toggle.highlight.name = Toggle Highlight
command.toggle.outline.sort.name = Sort
command.toggle.outline.sort.label = Sort
command.toggle.outline.hideFields.name = Hide Fields
command.toggle.outline.hideFields.label = Hide Fields
command.open.call.hierarchy.name = Open Call Hierarchy
command.open.call.hierarchy.description = Open Call Hierarchy for the selected item
command.open.type.hierarchy.name = Open Type Hierarchy
Expand Down
40 changes: 39 additions & 1 deletion org.eclipse.lsp4e/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@
class="org.eclipse.ui.handlers.RegistryToggleState:false"
id="org.eclipse.ui.commands.toggleState" />
</command>
<command
categoryId="org.eclipse.lsp4e.category"
id="org.eclipse.lsp4e.toggleHideFieldsOutline"
name="%command.toggle.outline.hideFields.name">
<state
class="org.eclipse.ui.handlers.RegistryToggleState:false"
id="org.eclipse.ui.commands.toggleState">
</state>
</command>
<command
categoryId="org.eclipse.lsp4e.category"
description="%command.open.call.hierarchy.description"
Expand Down Expand Up @@ -176,6 +185,12 @@
<handler commandId="org.eclipse.lsp4e.toggleSortOutline">
<class class="org.eclipse.lsp4e.outline.ToggleSortOutlineHandler" />
</handler>
<handler
commandId="org.eclipse.lsp4e.toggleHideFieldsOutline">
<class
class="org.eclipse.lsp4e.outline.ToggleHideFieldsOutlineHandler">
</class>
</handler>
<handler
class="org.eclipse.lsp4e.callhierarchy.CallHierarchyCommandHandler"
commandId="org.eclipse.lsp4e.openCallHierarchy">
Expand Down Expand Up @@ -336,12 +351,30 @@
</menu>
</menuContribution>
<menuContribution allPopups="false" locationURI="toolbar:org.eclipse.ui.views.ContentOutline?after=additions">
<command commandId="org.eclipse.lsp4e.toggleSortOutline" style="toggle" label="%command.toggle.outline.sort.label">
<command
commandId="org.eclipse.lsp4e.toggleSortOutline"
id="org.eclipse.lsp4e.outline.toolbar.sort"
label="%command.toggle.outline.sort.label"
style="toggle">
<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.sort">
<command
commandId="org.eclipse.lsp4e.toggleHideFieldsOutline"
label="%command.toggle.outline.hideFields.label"
style="toggle">
<visibleWhen>
<reference
definitionId="org.eclipse.lsp4e.activePartHasCNFOutlinePage">
</reference>
</visibleWhen>
</command>
</menuContribution>
<menuContribution
locationURI="popup:#TextEditorContext?before=org.eclipse.ui.genericeditor.findReferences">
<command
Expand Down Expand Up @@ -599,6 +632,11 @@
disabledIcon="icons/full/dlcl16/link_to_editor.png"
icon="icons/full/elcl16/link_to_editor.png">
</image>
<image
commandId="org.eclipse.lsp4e.toggleHideFieldsOutline"
disabledIcon="icons/full/dlcl16/fields_co.png"
icon="icons/full/elcl16/fields_co.png">
</image>
<image
commandId="org.eclipse.lsp4e.toggleSortOutline"
disabledIcon="icons/full/dlcl16/alphab_sort_co.png"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2024 Advantest Europe GmbH. All rights reserved.
* 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:
* Dietrich Travkin (Solunar GmbH) - initial implementation (issue #1073)
*******************************************************************************/
package org.eclipse.lsp4e.outline;

import java.util.Optional;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.lsp4e.LanguageServerPlugin;
import org.eclipse.lsp4j.SymbolKind;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.HandlerUtil;

public class ToggleHideFieldsOutlineHandler extends AbstractHandler implements IPreferenceChangeListener {

private static final String COMMAND_ID_HIDE_FIELDS = "org.eclipse.lsp4e.toggleHideFieldsOutline"; //$NON-NLS-1$

private final IEclipsePreferences preferences;
private final Optional<Command> toggleHideFieldsCommand;

public ToggleHideFieldsOutlineHandler() {
preferences = InstanceScope.INSTANCE.getNode(LanguageServerPlugin.PLUGIN_ID);
preferences.addPreferenceChangeListener(this);

ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
if (commandService != null) {
toggleHideFieldsCommand = Optional.of(commandService.getCommand(COMMAND_ID_HIDE_FIELDS));
} else {
toggleHideFieldsCommand = Optional.empty();
}
}

@Override
public @Nullable Object execute(final ExecutionEvent event) throws ExecutionException {
OutlineViewHideSymbolKindMenuContributor.toggleHideSymbolKind(SymbolKind.Field);
return null;
}

@Override
public void dispose() {
super.dispose();
preferences.removePreferenceChangeListener(this);
}

@Override
public void preferenceChange(PreferenceChangeEvent event) {
if (toggleHideFieldsCommand.isPresent()
&& event.getKey().startsWith(CNFOutlinePage.HIDE_DOCUMENT_SYMBOL_KIND_PREFERENCE_PREFIX)
&& event.getKey().endsWith(SymbolKind.Field.name())) {
try {
HandlerUtil.toggleCommandState(toggleHideFieldsCommand.get());
} catch (ExecutionException e) {
LanguageServerPlugin.logError(e);
}
}
}
}

0 comments on commit ff90685

Please sign in to comment.