-
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.
navigator-decorator: add symlink icon and tooltip to linked files
This commit adds a new decorator for the file navigator. It displays a downward right curved arrow at the tail of a file node if that file contains a symbolic link. A tooltip is also added displaying "Symbolic Link" when hovering over a symbolic linked file node.
- Loading branch information
1 parent
fa3147f
commit 9e386f0
Showing
2 changed files
with
69 additions
and
0 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
65 changes: 65 additions & 0 deletions
65
packages/navigator/src/browser/navigator-symlink-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,65 @@ | ||
/******************************************************************************** | ||
* 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 { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { Emitter, Event, nls } from '@theia/core'; | ||
import { TreeDecorator, Tree, TreeDecoration, DepthFirstTreeIterator } from '@theia/core/lib/browser'; | ||
import { FileStatNode } from '@theia/filesystem/lib/browser'; | ||
import { DecorationsService } from '@theia/core/lib/browser/decorations-service'; | ||
|
||
@injectable() | ||
export class NavigatorSymlinkDecorator implements TreeDecorator { | ||
|
||
readonly id = 'theia-navigator-symlink-decorator'; | ||
|
||
constructor(@inject(DecorationsService) protected readonly decorationsService: DecorationsService) { | ||
this.decorationsService.onDidChangeDecorations(() => { | ||
this.fireDidChangeDecorations((tree: Tree) => this.collectDecorator(tree)); | ||
}); | ||
} | ||
|
||
async decorations(tree: Tree): Promise<Map<string, TreeDecoration.Data>> { | ||
return this.collectDecorator(tree); | ||
} | ||
|
||
protected collectDecorator(tree: Tree): Map<string, TreeDecoration.Data> { | ||
const result = new Map<string, TreeDecoration.Data>(); | ||
if (tree.root === undefined) { | ||
return result; | ||
} | ||
for (const node of new DepthFirstTreeIterator(tree.root)) { | ||
if (FileStatNode.is(node) && node.fileStat.isSymbolicLink) { | ||
const decorations: TreeDecoration.Data = { | ||
tooltip: nls.localizeByDefault('Symbolic Link'), | ||
tailDecorations: [{ data: '\u2937' }] | ||
}; | ||
result.set(node.id, decorations); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
protected readonly emitter = new Emitter<(tree: Tree) => Map<string, TreeDecoration.Data>>(); | ||
|
||
get onDidChangeDecorations(): Event<(tree: Tree) => Map<string, TreeDecoration.Data>> { | ||
return this.emitter.event; | ||
} | ||
|
||
fireDidChangeDecorations(event: (tree: Tree) => Map<string, TreeDecoration.Data>): void { | ||
this.emitter.fire(event); | ||
} | ||
|
||
} |