Path: blob/main/src/vs/workbench/contrib/outline/browser/outlineViewState.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 { Emitter } from '../../../../base/common/event.js';6import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';7import { IOutlineViewState, OutlineSortOrder } from './outline.js';89export class OutlineViewState implements IOutlineViewState {1011private _followCursor = false;12private _filterOnType = true;13private _sortBy = OutlineSortOrder.ByPosition;1415private readonly _onDidChange = new Emitter<{ followCursor?: boolean; sortBy?: boolean; filterOnType?: boolean }>();16readonly onDidChange = this._onDidChange.event;1718dispose(): void {19this._onDidChange.dispose();20}2122set followCursor(value: boolean) {23if (value !== this._followCursor) {24this._followCursor = value;25this._onDidChange.fire({ followCursor: true });26}27}2829get followCursor(): boolean {30return this._followCursor;31}3233get filterOnType() {34return this._filterOnType;35}3637set filterOnType(value) {38if (value !== this._filterOnType) {39this._filterOnType = value;40this._onDidChange.fire({ filterOnType: true });41}42}4344set sortBy(value: OutlineSortOrder) {45if (value !== this._sortBy) {46this._sortBy = value;47this._onDidChange.fire({ sortBy: true });48}49}5051get sortBy(): OutlineSortOrder {52return this._sortBy;53}5455persist(storageService: IStorageService): void {56storageService.store('outline/state', JSON.stringify({57followCursor: this.followCursor,58sortBy: this.sortBy,59filterOnType: this.filterOnType,60}), StorageScope.WORKSPACE, StorageTarget.MACHINE);61}6263restore(storageService: IStorageService): void {64const raw = storageService.get('outline/state', StorageScope.WORKSPACE);65if (!raw) {66return;67}68let data: any;69try {70data = JSON.parse(raw);71} catch (e) {72return;73}74this.followCursor = data.followCursor;75this.sortBy = data.sortBy ?? OutlineSortOrder.ByPosition;76if (typeof data.filterOnType === 'boolean') {77this.filterOnType = data.filterOnType;78}79}80}818283