Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/outline/browser/outlineViewState.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Emitter } from '../../../../base/common/event.js';
7
import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
8
import { IOutlineViewState, OutlineSortOrder } from './outline.js';
9
10
export class OutlineViewState implements IOutlineViewState {
11
12
private _followCursor = false;
13
private _filterOnType = true;
14
private _sortBy = OutlineSortOrder.ByPosition;
15
16
private readonly _onDidChange = new Emitter<{ followCursor?: boolean; sortBy?: boolean; filterOnType?: boolean }>();
17
readonly onDidChange = this._onDidChange.event;
18
19
dispose(): void {
20
this._onDidChange.dispose();
21
}
22
23
set followCursor(value: boolean) {
24
if (value !== this._followCursor) {
25
this._followCursor = value;
26
this._onDidChange.fire({ followCursor: true });
27
}
28
}
29
30
get followCursor(): boolean {
31
return this._followCursor;
32
}
33
34
get filterOnType() {
35
return this._filterOnType;
36
}
37
38
set filterOnType(value) {
39
if (value !== this._filterOnType) {
40
this._filterOnType = value;
41
this._onDidChange.fire({ filterOnType: true });
42
}
43
}
44
45
set sortBy(value: OutlineSortOrder) {
46
if (value !== this._sortBy) {
47
this._sortBy = value;
48
this._onDidChange.fire({ sortBy: true });
49
}
50
}
51
52
get sortBy(): OutlineSortOrder {
53
return this._sortBy;
54
}
55
56
persist(storageService: IStorageService): void {
57
storageService.store('outline/state', JSON.stringify({
58
followCursor: this.followCursor,
59
sortBy: this.sortBy,
60
filterOnType: this.filterOnType,
61
}), StorageScope.WORKSPACE, StorageTarget.MACHINE);
62
}
63
64
restore(storageService: IStorageService): void {
65
const raw = storageService.get('outline/state', StorageScope.WORKSPACE);
66
if (!raw) {
67
return;
68
}
69
let data: any;
70
try {
71
data = JSON.parse(raw);
72
} catch (e) {
73
return;
74
}
75
this.followCursor = data.followCursor;
76
this.sortBy = data.sortBy ?? OutlineSortOrder.ByPosition;
77
if (typeof data.filterOnType === 'boolean') {
78
this.filterOnType = data.filterOnType;
79
}
80
}
81
}
82
83