Path: blob/main/src/vs/workbench/contrib/outline/browser/outlineActions.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { localize } from '../../../../nls.js';6import { Codicon } from '../../../../base/common/codicons.js';7import { MenuId, registerAction2 } from '../../../../platform/actions/common/actions.js';8import { ViewAction } from '../../../browser/parts/views/viewPane.js';9import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';10import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';11import { ctxAllCollapsed, ctxFilterOnType, ctxFollowsCursor, ctxSortMode, IOutlinePane, OutlineSortOrder } from './outline.js';121314// --- commands1516registerAction2(class CollapseAll extends ViewAction<IOutlinePane> {17constructor() {18super({19viewId: IOutlinePane.Id,20id: 'outline.collapse',21title: localize('collapse', "Collapse All"),22f1: false,23icon: Codicon.collapseAll,24menu: {25id: MenuId.ViewTitle,26group: 'navigation',27when: ContextKeyExpr.and(ContextKeyExpr.equals('view', IOutlinePane.Id), ctxAllCollapsed.isEqualTo(false))28}29});30}31runInView(_accessor: ServicesAccessor, view: IOutlinePane) {32view.collapseAll();33}34});3536registerAction2(class ExpandAll extends ViewAction<IOutlinePane> {37constructor() {38super({39viewId: IOutlinePane.Id,40id: 'outline.expand',41title: localize('expand', "Expand All"),42f1: false,43icon: Codicon.expandAll,44menu: {45id: MenuId.ViewTitle,46group: 'navigation',47when: ContextKeyExpr.and(ContextKeyExpr.equals('view', IOutlinePane.Id), ctxAllCollapsed.isEqualTo(true))48}49});50}51runInView(_accessor: ServicesAccessor, view: IOutlinePane) {52view.expandAll();53}54});5556registerAction2(class FollowCursor extends ViewAction<IOutlinePane> {57constructor() {58super({59viewId: IOutlinePane.Id,60id: 'outline.followCursor',61title: localize('followCur', "Follow Cursor"),62f1: false,63toggled: ctxFollowsCursor,64menu: {65id: MenuId.ViewTitle,66group: 'config',67order: 1,68when: ContextKeyExpr.equals('view', IOutlinePane.Id)69}70});71}72runInView(_accessor: ServicesAccessor, view: IOutlinePane) {73view.outlineViewState.followCursor = !view.outlineViewState.followCursor;74}75});7677registerAction2(class FilterOnType extends ViewAction<IOutlinePane> {78constructor() {79super({80viewId: IOutlinePane.Id,81id: 'outline.filterOnType',82title: localize('filterOnType', "Filter on Type"),83f1: false,84toggled: ctxFilterOnType,85menu: {86id: MenuId.ViewTitle,87group: 'config',88order: 2,89when: ContextKeyExpr.equals('view', IOutlinePane.Id)90}91});92}93runInView(_accessor: ServicesAccessor, view: IOutlinePane) {94view.outlineViewState.filterOnType = !view.outlineViewState.filterOnType;95}96});979899registerAction2(class SortByPosition extends ViewAction<IOutlinePane> {100constructor() {101super({102viewId: IOutlinePane.Id,103id: 'outline.sortByPosition',104title: localize('sortByPosition', "Sort By: Position"),105f1: false,106toggled: ctxSortMode.isEqualTo(OutlineSortOrder.ByPosition),107menu: {108id: MenuId.ViewTitle,109group: 'sort',110order: 1,111when: ContextKeyExpr.equals('view', IOutlinePane.Id)112}113});114}115runInView(_accessor: ServicesAccessor, view: IOutlinePane) {116view.outlineViewState.sortBy = OutlineSortOrder.ByPosition;117}118});119120registerAction2(class SortByName extends ViewAction<IOutlinePane> {121constructor() {122super({123viewId: IOutlinePane.Id,124id: 'outline.sortByName',125title: localize('sortByName', "Sort By: Name"),126f1: false,127toggled: ctxSortMode.isEqualTo(OutlineSortOrder.ByName),128menu: {129id: MenuId.ViewTitle,130group: 'sort',131order: 2,132when: ContextKeyExpr.equals('view', IOutlinePane.Id)133}134});135}136runInView(_accessor: ServicesAccessor, view: IOutlinePane) {137view.outlineViewState.sortBy = OutlineSortOrder.ByName;138}139});140141registerAction2(class SortByKind extends ViewAction<IOutlinePane> {142constructor() {143super({144viewId: IOutlinePane.Id,145id: 'outline.sortByKind',146title: localize('sortByKind', "Sort By: Category"),147f1: false,148toggled: ctxSortMode.isEqualTo(OutlineSortOrder.ByKind),149menu: {150id: MenuId.ViewTitle,151group: 'sort',152order: 3,153when: ContextKeyExpr.equals('view', IOutlinePane.Id)154}155});156}157runInView(_accessor: ServicesAccessor, view: IOutlinePane) {158view.outlineViewState.sortBy = OutlineSortOrder.ByKind;159}160});161162163