Skip to content

Commit

Permalink
try scm decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
kenneth-marut-work committed Nov 1, 2021
1 parent 579313c commit 739b6c1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 53 deletions.
1 change: 0 additions & 1 deletion packages/editor-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"dependencies": {
"@theia/core": "1.19.0",
"@theia/editor": "1.19.0",
"@theia/filesystem": "1.19.0",
"@theia/navigator": "1.19.0"
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { Emitter } from '@theia/core/lib/common/event';
import { Tree } from '@theia/core/lib/browser/tree/tree';
import {
ApplicationShell,
CorePreferences,
DepthFirstTreeIterator,
FrontendApplication,
FrontendApplicationContribution,
Expand All @@ -32,17 +31,11 @@ import { Disposable } from '@theia/core/lib/common';
import { OpenEditorNode } from '@theia/navigator/lib/browser/open-editors-widget/navigator-open-editors-tree-model';
import { EditorPreviewWidget } from './editor-preview-widget';
import { EditorPreviewManager } from './editor-preview-manager';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { FileChangesEvent } from '@theia/filesystem/lib/common/files';

@injectable()
export class EditorPreviewTreeDecorator implements TreeDecorator, FrontendApplicationContribution {
@inject(EditorPreviewManager) protected readonly editorPreviewManager: EditorPreviewManager;
@inject(ApplicationShell) protected readonly shell: ApplicationShell;
@inject(CorePreferences) protected readonly corePreferences: CorePreferences;
@inject(FileService) protected readonly fileService: FileService;

protected deletedEditorIds = new Set<string>();

readonly id = 'theia-open-editors-file-decorator';
protected decorationsMap = new Map<string, TreeDecoration.Data>();
Expand All @@ -56,35 +49,6 @@ export class EditorPreviewTreeDecorator implements TreeDecorator, FrontendApplic
this.shell.onDidAddWidget(widget => this.registerEditorListeners(widget));
this.shell.onDidRemoveWidget(widget => this.unregisterEditorListeners(widget));
this.editorWidgets.forEach(widget => this.registerEditorListeners(widget));
this.fileService.onDidFilesChange(async (event: FileChangesEvent) => {
if (!this.corePreferences['workbench.editor.closeOnFileDelete']) {
await this.checkForEditorDeleted(event);
this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
}
});
}

protected async checkForEditorDeleted(event: FileChangesEvent): Promise<void> {
// this implementation to check for deleted files is necessary since the gotDeleted check is not always reliable
const fileExistPromises: Promise<void>[] = [];
this.editorWidgets.forEach(editor => {
const editorURI = editor.getResourceUri();
if (editorURI && event.contains(editorURI)) {
const fileExistsPromise = this.fileService.exists(editorURI)
.then(doesExist => {
if (doesExist) {
this.deletedEditorIds.delete(editor.id);
} else {
this.deletedEditorIds.add(editor.id);
}
});
fileExistPromises.push(fileExistsPromise);
}
});
if (!fileExistPromises.length) {
return;
}
await Promise.all(fileExistPromises);
}

protected registerEditorListeners(widget: Widget): void {
Expand Down Expand Up @@ -129,18 +93,13 @@ export class EditorPreviewTreeDecorator implements TreeDecorator, FrontendApplic
return result;
}
for (const node of new DepthFirstTreeIterator(tree.root)) {
if (OpenEditorNode.is(node) && NavigatableWidget.is(node.widget)) {
if (OpenEditorNode.is(node)) {
const { widget } = node;
const isPreviewWidget = widget instanceof EditorPreviewWidget && widget.isPreview;
const deleted = this.deletedEditorIds.has(widget.id);
const style: TreeDecoration.FontStyle[] = [];
if (isPreviewWidget) {
style.push('italic');
}
if (deleted) {
style.push('line-through');
}
result.set(node.id, { fontData: { style } });
const decorations: TreeDecoration.Data = {
fontData: { style: isPreviewWidget ? 'italic' : undefined }
};
result.set(node.id, decorations);
}
}
return result;
Expand Down
6 changes: 0 additions & 6 deletions packages/editor-preview/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
},
{
"path": "../editor"
},
{
"path": "../filesystem"
},
{
"path": "../navigator"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class ScmNavigatorDecorator implements TreeDecorator {
protected toDecorator(change: Decoration): TreeDecoration.Data {
const colorVariable = change.colorId && this.colors.toCssVariableName(change.colorId);
return {
fontData: change.letter === "D" ? { style: 'line-through' } : undefined,
tailDecorations: [
{
data: change.letter ? change.letter : '',
Expand Down

0 comments on commit 739b6c1

Please sign in to comment.