forked from eclipse-lsp4e/lsp4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eclipse-lsp4e#254] Initial implementation of outline filters
- Loading branch information
Showing
4 changed files
with
162 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/OutlineViewFilterMenuContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/******************************************************************************* | ||
* 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 | ||
*******************************************************************************/ | ||
package org.eclipse.lsp4e.outline; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.eclipse.core.runtime.preferences.IEclipsePreferences; | ||
import org.eclipse.core.runtime.preferences.InstanceScope; | ||
import org.eclipse.jface.action.Action; | ||
import org.eclipse.jface.action.ActionContributionItem; | ||
import org.eclipse.jface.action.IAction; | ||
import org.eclipse.jface.action.IContributionItem; | ||
import org.eclipse.lsp4e.LanguageServerPlugin; | ||
import org.eclipse.lsp4j.SymbolKind; | ||
import org.eclipse.ui.actions.CompoundContributionItem; | ||
|
||
public class OutlineViewFilterMenuContributor extends CompoundContributionItem { | ||
|
||
@Override | ||
protected IContributionItem[] getContributionItems() { | ||
return Arrays.stream(SymbolKind.values()) | ||
.map(kind -> createHideSymbolKindContributionItem(kind)) | ||
.toArray(IContributionItem[]::new); | ||
} | ||
|
||
private IContributionItem createHideSymbolKindContributionItem(SymbolKind kind) { | ||
return new ActionContributionItem(new HideSymbolKindAction(kind)); | ||
} | ||
|
||
static boolean isHideSymbolKind(SymbolKind kind) { | ||
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(LanguageServerPlugin.PLUGIN_ID); | ||
return preferences.getBoolean(CNFOutlinePage.HIDE_DOCUMENT_SYMBOL_KIND_PREFERENCE_PREFIX + kind.name(), false); | ||
} | ||
|
||
static boolean toggleHideSymbolKind(SymbolKind kind) { | ||
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(LanguageServerPlugin.PLUGIN_ID); | ||
boolean oldValue = isHideSymbolKind(kind); | ||
|
||
preferences.putBoolean(CNFOutlinePage.HIDE_DOCUMENT_SYMBOL_KIND_PREFERENCE_PREFIX + kind.name(), !oldValue); | ||
|
||
return !oldValue; | ||
} | ||
|
||
private static class HideSymbolKindAction extends Action { | ||
private final SymbolKind kind; | ||
|
||
HideSymbolKindAction(SymbolKind kind) { | ||
super(kind.name(), IAction.AS_CHECK_BOX); | ||
this.kind = kind; | ||
this.setChecked(isHideSymbolKind(kind)); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
boolean checkedState = toggleHideSymbolKind(kind); | ||
setChecked(checkedState); | ||
} | ||
|
||
} | ||
|
||
} |