Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debt - extract outline actions and outline interfaces into separate files #164887

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/vs/workbench/contrib/outline/browser/outline.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { localize } from 'vs/nls';
import { IViewsRegistry, IViewDescriptor, Extensions as ViewExtensions } from 'vs/workbench/common/views';
import { IViewsRegistry, Extensions as ViewExtensions } from 'vs/workbench/common/views';
import { OutlinePane } from './outlinePane';
import { Registry } from 'vs/platform/registry/common/platform';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
Expand All @@ -13,12 +13,18 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { Codicon } from 'vs/base/common/codicons';
import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
import { OutlineConfigKeys } from 'vs/workbench/services/outline/browser/outline';
import { IOutlinePane } from 'vs/workbench/contrib/outline/browser/outline';

// --- actions

import './outlineActions';

// --- view

const outlineViewIcon = registerIcon('outline-view-icon', Codicon.symbolClass, localize('outlineViewIcon', 'View icon of the outline view.'));

const _outlineDesc = <IViewDescriptor>{
id: OutlinePane.Id,
Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).registerViews([{
id: IOutlinePane.Id,
name: localize('name', "Outline"),
containerIcon: outlineViewIcon,
ctorDescriptor: new SyncDescriptor(OutlinePane),
Expand All @@ -29,9 +35,9 @@ const _outlineDesc = <IViewDescriptor>{
order: 2,
weight: 30,
focusCommand: { id: 'outline.focus' }
};
}], VIEW_CONTAINER);

Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).registerViews([_outlineDesc], VIEW_CONTAINER);
// --- configurations

Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({
'id': 'outline',
Expand Down
36 changes: 36 additions & 0 deletions src/vs/workbench/contrib/outline/browser/outline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import type { IView } from 'vs/workbench/common/views';

export const enum OutlineSortOrder {
ByPosition,
ByName,
ByKind
}

export interface IOutlineViewState {
followCursor: boolean;
filterOnType: boolean;
sortBy: OutlineSortOrder;
}

export namespace IOutlinePane {
export const Id = 'outline';
}

export interface IOutlinePane extends IView {
outlineViewState: IOutlineViewState;
collapseAll(): void;
expandAll(): void;
}

// --- context keys

export const ctxFollowsCursor = new RawContextKey<boolean>('outlineFollowsCursor', false);
export const ctxFilterOnType = new RawContextKey<boolean>('outlineFiltersOnType', false);
export const ctxSortMode = new RawContextKey<OutlineSortOrder>('outlineSortMode', OutlineSortOrder.ByPosition);
export const ctxAllCollapsed = new RawContextKey<boolean>('outlineAllCollapsed', false);
161 changes: 161 additions & 0 deletions src/vs/workbench/contrib/outline/browser/outlineActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { localize } from 'vs/nls';
import { Codicon } from 'vs/base/common/codicons';
import { MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
import { ViewAction } from 'vs/workbench/browser/parts/views/viewPane';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ctxAllCollapsed, ctxFilterOnType, ctxFollowsCursor, ctxSortMode, IOutlinePane, OutlineSortOrder } from 'vs/workbench/contrib/outline/browser/outline';


// --- commands

registerAction2(class CollapseAll extends ViewAction<IOutlinePane> {
constructor() {
super({
viewId: IOutlinePane.Id,
id: 'outline.collapse',
title: localize('collapse', "Collapse All"),
f1: false,
icon: Codicon.collapseAll,
menu: {
id: MenuId.ViewTitle,
group: 'navigation',
when: ContextKeyExpr.and(ContextKeyExpr.equals('view', IOutlinePane.Id), ctxAllCollapsed.isEqualTo(false))
}
});
}
runInView(_accessor: ServicesAccessor, view: IOutlinePane) {
view.collapseAll();
}
});

registerAction2(class ExpandAll extends ViewAction<IOutlinePane> {
constructor() {
super({
viewId: IOutlinePane.Id,
id: 'outline.expand',
title: localize('expand', "Expand All"),
f1: false,
icon: Codicon.expandAll,
menu: {
id: MenuId.ViewTitle,
group: 'navigation',
when: ContextKeyExpr.and(ContextKeyExpr.equals('view', IOutlinePane.Id), ctxAllCollapsed.isEqualTo(true))
}
});
}
runInView(_accessor: ServicesAccessor, view: IOutlinePane) {
view.expandAll();
}
});

registerAction2(class FollowCursor extends ViewAction<IOutlinePane> {
constructor() {
super({
viewId: IOutlinePane.Id,
id: 'outline.followCursor',
title: localize('followCur', "Follow Cursor"),
f1: false,
toggled: ctxFollowsCursor,
menu: {
id: MenuId.ViewTitle,
group: 'config',
order: 1,
when: ContextKeyExpr.equals('view', IOutlinePane.Id)
}
});
}
runInView(_accessor: ServicesAccessor, view: IOutlinePane) {
view.outlineViewState.followCursor = !view.outlineViewState.followCursor;
}
});

registerAction2(class FilterOnType extends ViewAction<IOutlinePane> {
constructor() {
super({
viewId: IOutlinePane.Id,
id: 'outline.filterOnType',
title: localize('filterOnType', "Filter on Type"),
f1: false,
toggled: ctxFilterOnType,
menu: {
id: MenuId.ViewTitle,
group: 'config',
order: 2,
when: ContextKeyExpr.equals('view', IOutlinePane.Id)
}
});
}
runInView(_accessor: ServicesAccessor, view: IOutlinePane) {
view.outlineViewState.filterOnType = !view.outlineViewState.filterOnType;
}
});


registerAction2(class SortByPosition extends ViewAction<IOutlinePane> {
constructor() {
super({
viewId: IOutlinePane.Id,
id: 'outline.sortByPosition',
title: localize('sortByPosition', "Sort By: Position"),
f1: false,
toggled: ctxSortMode.isEqualTo(OutlineSortOrder.ByPosition),
menu: {
id: MenuId.ViewTitle,
group: 'sort',
order: 1,
when: ContextKeyExpr.equals('view', IOutlinePane.Id)
}
});
}
runInView(_accessor: ServicesAccessor, view: IOutlinePane) {
view.outlineViewState.sortBy = OutlineSortOrder.ByPosition;
}
});

registerAction2(class SortByName extends ViewAction<IOutlinePane> {
constructor() {
super({
viewId: IOutlinePane.Id,
id: 'outline.sortByName',
title: localize('sortByName', "Sort By: Name"),
f1: false,
toggled: ctxSortMode.isEqualTo(OutlineSortOrder.ByName),
menu: {
id: MenuId.ViewTitle,
group: 'sort',
order: 2,
when: ContextKeyExpr.equals('view', IOutlinePane.Id)
}
});
}
runInView(_accessor: ServicesAccessor, view: IOutlinePane) {
view.outlineViewState.sortBy = OutlineSortOrder.ByName;
}
});

registerAction2(class SortByKind extends ViewAction<IOutlinePane> {
constructor() {
super({
viewId: IOutlinePane.Id,
id: 'outline.sortByKind',
title: localize('sortByKind', "Sort By: Category"),
f1: false,
toggled: ctxSortMode.isEqualTo(OutlineSortOrder.ByKind),
menu: {
id: MenuId.ViewTitle,
group: 'sort',
order: 3,
when: ContextKeyExpr.equals('view', IOutlinePane.Id)
}
});
}
runInView(_accessor: ServicesAccessor, view: IOutlinePane) {
view.outlineViewState.sortBy = OutlineSortOrder.ByKind;
}
});
Loading