-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle deleted files in open editors widget
- Loading branch information
1 parent
c558358
commit cc34e5a
Showing
4 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/navigator/src/browser/open-editors-widget/navigator-deleted-editor-decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify'; | ||
import { DepthFirstTreeIterator, NavigatableWidget, Tree, TreeDecoration, TreeDecorator } from '@theia/core/lib/browser'; | ||
import { FileSystemFrontendContribution } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution'; | ||
import { Emitter } from '@theia/core'; | ||
import { OpenEditorNode } from './navigator-open-editors-tree-model'; | ||
import { FileChangeType } from '@theia/filesystem/lib/browser'; | ||
|
||
@injectable() | ||
export class NavigatorDeletedEditorDecorator implements TreeDecorator { | ||
|
||
@inject(FileSystemFrontendContribution) | ||
protected readonly fileSystemContribution: FileSystemFrontendContribution; | ||
|
||
readonly id = 'theia-deleted-editor-decorator'; | ||
protected readonly onDidChangeDecorationsEmitter = new Emitter(); | ||
readonly onDidChangeDecorations = this.onDidChangeDecorationsEmitter.event; | ||
protected deletedEditors = new Set<NavigatableWidget>(); | ||
|
||
@postConstruct() | ||
init(): void { | ||
this.fileSystemContribution.onDidChangeEditorFile(({ editor, type }) => { | ||
if (type === FileChangeType.DELETED) { | ||
this.deletedEditors.add(editor); | ||
} else if (type === FileChangeType.ADDED) { | ||
this.deletedEditors.delete(editor); | ||
} | ||
this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree)); | ||
}); | ||
} | ||
|
||
decorations(tree: Tree): Map<string, TreeDecoration.Data> { | ||
return this.collectDecorators(tree); | ||
} | ||
|
||
protected collectDecorators(tree: Tree): Map<string, TreeDecoration.Data> { | ||
const deletedEditorsCopy = new Set(this.deletedEditors); | ||
const result = new Map<string, TreeDecoration.Data>(); | ||
if (tree.root === undefined) { | ||
return result; | ||
} | ||
for (const node of new DepthFirstTreeIterator(tree.root)) { | ||
if (OpenEditorNode.is(node) && NavigatableWidget.is(node.widget)) { | ||
if (this.deletedEditors.has(node.widget)) { | ||
const deletedDecoration: TreeDecoration.Data = { | ||
fontData: { | ||
style: 'line-through', | ||
} | ||
}; | ||
deletedEditorsCopy.delete(node.widget); | ||
result.set(node.id, deletedDecoration); | ||
} | ||
} | ||
} | ||
deletedEditorsCopy.forEach(remainingEditor => this.deletedEditors.delete(remainingEditor)); | ||
return result; | ||
} | ||
|
||
protected fireDidChangeDecorations(event: (tree: Tree) => Map<string, TreeDecoration.Data>): void { | ||
this.onDidChangeDecorationsEmitter.fire(event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters