@theia/scm 1.45.1 → 1.46.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -31
- package/lib/browser/decorations/scm-decorations-service.d.ts +14 -14
- package/lib/browser/decorations/scm-decorations-service.js +101 -101
- package/lib/browser/decorations/scm-navigator-decorator.d.ts +25 -25
- package/lib/browser/decorations/scm-navigator-decorator.js +132 -132
- package/lib/browser/decorations/scm-tab-bar-decorator.d.ts +17 -17
- package/lib/browser/decorations/scm-tab-bar-decorator.js +93 -93
- package/lib/browser/dirty-diff/content-lines.d.ts +12 -12
- package/lib/browser/dirty-diff/content-lines.js +106 -106
- package/lib/browser/dirty-diff/content-lines.spec.d.ts +1 -1
- package/lib/browser/dirty-diff/content-lines.spec.js +39 -39
- package/lib/browser/dirty-diff/diff-computer.d.ts +29 -29
- package/lib/browser/dirty-diff/diff-computer.js +102 -102
- package/lib/browser/dirty-diff/diff-computer.spec.d.ts +1 -1
- package/lib/browser/dirty-diff/diff-computer.spec.js +315 -315
- package/lib/browser/dirty-diff/dirty-diff-decorator.d.ts +14 -14
- package/lib/browser/dirty-diff/dirty-diff-decorator.js +98 -98
- package/lib/browser/dirty-diff/dirty-diff-module.d.ts +3 -3
- package/lib/browser/dirty-diff/dirty-diff-module.js +24 -24
- package/lib/browser/scm-amend-component.d.ts +123 -123
- package/lib/browser/scm-amend-component.js +463 -463
- package/lib/browser/scm-amend-widget.d.ts +20 -20
- package/lib/browser/scm-amend-widget.js +101 -101
- package/lib/browser/scm-avatar-service.d.ts +3 -3
- package/lib/browser/scm-avatar-service.js +36 -36
- package/lib/browser/scm-commit-widget.d.ts +52 -52
- package/lib/browser/scm-commit-widget.js +199 -199
- package/lib/browser/scm-context-key-service.d.ts +10 -10
- package/lib/browser/scm-context-key-service.js +58 -58
- package/lib/browser/scm-contribution.d.ts +83 -83
- package/lib/browser/scm-contribution.js +356 -356
- package/lib/browser/scm-frontend-module.d.ts +6 -6
- package/lib/browser/scm-frontend-module.js +130 -130
- package/lib/browser/scm-groups-tree-model.d.ts +14 -14
- package/lib/browser/scm-groups-tree-model.js +97 -97
- package/lib/browser/scm-input.d.ts +53 -53
- package/lib/browser/scm-input.js +127 -127
- package/lib/browser/scm-layout-migrations.d.ts +9 -9
- package/lib/browser/scm-layout-migrations.js +79 -79
- package/lib/browser/scm-no-repository-widget.d.ts +8 -8
- package/lib/browser/scm-no-repository-widget.js +49 -49
- package/lib/browser/scm-preferences.d.ts +11 -11
- package/lib/browser/scm-preferences.js +51 -51
- package/lib/browser/scm-provider.d.ts +58 -58
- package/lib/browser/scm-provider.js +19 -19
- package/lib/browser/scm-quick-open-service.d.ts +11 -11
- package/lib/browser/scm-quick-open-service.js +73 -73
- package/lib/browser/scm-repository.d.ts +17 -17
- package/lib/browser/scm-repository.js +41 -41
- package/lib/browser/scm-service.d.ts +26 -26
- package/lib/browser/scm-service.js +108 -108
- package/lib/browser/scm-tree-label-provider.d.ts +7 -7
- package/lib/browser/scm-tree-label-provider.js +57 -57
- package/lib/browser/scm-tree-model.d.ts +74 -74
- package/lib/browser/scm-tree-model.js +351 -351
- package/lib/browser/scm-tree-widget.d.ts +208 -208
- package/lib/browser/scm-tree-widget.js +703 -703
- package/lib/browser/scm-widget.d.ts +40 -40
- package/lib/browser/scm-widget.js +218 -218
- package/package.json +6 -6
- package/src/browser/decorations/scm-decorations-service.ts +78 -78
- package/src/browser/decorations/scm-navigator-decorator.ts +121 -121
- package/src/browser/decorations/scm-tab-bar-decorator.ts +83 -83
- package/src/browser/dirty-diff/content-lines.spec.ts +42 -42
- package/src/browser/dirty-diff/content-lines.ts +112 -112
- package/src/browser/dirty-diff/diff-computer.spec.ts +387 -387
- package/src/browser/dirty-diff/diff-computer.ts +129 -129
- package/src/browser/dirty-diff/dirty-diff-decorator.ts +107 -107
- package/src/browser/dirty-diff/dirty-diff-module.ts +24 -24
- package/src/browser/scm-amend-component.tsx +600 -600
- package/src/browser/scm-amend-widget.tsx +77 -77
- package/src/browser/scm-avatar-service.ts +27 -27
- package/src/browser/scm-commit-widget.tsx +215 -215
- package/src/browser/scm-context-key-service.ts +46 -46
- package/src/browser/scm-contribution.ts +361 -361
- package/src/browser/scm-frontend-module.ts +149 -149
- package/src/browser/scm-groups-tree-model.ts +78 -78
- package/src/browser/scm-input.ts +164 -164
- package/src/browser/scm-layout-migrations.ts +64 -64
- package/src/browser/scm-no-repository-widget.tsx +41 -41
- package/src/browser/scm-preferences.ts +63 -63
- package/src/browser/scm-provider.ts +91 -91
- package/src/browser/scm-quick-open-service.ts +48 -48
- package/src/browser/scm-repository.ts +52 -52
- package/src/browser/scm-service.ts +108 -108
- package/src/browser/scm-tree-label-provider.ts +44 -44
- package/src/browser/scm-tree-model.ts +405 -405
- package/src/browser/scm-tree-widget.tsx +838 -838
- package/src/browser/scm-widget.tsx +204 -204
- package/src/browser/style/dirty-diff-decorator.css +52 -52
- package/src/browser/style/dirty-diff.css +50 -50
- package/src/browser/style/index.css +271 -271
- package/src/browser/style/scm-amend-component.css +94 -94
- package/src/browser/style/scm.svg +4 -4
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2019 Red Hat, Inc. and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable, inject } from '@theia/core/shared/inversify';
|
|
18
|
-
import { ResourceProvider } from '@theia/core';
|
|
19
|
-
import { DirtyDiffDecorator } from '../dirty-diff/dirty-diff-decorator';
|
|
20
|
-
import { DiffComputer } from '../dirty-diff/diff-computer';
|
|
21
|
-
import { ContentLines } from '../dirty-diff/content-lines';
|
|
22
|
-
import { EditorManager, TextEditor } from '@theia/editor/lib/browser';
|
|
23
|
-
import { ScmService } from '../scm-service';
|
|
24
|
-
|
|
25
|
-
@injectable()
|
|
26
|
-
export class ScmDecorationsService {
|
|
27
|
-
private readonly diffComputer: DiffComputer;
|
|
28
|
-
private dirtyState: boolean = true;
|
|
29
|
-
|
|
30
|
-
constructor(@inject(DirtyDiffDecorator) protected readonly decorator: DirtyDiffDecorator,
|
|
31
|
-
@inject(ScmService) protected readonly scmService: ScmService,
|
|
32
|
-
@inject(EditorManager) protected readonly editorManager: EditorManager,
|
|
33
|
-
@inject(ResourceProvider) protected readonly resourceProvider: ResourceProvider) {
|
|
34
|
-
this.diffComputer = new DiffComputer();
|
|
35
|
-
this.editorManager.onCreated(async editor => this.applyEditorDecorations(editor.editor));
|
|
36
|
-
this.scmService.onDidAddRepository(repository => repository.provider.onDidChange(() => {
|
|
37
|
-
const editor = this.editorManager.currentEditor;
|
|
38
|
-
if (editor) {
|
|
39
|
-
if (this.dirtyState) {
|
|
40
|
-
this.applyEditorDecorations(editor.editor);
|
|
41
|
-
this.dirtyState = false;
|
|
42
|
-
} else {
|
|
43
|
-
/** onDidChange event might be called several times one after another, so need to prevent repeated events. */
|
|
44
|
-
setTimeout(() => {
|
|
45
|
-
this.dirtyState = true;
|
|
46
|
-
}, 500);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}));
|
|
50
|
-
this.scmService.onDidChangeSelectedRepository(() => {
|
|
51
|
-
const editor = this.editorManager.currentEditor;
|
|
52
|
-
if (editor) {
|
|
53
|
-
this.applyEditorDecorations(editor.editor);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async applyEditorDecorations(editor: TextEditor): Promise<void> {
|
|
59
|
-
const currentRepo = this.scmService.selectedRepository;
|
|
60
|
-
if (currentRepo) {
|
|
61
|
-
try {
|
|
62
|
-
const uri = editor.uri.withScheme(currentRepo.provider.id).withQuery(`{"ref":"", "path":"${editor.uri.path.toString()}"}`);
|
|
63
|
-
const previousResource = await this.resourceProvider(uri);
|
|
64
|
-
const previousContent = await previousResource.readContents();
|
|
65
|
-
const previousLines = ContentLines.fromString(previousContent);
|
|
66
|
-
const currentResource = await this.resourceProvider(editor.uri);
|
|
67
|
-
const currentContent = await currentResource.readContents();
|
|
68
|
-
const currentLines = ContentLines.fromString(currentContent);
|
|
69
|
-
const { added, removed, modified } = this.diffComputer.computeDirtyDiff(ContentLines.arrayLike(previousLines), ContentLines.arrayLike(currentLines));
|
|
70
|
-
this.decorator.applyDecorations({ editor: editor, added, removed, modified });
|
|
71
|
-
currentResource.dispose();
|
|
72
|
-
previousResource.dispose();
|
|
73
|
-
} catch (e) {
|
|
74
|
-
// Scm resource may not be found, do nothing.
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2019 Red Hat, Inc. and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable, inject } from '@theia/core/shared/inversify';
|
|
18
|
+
import { ResourceProvider } from '@theia/core';
|
|
19
|
+
import { DirtyDiffDecorator } from '../dirty-diff/dirty-diff-decorator';
|
|
20
|
+
import { DiffComputer } from '../dirty-diff/diff-computer';
|
|
21
|
+
import { ContentLines } from '../dirty-diff/content-lines';
|
|
22
|
+
import { EditorManager, TextEditor } from '@theia/editor/lib/browser';
|
|
23
|
+
import { ScmService } from '../scm-service';
|
|
24
|
+
|
|
25
|
+
@injectable()
|
|
26
|
+
export class ScmDecorationsService {
|
|
27
|
+
private readonly diffComputer: DiffComputer;
|
|
28
|
+
private dirtyState: boolean = true;
|
|
29
|
+
|
|
30
|
+
constructor(@inject(DirtyDiffDecorator) protected readonly decorator: DirtyDiffDecorator,
|
|
31
|
+
@inject(ScmService) protected readonly scmService: ScmService,
|
|
32
|
+
@inject(EditorManager) protected readonly editorManager: EditorManager,
|
|
33
|
+
@inject(ResourceProvider) protected readonly resourceProvider: ResourceProvider) {
|
|
34
|
+
this.diffComputer = new DiffComputer();
|
|
35
|
+
this.editorManager.onCreated(async editor => this.applyEditorDecorations(editor.editor));
|
|
36
|
+
this.scmService.onDidAddRepository(repository => repository.provider.onDidChange(() => {
|
|
37
|
+
const editor = this.editorManager.currentEditor;
|
|
38
|
+
if (editor) {
|
|
39
|
+
if (this.dirtyState) {
|
|
40
|
+
this.applyEditorDecorations(editor.editor);
|
|
41
|
+
this.dirtyState = false;
|
|
42
|
+
} else {
|
|
43
|
+
/** onDidChange event might be called several times one after another, so need to prevent repeated events. */
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
this.dirtyState = true;
|
|
46
|
+
}, 500);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
this.scmService.onDidChangeSelectedRepository(() => {
|
|
51
|
+
const editor = this.editorManager.currentEditor;
|
|
52
|
+
if (editor) {
|
|
53
|
+
this.applyEditorDecorations(editor.editor);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async applyEditorDecorations(editor: TextEditor): Promise<void> {
|
|
59
|
+
const currentRepo = this.scmService.selectedRepository;
|
|
60
|
+
if (currentRepo) {
|
|
61
|
+
try {
|
|
62
|
+
const uri = editor.uri.withScheme(currentRepo.provider.id).withQuery(`{"ref":"", "path":"${editor.uri.path.toString()}"}`);
|
|
63
|
+
const previousResource = await this.resourceProvider(uri);
|
|
64
|
+
const previousContent = await previousResource.readContents();
|
|
65
|
+
const previousLines = ContentLines.fromString(previousContent);
|
|
66
|
+
const currentResource = await this.resourceProvider(editor.uri);
|
|
67
|
+
const currentContent = await currentResource.readContents();
|
|
68
|
+
const currentLines = ContentLines.fromString(currentContent);
|
|
69
|
+
const { added, removed, modified } = this.diffComputer.computeDirtyDiff(ContentLines.arrayLike(previousLines), ContentLines.arrayLike(currentLines));
|
|
70
|
+
this.decorator.applyDecorations({ editor: editor, added, removed, modified });
|
|
71
|
+
currentResource.dispose();
|
|
72
|
+
previousResource.dispose();
|
|
73
|
+
} catch (e) {
|
|
74
|
+
// Scm resource may not be found, do nothing.
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2019 Red Hat, Inc. and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
-
import { ILogger } from '@theia/core/lib/common/logger';
|
|
19
|
-
import { Event, Emitter } from '@theia/core/lib/common/event';
|
|
20
|
-
import { Tree } from '@theia/core/lib/browser/tree/tree';
|
|
21
|
-
import { TreeDecorator, TreeDecoration } from '@theia/core/lib/browser/tree/tree-decorator';
|
|
22
|
-
import { DepthFirstTreeIterator } from '@theia/core/lib/browser';
|
|
23
|
-
import { FileStatNode } from '@theia/filesystem/lib/browser';
|
|
24
|
-
import URI from '@theia/core/lib/common/uri';
|
|
25
|
-
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
|
|
26
|
-
import { Decoration, DecorationsService } from '@theia/core/lib/browser/decorations-service';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated since 1.25.0
|
|
30
|
-
* URI-based decorators should implement `DecorationsProvider` and contribute decorations via the `DecorationsService`.
|
|
31
|
-
*/
|
|
32
|
-
@injectable()
|
|
33
|
-
export class ScmNavigatorDecorator implements TreeDecorator {
|
|
34
|
-
|
|
35
|
-
readonly id = 'theia-scm-decorator';
|
|
36
|
-
private decorationsMap: Map<string, Decoration> | undefined;
|
|
37
|
-
|
|
38
|
-
@inject(ILogger) protected readonly logger: ILogger;
|
|
39
|
-
|
|
40
|
-
@inject(ColorRegistry)
|
|
41
|
-
protected readonly colors: ColorRegistry;
|
|
42
|
-
|
|
43
|
-
constructor(@inject(DecorationsService) protected readonly decorationsService: DecorationsService) {
|
|
44
|
-
this.decorationsService.onDidChangeDecorations(data => {
|
|
45
|
-
this.decorationsMap = data;
|
|
46
|
-
this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
protected collectDecorators(tree: Tree): Map<string, TreeDecoration.Data> {
|
|
51
|
-
const result = new Map();
|
|
52
|
-
if (tree.root === undefined || !this.decorationsMap) {
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
const markers = this.appendContainerChanges(this.decorationsMap);
|
|
56
|
-
for (const treeNode of new DepthFirstTreeIterator(tree.root)) {
|
|
57
|
-
const uri = FileStatNode.getUri(treeNode);
|
|
58
|
-
if (uri) {
|
|
59
|
-
const marker = markers.get(uri);
|
|
60
|
-
if (marker) {
|
|
61
|
-
result.set(treeNode.id, marker);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return new Map(Array.from(result.entries()).map(m => [m[0], this.toDecorator(m[1])] as [string, TreeDecoration.Data]));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
protected toDecorator(change: Decoration): TreeDecoration.Data {
|
|
69
|
-
const colorVariable = change.colorId && this.colors.toCssVariableName(change.colorId);
|
|
70
|
-
return {
|
|
71
|
-
tailDecorations: [
|
|
72
|
-
{
|
|
73
|
-
data: change.letter ? change.letter : '',
|
|
74
|
-
fontData: {
|
|
75
|
-
color: colorVariable && `var(${colorVariable})`
|
|
76
|
-
},
|
|
77
|
-
tooltip: change.tooltip ? change.tooltip : ''
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
protected readonly emitter = new Emitter<(tree: Tree) => Map<string, TreeDecoration.Data>>();
|
|
84
|
-
|
|
85
|
-
async decorations(tree: Tree): Promise<Map<string, TreeDecoration.Data>> {
|
|
86
|
-
if (this.decorationsMap) {
|
|
87
|
-
return this.collectDecorators(tree);
|
|
88
|
-
} else {
|
|
89
|
-
return new Map();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
protected appendContainerChanges(decorationsMap: Map<string, Decoration>): Map<string, Decoration> {
|
|
94
|
-
const result: Map<string, Decoration> = new Map();
|
|
95
|
-
for (const [uri, data] of decorationsMap.entries()) {
|
|
96
|
-
const uriString = uri.toString();
|
|
97
|
-
result.set(uriString, data);
|
|
98
|
-
let parentUri: URI | undefined = new URI(uri).parent;
|
|
99
|
-
while (parentUri && !parentUri.path.isRoot) {
|
|
100
|
-
const parentUriString = parentUri.toString();
|
|
101
|
-
const existing = result.get(parentUriString);
|
|
102
|
-
if (existing === undefined) {
|
|
103
|
-
result.set(parentUriString, data);
|
|
104
|
-
parentUri = parentUri.parent;
|
|
105
|
-
} else {
|
|
106
|
-
parentUri = undefined;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
get onDidChangeDecorations(): Event<(tree: Tree) => Map<string, TreeDecoration.Data>> {
|
|
114
|
-
return this.emitter.event;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
fireDidChangeDecorations(event: (tree: Tree) => Map<string, TreeDecoration.Data>): void {
|
|
118
|
-
this.emitter.fire(event);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2019 Red Hat, Inc. and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { ILogger } from '@theia/core/lib/common/logger';
|
|
19
|
+
import { Event, Emitter } from '@theia/core/lib/common/event';
|
|
20
|
+
import { Tree } from '@theia/core/lib/browser/tree/tree';
|
|
21
|
+
import { TreeDecorator, TreeDecoration } from '@theia/core/lib/browser/tree/tree-decorator';
|
|
22
|
+
import { DepthFirstTreeIterator } from '@theia/core/lib/browser';
|
|
23
|
+
import { FileStatNode } from '@theia/filesystem/lib/browser';
|
|
24
|
+
import URI from '@theia/core/lib/common/uri';
|
|
25
|
+
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
|
|
26
|
+
import { Decoration, DecorationsService } from '@theia/core/lib/browser/decorations-service';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated since 1.25.0
|
|
30
|
+
* URI-based decorators should implement `DecorationsProvider` and contribute decorations via the `DecorationsService`.
|
|
31
|
+
*/
|
|
32
|
+
@injectable()
|
|
33
|
+
export class ScmNavigatorDecorator implements TreeDecorator {
|
|
34
|
+
|
|
35
|
+
readonly id = 'theia-scm-decorator';
|
|
36
|
+
private decorationsMap: Map<string, Decoration> | undefined;
|
|
37
|
+
|
|
38
|
+
@inject(ILogger) protected readonly logger: ILogger;
|
|
39
|
+
|
|
40
|
+
@inject(ColorRegistry)
|
|
41
|
+
protected readonly colors: ColorRegistry;
|
|
42
|
+
|
|
43
|
+
constructor(@inject(DecorationsService) protected readonly decorationsService: DecorationsService) {
|
|
44
|
+
this.decorationsService.onDidChangeDecorations(data => {
|
|
45
|
+
this.decorationsMap = data;
|
|
46
|
+
this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected collectDecorators(tree: Tree): Map<string, TreeDecoration.Data> {
|
|
51
|
+
const result = new Map();
|
|
52
|
+
if (tree.root === undefined || !this.decorationsMap) {
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
const markers = this.appendContainerChanges(this.decorationsMap);
|
|
56
|
+
for (const treeNode of new DepthFirstTreeIterator(tree.root)) {
|
|
57
|
+
const uri = FileStatNode.getUri(treeNode);
|
|
58
|
+
if (uri) {
|
|
59
|
+
const marker = markers.get(uri);
|
|
60
|
+
if (marker) {
|
|
61
|
+
result.set(treeNode.id, marker);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return new Map(Array.from(result.entries()).map(m => [m[0], this.toDecorator(m[1])] as [string, TreeDecoration.Data]));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected toDecorator(change: Decoration): TreeDecoration.Data {
|
|
69
|
+
const colorVariable = change.colorId && this.colors.toCssVariableName(change.colorId);
|
|
70
|
+
return {
|
|
71
|
+
tailDecorations: [
|
|
72
|
+
{
|
|
73
|
+
data: change.letter ? change.letter : '',
|
|
74
|
+
fontData: {
|
|
75
|
+
color: colorVariable && `var(${colorVariable})`
|
|
76
|
+
},
|
|
77
|
+
tooltip: change.tooltip ? change.tooltip : ''
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected readonly emitter = new Emitter<(tree: Tree) => Map<string, TreeDecoration.Data>>();
|
|
84
|
+
|
|
85
|
+
async decorations(tree: Tree): Promise<Map<string, TreeDecoration.Data>> {
|
|
86
|
+
if (this.decorationsMap) {
|
|
87
|
+
return this.collectDecorators(tree);
|
|
88
|
+
} else {
|
|
89
|
+
return new Map();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
protected appendContainerChanges(decorationsMap: Map<string, Decoration>): Map<string, Decoration> {
|
|
94
|
+
const result: Map<string, Decoration> = new Map();
|
|
95
|
+
for (const [uri, data] of decorationsMap.entries()) {
|
|
96
|
+
const uriString = uri.toString();
|
|
97
|
+
result.set(uriString, data);
|
|
98
|
+
let parentUri: URI | undefined = new URI(uri).parent;
|
|
99
|
+
while (parentUri && !parentUri.path.isRoot) {
|
|
100
|
+
const parentUriString = parentUri.toString();
|
|
101
|
+
const existing = result.get(parentUriString);
|
|
102
|
+
if (existing === undefined) {
|
|
103
|
+
result.set(parentUriString, data);
|
|
104
|
+
parentUri = parentUri.parent;
|
|
105
|
+
} else {
|
|
106
|
+
parentUri = undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get onDidChangeDecorations(): Event<(tree: Tree) => Map<string, TreeDecoration.Data>> {
|
|
114
|
+
return this.emitter.event;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fireDidChangeDecorations(event: (tree: Tree) => Map<string, TreeDecoration.Data>): void {
|
|
118
|
+
this.emitter.fire(event);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
}
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2020 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
-
import { Event, Emitter } from '@theia/core/lib/common/event';
|
|
19
|
-
import { ScmService } from '../scm-service';
|
|
20
|
-
import { TabBarDecorator } from '@theia/core/lib/browser/shell/tab-bar-decorator';
|
|
21
|
-
import { Title, ViewContainer, Widget } from '@theia/core/lib/browser';
|
|
22
|
-
import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration';
|
|
23
|
-
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
|
24
|
-
import { ScmWidget } from '../scm-widget';
|
|
25
|
-
|
|
26
|
-
@injectable()
|
|
27
|
-
export class ScmTabBarDecorator implements TabBarDecorator {
|
|
28
|
-
|
|
29
|
-
readonly id = 'theia-scm-tabbar-decorator';
|
|
30
|
-
protected readonly emitter = new Emitter<void>();
|
|
31
|
-
|
|
32
|
-
private readonly toDispose = new DisposableCollection();
|
|
33
|
-
private readonly toDisposeOnDidChange = new DisposableCollection();
|
|
34
|
-
|
|
35
|
-
@inject(ScmService)
|
|
36
|
-
protected readonly scmService: ScmService;
|
|
37
|
-
|
|
38
|
-
@postConstruct()
|
|
39
|
-
protected init(): void {
|
|
40
|
-
this.toDispose.push(this.scmService.onDidChangeSelectedRepository(repository => {
|
|
41
|
-
this.toDisposeOnDidChange.dispose();
|
|
42
|
-
if (repository) {
|
|
43
|
-
this.toDisposeOnDidChange.push(
|
|
44
|
-
repository.provider.onDidChange(() => this.fireDidChangeDecorations())
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
this.fireDidChangeDecorations();
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
decorate(title: Title<Widget>): WidgetDecoration.Data[] {
|
|
52
|
-
const { owner } = title;
|
|
53
|
-
if (owner instanceof ViewContainer && owner.getParts().find(part => part.wrapped instanceof ScmWidget)) {
|
|
54
|
-
const changes = this.collectChangesCount();
|
|
55
|
-
return changes > 0 ? [{ badge: changes }] : [];
|
|
56
|
-
} else {
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
protected collectChangesCount(): number {
|
|
62
|
-
const repository = this.scmService.selectedRepository;
|
|
63
|
-
let changes = 0;
|
|
64
|
-
if (!repository) {
|
|
65
|
-
return 0;
|
|
66
|
-
}
|
|
67
|
-
repository.provider.groups.map(group => {
|
|
68
|
-
if (group.id === 'index' || group.id === 'workingTree') {
|
|
69
|
-
changes += group.resources.length;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return changes;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
get onDidChangeDecorations(): Event<void> {
|
|
76
|
-
return this.emitter.event;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
protected fireDidChangeDecorations(): void {
|
|
80
|
-
this.emitter.fire(undefined);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2020 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
+
import { Event, Emitter } from '@theia/core/lib/common/event';
|
|
19
|
+
import { ScmService } from '../scm-service';
|
|
20
|
+
import { TabBarDecorator } from '@theia/core/lib/browser/shell/tab-bar-decorator';
|
|
21
|
+
import { Title, ViewContainer, Widget } from '@theia/core/lib/browser';
|
|
22
|
+
import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration';
|
|
23
|
+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
|
24
|
+
import { ScmWidget } from '../scm-widget';
|
|
25
|
+
|
|
26
|
+
@injectable()
|
|
27
|
+
export class ScmTabBarDecorator implements TabBarDecorator {
|
|
28
|
+
|
|
29
|
+
readonly id = 'theia-scm-tabbar-decorator';
|
|
30
|
+
protected readonly emitter = new Emitter<void>();
|
|
31
|
+
|
|
32
|
+
private readonly toDispose = new DisposableCollection();
|
|
33
|
+
private readonly toDisposeOnDidChange = new DisposableCollection();
|
|
34
|
+
|
|
35
|
+
@inject(ScmService)
|
|
36
|
+
protected readonly scmService: ScmService;
|
|
37
|
+
|
|
38
|
+
@postConstruct()
|
|
39
|
+
protected init(): void {
|
|
40
|
+
this.toDispose.push(this.scmService.onDidChangeSelectedRepository(repository => {
|
|
41
|
+
this.toDisposeOnDidChange.dispose();
|
|
42
|
+
if (repository) {
|
|
43
|
+
this.toDisposeOnDidChange.push(
|
|
44
|
+
repository.provider.onDidChange(() => this.fireDidChangeDecorations())
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
this.fireDidChangeDecorations();
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
decorate(title: Title<Widget>): WidgetDecoration.Data[] {
|
|
52
|
+
const { owner } = title;
|
|
53
|
+
if (owner instanceof ViewContainer && owner.getParts().find(part => part.wrapped instanceof ScmWidget)) {
|
|
54
|
+
const changes = this.collectChangesCount();
|
|
55
|
+
return changes > 0 ? [{ badge: changes }] : [];
|
|
56
|
+
} else {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected collectChangesCount(): number {
|
|
62
|
+
const repository = this.scmService.selectedRepository;
|
|
63
|
+
let changes = 0;
|
|
64
|
+
if (!repository) {
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
repository.provider.groups.map(group => {
|
|
68
|
+
if (group.id === 'index' || group.id === 'workingTree') {
|
|
69
|
+
changes += group.resources.length;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return changes;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get onDidChangeDecorations(): Event<void> {
|
|
76
|
+
return this.emitter.event;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
protected fireDidChangeDecorations(): void {
|
|
80
|
+
this.emitter.fire(undefined);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|